// File: ctSkennerton[P]fxtract/util/scan.c
// Function: scanstr
char const*
scanstr(char const* tgt, char const* pat)
{
    if (!pat[0]) return tgt;
    if (!pat[1]) return strchr(tgt, *pat);

    XMM         zero = {}, xt;
    XMM         xp0  = xm_fill(pat[0]);
    XMM         xp1  = xm_fill(pat[1]);
    unsigned    m    = 15 & (intptr_t)tgt, patlen = strlen(pat);
    unsigned    mz   = (-1 << m) & xm_same(zero, xt = xm_load(tgt -= m));
    unsigned    m0   = (-1 << m) & xm_same(xp0, xt);
    char const  *p;

    while (!mz) {
        if (m0) {
            unsigned m1 = xm_same(xp1, xt);
            m0 &= (m1 >> 1) | (tgt[16] == pat[1] ? 0x8000 : 0);
            for (m = m0; m; m &= m - 1) {
                int pos = ffs(m) - 1;
                if (!intcmp(pat+2, tgt+pos+2, patlen-2)) return tgt+pos;
            }
        }
        mz = xm_same(zero, xt = xm_load(tgt += 16));
        m0 = xm_same(xp0, xt);
    }

    if ((m0 &= under(mz))) {
        m0 &= (xm_same(xp1, xt) >> 1);
        for (m = m0; m; m &= m - 1) {
             p = tgt + ffs(m) - 1;
             if (!intcmp(pat+2, p+2, patlen-2))
                return p;
        }
    }

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x58(%rbp)
movq %rsi, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x9e09
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0xa32b
movq -0x60(%rbp), %rax
cmpb $0x0, 0x1(%rax)
jne 0x9e2c
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rax
movsbl (%rax), %esi
callq 0x30c0
movq %rax, -0x50(%rbp)
jmp 0xa32b
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movq -0x60(%rbp), %rax
movb (%rax), %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
movb %al, -0xe2(%rbp)
movb %al, -0x21(%rbp)
movb %al, -0x22(%rbp)
movb %al, -0x23(%rbp)
movb %al, -0x24(%rbp)
movb %al, -0x25(%rbp)
movb %al, -0x26(%rbp)
movb %al, -0x27(%rbp)
movb %al, -0x28(%rbp)
movb %al, -0x29(%rbp)
movb %al, -0x2a(%rbp)
movb %al, -0x2b(%rbp)
movb %al, -0x2c(%rbp)
movb %al, -0x2d(%rbp)
movb %al, -0x2e(%rbp)
movb %al, -0x2f(%rbp)
movb %al, -0x30(%rbp)
movzbl -0x21(%rbp), %eax
movd %eax, %xmm0
movzbl -0x22(%rbp), %eax
movd %eax, %xmm1
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
movzbl -0x23(%rbp), %eax
movd %eax, %xmm2
movzbl -0x24(%rbp), %eax
movd %eax, %xmm0
punpcklbw %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3],xmm0[4],xmm2[4],xmm0[5],xmm2[5],xmm0[6],xmm2[6],xmm0[7],xmm2[7]
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
movzbl -0x25(%rbp), %eax
movd %eax, %xmm1
movzbl -0x26(%rbp), %eax
movd %eax, %xmm2
punpcklbw %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3],xmm2[4],xmm1[4],xmm2[5],xmm1[5],xmm2[6],xmm1[6],xmm2[7],xmm1[7]
movzbl -0x27(%rbp), %eax
movd %eax, %xmm3
movzbl -0x28(%rbp), %eax
movd %eax, %xmm1
punpcklbw %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1],xmm1[2],xmm3[2],xmm1[3],xmm3[3],xmm1[4],xmm3[4],xmm1[5],xmm3[5],xmm1[6],xmm3[6],xmm1[7],xmm3[7]
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movzbl -0x29(%rbp), %eax
movd %eax, %xmm2
movzbl -0x2a(%rbp), %eax
movd %eax, %xmm0
punpcklbw %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3],xmm0[4],xmm2[4],xmm0[5],xmm2[5],xmm0[6],xmm2[6],xmm0[7],xmm2[7]
movzbl -0x2b(%rbp), %eax
movd %eax, %xmm3
movzbl -0x2c(%rbp), %eax
movd %eax, %xmm2
punpcklbw %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1],xmm2[2],xmm3[2],xmm2[3],xmm3[3],xmm2[4],xmm3[4],xmm2[5],xmm3[5],xmm2[6],xmm3[6],xmm2[7],xmm3[7]
punpcklwd %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1],xmm2[2],xmm0[2],xmm2[3],xmm0[3]
movzbl -0x2d(%rbp), %eax
movd %eax, %xmm0
movzbl -0x2e(%rbp), %eax
movd %eax, %xmm3
punpcklbw %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3],xmm3[4],xmm0[4],xmm3[5],xmm0[5],xmm3[6],xmm0[6],xmm3[7],xmm0[7]
movzbl -0x2f(%rbp), %eax
movd %eax, %xmm4
movzbl -0x30(%rbp), %eax
movd %eax, %xmm0
punpcklbw %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1],xmm0[2],xmm4[2],xmm0[3],xmm4[3],xmm0[4],xmm4[4],xmm0[5],xmm4[5],xmm0[6],xmm4[6],xmm0[7],xmm4[7]
punpcklwd %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1],xmm0[2],xmm3[2],xmm0[3],xmm3[3]
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, -0x40(%rbp)
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0x90(%rbp)
movq -0x60(%rbp), %rax
movb 0x1(%rax), %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
movb %al, -0xe1(%rbp)
movb %al, -0x1(%rbp)
movb %al, -0x2(%rbp)
movb %al, -0x3(%rbp)
movb %al, -0x4(%rbp)
movb %al, -0x5(%rbp)
movb %al, -0x6(%rbp)
movb %al, -0x7(%rbp)
movb %al, -0x8(%rbp)
movb %al, -0x9(%rbp)
movb %al, -0xa(%rbp)
movb %al, -0xb(%rbp)
movb %al, -0xc(%rbp)
movb %al, -0xd(%rbp)
movb %al, -0xe(%rbp)
movb %al, -0xf(%rbp)
movb %al, -0x10(%rbp)
movzbl -0x1(%rbp), %eax
movd %eax, %xmm0
movzbl -0x2(%rbp), %eax
movd %eax, %xmm1
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
movzbl -0x3(%rbp), %eax
movd %eax, %xmm2
movzbl -0x4(%rbp), %eax
movd %eax, %xmm0
punpcklbw %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3],xmm0[4],xmm2[4],xmm0[5],xmm2[5],xmm0[6],xmm2[6],xmm0[7],xmm2[7]
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
movzbl -0x5(%rbp), %eax
movd %eax, %xmm1
movzbl -0x6(%rbp), %eax
movd %eax, %xmm2
punpcklbw %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3],xmm2[4],xmm1[4],xmm2[5],xmm1[5],xmm2[6],xmm1[6],xmm2[7],xmm1[7]
movzbl -0x7(%rbp), %eax
movd %eax, %xmm3
movzbl -0x8(%rbp), %eax
movd %eax, %xmm1
punpcklbw %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1],xmm1[2],xmm3[2],xmm1[3],xmm3[3],xmm1[4],xmm3[4],xmm1[5],xmm3[5],xmm1[6],xmm3[6],xmm1[7],xmm3[7]
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movzbl -0x9(%rbp), %eax
movd %eax, %xmm2
movzbl -0xa(%rbp), %eax
movd %eax, %xmm0
punpcklbw %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3],xmm0[4],xmm2[4],xmm0[5],xmm2[5],xmm0[6],xmm2[6],xmm0[7],xmm2[7]
movzbl -0xb(%rbp), %eax
movd %eax, %xmm3
movzbl -0xc(%rbp), %eax
movd %eax, %xmm2
punpcklbw %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1],xmm2[2],xmm3[2],xmm2[3],xmm3[3],xmm2[4],xmm3[4],xmm2[5],xmm3[5],xmm2[6],xmm3[6],xmm2[7],xmm3[7]
punpcklwd %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1],xmm2[2],xmm0[2],xmm2[3],xmm0[3]
movzbl -0xd(%rbp), %eax
movd %eax, %xmm0
movzbl -0xe(%rbp), %eax
movd %eax, %xmm3
punpcklbw %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3],xmm3[4],xmm0[4],xmm3[5],xmm0[5],xmm3[6],xmm0[6],xmm3[7],xmm0[7]
movzbl -0xf(%rbp), %eax
movd %eax, %xmm4
movzbl -0x10(%rbp), %eax
movd %eax, %xmm0
punpcklbw %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1],xmm0[2],xmm4[2],xmm0[3],xmm4[3],xmm0[4],xmm4[4],xmm0[5],xmm4[5],xmm0[6],xmm4[6],xmm0[7],xmm4[7]
punpcklwd %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1],xmm0[2],xmm3[2],xmm0[3],xmm3[3]
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqa %xmm0, -0x20(%rbp)
movdqa -0x20(%rbp), %xmm0
movdqa %xmm0, -0xa0(%rbp)
movq -0x58(%rbp), %rax
andq $0xf, %rax
movl %eax, -0xa4(%rbp)
movq -0x60(%rbp), %rdi
callq 0x30d0
movl %eax, -0xa8(%rbp)
movl -0xa4(%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movl %eax, -0xc8(%rbp)
movdqa -0x70(%rbp), %xmm0
movaps %xmm0, -0xe0(%rbp)
movl -0xa4(%rbp), %eax
movq -0x58(%rbp), %rdi
movl %eax, %eax
movl %eax, %ecx
xorl %eax, %eax
subq %rcx, %rax
addq %rax, %rdi
movq %rdi, -0x58(%rbp)
callq 0x9af0
movaps %xmm0, %xmm1
movaps -0xe0(%rbp), %xmm0
movdqa %xmm1, -0x80(%rbp)
callq 0x9ab0
movl %eax, %ecx
movl -0xc8(%rbp), %eax
andl %ecx, %eax
movl %eax, -0xac(%rbp)
movl -0xa4(%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movl %eax, -0xc4(%rbp)
movdqa -0x90(%rbp), %xmm0
movdqa -0x80(%rbp), %xmm1
callq 0x9ab0
movl %eax, %ecx
movl -0xc4(%rbp), %eax
andl %ecx, %eax
movl %eax, -0xb0(%rbp)
cmpl $0x0, -0xac(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xa11a
jmp 0xa24d
cmpl $0x0, -0xb0(%rbp)
je 0xa1f9
movdqa -0xa0(%rbp), %xmm0
movdqa -0x80(%rbp), %xmm1
callq 0x9ab0
movl %eax, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
shrl %eax
movq -0x58(%rbp), %rcx
movsbl 0x10(%rcx), %esi
movq -0x60(%rbp), %rcx
movsbl 0x1(%rcx), %edi
xorl %ecx, %ecx
movl $0x8000, %edx           # imm = 0x8000
cmpl %edi, %esi
cmovel %edx, %ecx
orl %ecx, %eax
andl -0xb0(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
je 0xa1f7
movl -0xa4(%rbp), %edi
callq 0x32f0
subl $0x1, %eax
movl %eax, -0xc0(%rbp)
movq -0x60(%rbp), %rdi
addq $0x2, %rdi
movq -0x58(%rbp), %rsi
movslq -0xc0(%rbp), %rax
addq %rax, %rsi
addq $0x2, %rsi
movl -0xa8(%rbp), %edx
subl $0x2, %edx
callq 0xa340
cmpl $0x0, %eax
jne 0xa1de
movq -0x58(%rbp), %rax
movslq -0xc0(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0xa32b
jmp 0xa1e0
movl -0xa4(%rbp), %eax
subl $0x1, %eax
andl -0xa4(%rbp), %eax
movl %eax, -0xa4(%rbp)
jmp 0xa17d
jmp 0xa1f9
movdqa -0x70(%rbp), %xmm0
movaps %xmm0, -0x100(%rbp)
movq -0x58(%rbp), %rdi
addq $0x10, %rdi
movq %rdi, -0x58(%rbp)
callq 0x9af0
movaps %xmm0, %xmm1
movaps -0x100(%rbp), %xmm0
movdqa %xmm1, -0x80(%rbp)
callq 0x9ab0
movl %eax, -0xac(%rbp)
movdqa -0x90(%rbp), %xmm0
movdqa -0x80(%rbp), %xmm1
callq 0x9ab0
movl %eax, -0xb0(%rbp)
jmp 0xa105
movl -0xac(%rbp), %edi
callq 0x9b10
andl -0xb0(%rbp), %eax
movl %eax, -0xb0(%rbp)
cmpl $0x0, %eax
je 0xa323
movdqa -0xa0(%rbp), %xmm0
movdqa -0x80(%rbp), %xmm1
callq 0x9ab0
shrl %eax
andl -0xb0(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
je 0xa321
movq -0x58(%rbp), %rax
movq %rax, -0x108(%rbp)
movl -0xa4(%rbp), %edi
callq 0x32f0
movl %eax, %ecx
movq -0x108(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0xb8(%rbp)
movq -0x60(%rbp), %rdi
addq $0x2, %rdi
movq -0xb8(%rbp), %rsi
addq $0x2, %rsi
movl -0xa8(%rbp), %edx
subl $0x2, %edx
callq 0xa340
cmpl $0x0, %eax
jne 0xa305
movq -0xb8(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0xa32b
jmp 0xa307
movl -0xa4(%rbp), %eax
subl $0x1, %eax
andl -0xa4(%rbp), %eax
movl %eax, -0xa4(%rbp)
jmp 0xa299
jmp 0xa323
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)