// File: ctSkennerton[P]fxtract/util/ssearch_x.c
// Function: main
int
main(int argc, char **argv)
{
    char    *pgm = strrchr(argv[0], '/');
    pgm	= pgm ? pgm + 1 : argv[0];

    while (argc > 1 && !strcmp(argv[1], "-v"))
	++verbose, ++argv;

    if (argc < 2) {
	fprintf(stderr, "Usage: %s [-v [-v]...] <patt_file> [text_file [matches]]\n", pgm);
	return	1;
    }

    MEMBUF  patt = chomp(slurp(argv[1]));
    fprintf(stderr, "# %s: %"FSIZE"d bytes\n", argv[1], patt.len);

    int	    npatts, i;
    MEMREF  *pattv = refsplit(patt.ptr, '\n', &npatts);
    text = argc > 2 && strcmp(argv[1], argv[2]) ? slurp(argv[2]) : patt;
    // text now contains \0's instead of \n's,
    //  but ssearch treats \0 like any other byte.
    int	    matches = argc > 3 ? atoi(argv[3]) : npatts;

    SSEARCH *ssp = ssearch_create(pattv, npatts);
    ssearch_dump(ssp, verbose ? stderr : fopen("/dev/null", "w")); // coverage

    plan_tests(4);
    ok(patt.ptr, "patt_file loaded");
    ok(npatts, "text_file loaded");
    ok(ssp, "ssearch_create returns a value");

    hits = 0;
    double	t = tick();
    (void)ssearch_scan(ssp, bufref(text), (SSEARCH_CB)on_match, pattv);
    t = tick() - t;
    if (!ok(hits == matches, "match count"))
	fprintf(stderr, "# actual: %d expected: %d\n", hits, matches);
    fprintf(stderr, "# elapsed: %G secs\n", t);
    if (verbose)
        for (i = 0; i < 16; ++i)
            if (ssearch_skip[i]) 
                fprintf(stderr, "# skip %2d: %8d\n", i, ssearch_skip[i]);
    ssearch_destroy(ssp);   // coverage
    buffree(patt);
    free(pattv);
    return exit_status();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x2f, %esi
callq 0x31b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x34a6
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x34b4
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x18(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x8(%rbp)
movb %al, -0x89(%rbp)
jle 0x34ef
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x5b28(%rip), %rsi      # 0x9004
callq 0x3360
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x34fb
jmp 0x3518
movl 0x9277(%rip), %eax      # 0xc778
addl $0x1, %eax
movl %eax, 0x926e(%rip)      # 0xc778
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x34bf
cmpl $0x2, -0x8(%rbp)
jge 0x3546
movq 0x8ab3(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x5ad4(%rip), %rsi      # 0x9007
movb $0x0, %al
callq 0x3260
movl $0x1, -0x4(%rbp)
jmp 0x39f5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5710
movq %rax, -0x38(%rbp)
movq %rdx, -0x30(%rbp)
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x4c40
movq %rax, -0x28(%rbp)
movq %rdx, -0x20(%rbp)
movq 0x8a61(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x20(%rbp), %rcx
leaq 0x5ab4(%rip), %rsi      # 0x9041
movb $0x0, %al
callq 0x3260
movq -0x28(%rbp), %rdi
movl $0xa, %esi
leaq -0x3c(%rbp), %rdx
callq 0x54c0
movq %rax, -0x48(%rbp)
cmpl $0x2, -0x8(%rbp)
jle 0x35f7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x3360
cmpl $0x0, %eax
je 0x35f7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x5710
movq %rax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq %rax, 0x9196(%rip)      # 0xc780
movq -0x50(%rbp), %rax
movq %rax, 0x9193(%rip)      # 0xc788
jmp 0x360d
movq -0x28(%rbp), %rax
movq %rax, 0x917e(%rip)      # 0xc780
movq -0x20(%rbp), %rax
movq %rax, 0x917b(%rip)      # 0xc788
cmpl $0x3, -0x8(%rbp)
jle 0x3628
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x32a0
movl %eax, -0x90(%rbp)
jmp 0x3631
movl -0x3c(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x48(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x5bd0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpl $0x0, 0x911c(%rip)      # 0xc778
je 0x3671
movq 0x8973(%rip), %rax      # 0xbfd8
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x368b
leaq 0x59da(%rip), %rdi      # 0x9052
leaq 0x59dd(%rip), %rsi      # 0x905c
callq 0x31e0
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x64e0
movl $0x4, %edi
callq 0x8550
cmpq $0x0, -0x28(%rbp)
je 0x36f0
xorl %edi, %edi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %r8d
leaq 0x599c(%rip), %r9       # 0x905e
leaq 0x599a(%rip), %r10      # 0x9063
leaq 0x599f(%rip), %rax      # 0x906f
movq %r8, %rdx
movq %r8, %rcx
movq %r10, (%rsp)
movl $0x2c, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x7870
jmp 0x372d
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %r8d
leaq 0x5960(%rip), %r9       # 0x905e
leaq 0x595e(%rip), %r10      # 0x9063
leaq 0x5963(%rip), %rax      # 0x906f
movq %r8, %rsi
movq %r8, %rdx
movq %r8, %rcx
movq %r10, (%rsp)
movl $0x2c, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x7870
cmpl $0x0, -0x3c(%rbp)
je 0x3774
xorl %edi, %edi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %r8d
leaq 0x5918(%rip), %r9       # 0x905e
leaq 0x5916(%rip), %r10      # 0x9063
leaq 0x592c(%rip), %rax      # 0x9080
movq %r8, %rdx
movq %r8, %rcx
movq %r10, (%rsp)
movl $0x2d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x7870
jmp 0x37b1
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %r8d
leaq 0x58dc(%rip), %r9       # 0x905e
leaq 0x58da(%rip), %r10      # 0x9063
leaq 0x58f0(%rip), %rax      # 0x9080
movq %r8, %rsi
movq %r8, %rdx
movq %r8, %rcx
movq %r10, (%rsp)
movl $0x2d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x7870
cmpq $0x0, -0x68(%rbp)
je 0x37f9
xorl %edi, %edi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %r8d
leaq 0x5893(%rip), %r9       # 0x905e
leaq 0x5891(%rip), %r10      # 0x9063
leaq 0x58b8(%rip), %rax      # 0x9091
movq %r8, %rdx
movq %r8, %rcx
movq %r10, (%rsp)
movl $0x2e, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x7870
jmp 0x3836
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %r8d
leaq 0x5857(%rip), %r9       # 0x905e
leaq 0x5855(%rip), %r10      # 0x9063
leaq 0x587c(%rip), %rax      # 0x9091
movq %r8, %rsi
movq %r8, %rdx
movq %r8, %rcx
movq %r10, (%rsp)
movl $0x2e, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x7870
movl $0x0, 0x8f50(%rip)      # 0xc790
callq 0x5b20
movsd %xmm0, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0x8f24(%rip), %rdi      # 0xc780
movq 0x8f25(%rip), %rsi      # 0xc788
callq 0x3a10
movq -0xa8(%rbp), %rdi
movq %rax, -0x80(%rbp)
movq %rdx, -0x78(%rbp)
movq -0x48(%rbp), %r8
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq 0x1b6(%rip), %rcx       # 0x3a40
callq 0x6150
callq 0x5b20
subsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movl 0x8eec(%rip), %eax      # 0xc790
cmpl -0x5c(%rbp), %eax
jne 0x38ef
xorl %edi, %edi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %r8d
leaq 0x57a2(%rip), %r9       # 0x905e
leaq 0x57a0(%rip), %r10      # 0x9063
leaq 0x57e6(%rip), %rax      # 0x90b0
movq %r8, %rdx
movq %r8, %rcx
movq %r10, (%rsp)
movl $0x34, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x7870
cmpl $0x0, %eax
jne 0x3952
jmp 0x3931
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %r8d
leaq 0x5761(%rip), %r9       # 0x905e
leaq 0x575f(%rip), %r10      # 0x9063
leaq 0x57a5(%rip), %rax      # 0x90b0
movq %r8, %rsi
movq %r8, %rdx
movq %r8, %rcx
movq %r10, (%rsp)
movl $0x34, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x7870
cmpl $0x0, %eax
jne 0x3952
movq 0x86a0(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movl 0x8e4f(%rip), %edx      # 0xc790
movl -0x5c(%rbp), %ecx
leaq 0x5771(%rip), %rsi      # 0x90bc
movb $0x0, %al
callq 0x3260
movq 0x867f(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movsd -0x70(%rbp), %xmm0
leaq 0x576f(%rip), %rsi      # 0x90d7
movb $0x1, %al
callq 0x3260
cmpl $0x0, 0x8e02(%rip)      # 0xc778
je 0x39ce
movl $0x0, -0x40(%rbp)
cmpl $0x10, -0x40(%rbp)
jge 0x39cc
movslq -0x40(%rbp), %rcx
leaq 0x8e10(%rip), %rax      # 0xc7a0
cmpl $0x0, (%rax,%rcx,4)
je 0x39bf
movq 0x863b(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movl -0x40(%rbp), %edx
movslq -0x40(%rbp), %rcx
leaq 0x8df2(%rip), %rax      # 0xc7a0
movl (%rax,%rcx,4), %ecx
leaq 0x5733(%rip), %rsi      # 0x90eb
movb $0x0, %al
callq 0x3260
jmp 0x39c1
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x397f
jmp 0x39ce
movq -0x68(%rbp), %rdi
callq 0x6100
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3ad0
movq -0x48(%rbp), %rdi
callq 0x3200
callq 0x88a0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)