// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movsbl (%rsi), %esi
testl %esi, %esi
je 0x6ade
movb 0x1(%r14), %bpl
testb %bpl, %bpl
je 0x6af0
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, (%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
movq %rax, %r15
movl %ebx, %ecx
andb $0xf, %cl
pushq $-0x1
popq %rdx
shll %cl, %edx
andq $-0x10, %rbx
movdqa (%rbx), %xmm0
pxor %xmm2, %xmm2
movdqa %xmm0, %xmm1
pcmpeqb %xmm2, %xmm1
pmovmskb %xmm1, %r12d
andl %edx, %r12d
movdqa (%rsp), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
andl %edx, %eax
addq $0x2, %r14
addl $-0x2, %r15d
pcmpeqb 0x10(%rsp), %xmm0
testl %r12d, %r12d
jne 0x6b06
testl %eax, %eax
je 0x6aaf
pmovmskb %xmm0, %ecx
shrl %ecx
xorl %r12d, %r12d
cmpb %bpl, 0x10(%rbx)
sete %r12b
shll $0xf, %r12d
orl %ecx, %r12d
andl %eax, %r12d
testl %r12d, %r12d
je 0x6aaf
bsfl %r12d, %r13d
leaq (%rbx,%r13), %rsi
addq $0x2, %rsi
movq %r14, %rdi
movl %r15d, %edx
callq 0x6b5b
testl %eax, %eax
je 0x6adb
leal -0x1(%r12), %eax
andl %r12d, %eax
movl %eax, %r12d
jmp 0x6a82
movdqa 0x10(%rbx), %xmm0
addq $0x10, %rbx
movdqa %xmm0, %xmm1
pcmpeqb 0x195c(%rip), %xmm1     # 0x8420
pmovmskb %xmm1, %r12d
movdqa (%rsp), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %eax
jmp 0x6a54
addq %r13, %rbx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30c0
leal -0x1(%r12), %ecx
notl %r12d
andl %ecx, %r12d
andl %eax, %r12d
je 0x6b4c
pmovmskb %xmm0, %eax
shrl %eax
andl %eax, %r12d
testl %r12d, %r12d
je 0x6b4c
bsfl %r12d, %r13d
leaq (%rbx,%r13), %rsi
addq $0x2, %rsi
movq %r14, %rdi
movl %r15d, %edx
callq 0x6b5b
testl %eax, %eax
je 0x6b50
leal -0x1(%r12), %eax
andl %r12d, %eax
movl %eax, %r12d
jmp 0x6b1f
xorl %ebx, %ebx
jmp 0x6ade
addq %r13, %rbx
incq %rbx
decq %rbx
jmp 0x6ade