// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movsbl (%rsi), %esi
testl %esi, %esi
je 0x70ca
movb 0x1(%r15), %r14b
testb %r14b, %r14b
je 0x70cf
movd %esi, %xmm0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pshuflw $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0,4,5,6,7]
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa %xmm0, 0x10(%rsp)
movzbl %r14b, %eax
movd %eax, %xmm0
punpcklbw %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pshuflw $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0,4,5,6,7]
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa %xmm0, 0x30(%rsp)
movq %r15, %rdi
callq 0x30d0
movdqa 0x10(%rsp), %xmm2
movl %ebx, %ecx
andb $0xf, %cl
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
movq %rax, %rbp
andq $-0x10, %rbx
movdqa (%rbx), %xmm0
pxor %xmm3, %xmm3
movdqa %xmm0, %xmm1
pcmpeqb %xmm3, %xmm1
pmovmskb %xmm1, %r13d
movdqa %xmm2, %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
andl %edx, %eax
andl %edx, %r13d
jne 0x7074
movq %r15, 0x28(%rsp)
leaq 0x2(%r15), %rcx
movq %rcx, 0x8(%rsp)
movq %rbp, 0x20(%rsp)
addl $-0x2, %ebp
movb %r14b, 0x7(%rsp)
testl %eax, %eax
je 0x703d
pcmpeqb 0x30(%rsp), %xmm0
pmovmskb %xmm0, %ecx
shrl %ecx
xorl %r15d, %r15d
cmpb %r14b, 0x10(%rbx)
sete %r15b
shll $0xf, %r15d
orl %ecx, %r15d
andl %eax, %r15d
sete %r14b
je 0x702f
bsfl %r15d, %eax
leaq (%rbx,%rax), %r13
leaq (%rbx,%rax), %rsi
addq $0x2, %rsi
movq 0x8(%rsp), %rdi
movl %ebp, %edx
callq 0x7106
pxor %xmm3, %xmm3
movdqa 0x10(%rsp), %xmm2
testl %eax, %eax
cmoveq %r13, %r12
je 0x702f
movl %r15d, %eax
leal -0x1(%rax), %r15d
andl %eax, %r15d
jmp 0x6fef
testb %r14b, %r14b
movb 0x7(%rsp), %r14b
je 0x70f4
movdqa 0x10(%rbx), %xmm0
addq $0x10, %rbx
movdqa %xmm0, %xmm1
pcmpeqb %xmm3, %xmm1
pmovmskb %xmm1, %ecx
movdqa %xmm2, %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
testl %ecx, %ecx
je 0x6fca
movzwl %cx, %r13d
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbp
leal -0x1(%r13), %ecx
notl %r13d
andl %ecx, %r13d
andl %eax, %r13d
je 0x70e5
movdqa 0x30(%rsp), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
shrl %eax
andl %eax, %r13d
je 0x70e5
addq $0x2, %r15
addl $-0x2, %ebp
xorl %r12d, %r12d
bsfl %r13d, %r14d
leaq (%r14,%rbx), %rsi
addq $0x2, %rsi
movq %r15, %rdi
movl %ebp, %edx
callq 0x7106
testl %eax, %eax
je 0x70ea
leal -0x1(%r13), %eax
andl %r13d, %eax
movl %eax, %r13d
jne 0x70a2
jmp 0x70f4
movq %rbx, %r12
jmp 0x70f4
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30c0
xorl %r12d, %r12d
jmp 0x70f4
leaq (%r14,%rbx), %r12
incq %r12
decq %r12
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq