// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movsbl (%rsi), %esi
testl %esi, %esi
je 0x6eda
movb 0x1(%r14), %bpl
testb %bpl, %bpl
je 0x6e1b
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, 0x20(%rsp)
movzbl %bpl, %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, 0x10(%rsp)
movq %r14, %rdi
callq 0x30d0
movdqa 0x20(%rsp), %xmm2
movl %ebx, %ecx
andb $0xf, %cl
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
movq %rax, %r13
andq $-0x10, %rbx
movdqa (%rbx), %xmm0
pxor %xmm3, %xmm3
movdqa %xmm0, %xmm1
pcmpeqb %xmm3, %xmm1
pmovmskb %xmm1, %r12d
movdqa %xmm2, %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
andl %edx, %eax
andl %edx, %r12d
je 0x6e31
leal -0x1(%r12), %ecx
notl %r12d
andl %ecx, %r12d
andl %eax, %r12d
je 0x6e14
movdqa 0x10(%rsp), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
shrl %eax
andl %eax, %r12d
je 0x6e14
addq $0x2, %r14
addl $-0x2, %r13d
bsfl %r12d, %r15d
leaq (%r15,%rbx), %rsi
addq $0x2, %rsi
movq %r14, %rdi
movl %r13d, %edx
callq 0x6eec
testl %eax, %eax
je 0x6ed1
leal -0x1(%r12), %eax
andl %r12d, %eax
movl %eax, %r12d
jne 0x6de8
xorl %ebx, %ebx
jmp 0x6eda
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30c0
movb %bpl, 0x7(%rsp)
leaq 0x2(%r14), %r12
movq %r13, 0x8(%rsp)
leal -0x2(%r13), %ebp
testl %eax, %eax
je 0x6e93
pcmpeqb 0x10(%rsp), %xmm0
pmovmskb %xmm0, %ecx
shrl %ecx
xorl %r15d, %r15d
movb 0x7(%rsp), %dl
cmpb %dl, 0x10(%rbx)
sete %r15b
shll $0xf, %r15d
orl %ecx, %r15d
andl %eax, %r15d
je 0x6e93
bsfl %r15d, %r13d
leaq (%rbx,%r13), %rsi
addq $0x2, %rsi
movq %r12, %rdi
movl %ebp, %edx
callq 0x6eec
testl %eax, %eax
je 0x6ecc
leal -0x1(%r15), %eax
andl %r15d, %eax
movl %eax, %r15d
jne 0x6e6d
movdqa 0x10(%rbx), %xmm0
addq $0x10, %rbx
movdqa %xmm0, %xmm1
pxor %xmm2, %xmm2
pcmpeqb %xmm2, %xmm1
pmovmskb %xmm1, %ecx
movdqa 0x20(%rsp), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
testl %ecx, %ecx
je 0x6e43
movzwl %cx, %r12d
movq 0x8(%rsp), %r13
jmp 0x6dbb
addq %r13, %rbx
jmp 0x6eda
addq %r15, %rbx
incq %rbx
decq %rbx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq