// File: ctSkennerton[P]fxtract/util/msutil.c
// Function: findbit_1
int
findbit_1(uint8_t const*vec, int len)
{
    int off = 15 & (intptr_t)vec;
    uint8_t const *bp = vec - off;  // Back up to a 16b boundary.
    __m128i zero = _mm_setzero_si128();
    uint16_t m = BYTEDIFF(bp, zero);
    len += off;
        // Mask off trailing bits (tiny vec)
    if (len < 16) m &= ~(-1 << len);  
        // First time through, mask off leading (off) bits
    for (m &= -1 << off; !m && len >= 16; m = BYTEDIFF(bp, zero))
        bp += 16, len -= 16, _mm_prefetch(bp+512, _MM_HINT_NTA);
        // Mask off trailing bits (tail of vec)
    if (len < 16) m &= ~(-1 << len);  
    if (!m) return -1;
    off = bsrl(m);
    return 8*(off + bp - vec) + bsrl(bp[off]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x80(%rbp)
movl %esi, -0x84(%rbp)
movl -0x80(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movslq -0x88(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x90(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x10(%rbp)
movaps -0x10(%rbp), %xmm0
movaps %xmm0, -0xa0(%rbp)
movq -0x90(%rbp), %rax
movaps (%rax), %xmm1
movaps -0xa0(%rbp), %xmm0
movaps %xmm1, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps -0x20(%rbp), %xmm0
movaps -0x30(%rbp), %xmm1
pcmpeqb %xmm1, %xmm0
movdqa %xmm0, -0x60(%rbp)
movdqa -0x60(%rbp), %xmm0
pmovmskb %xmm0, %eax
xorl $0xffff, %eax           # imm = 0xFFFF
movw %ax, -0xa2(%rbp)
movl -0x88(%rbp), %eax
addl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
cmpl $0x10, -0x84(%rbp)
jge 0x83f4
movl -0x84(%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
movzwl -0xa2(%rbp), %eax
andl %ecx, %eax
movw %ax, -0xa2(%rbp)
movl -0x88(%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movl %eax, %ecx
movzwl -0xa2(%rbp), %eax
andl %ecx, %eax
movw %ax, -0xa2(%rbp)
xorl %eax, %eax
cmpw $0x0, -0xa2(%rbp)
movb %al, -0xa3(%rbp)
jne 0x8435
cmpl $0x10, -0x84(%rbp)
setge %al
movb %al, -0xa3(%rbp)
movb -0xa3(%rbp), %al
testb $0x1, %al
jne 0x8441
jmp 0x84b6
movq -0x90(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x90(%rbp)
movl -0x84(%rbp), %eax
subl $0x10, %eax
movl %eax, -0x84(%rbp)
movq -0x90(%rbp), %rax
addq $0x200, %rax            # imm = 0x200
prefetchnta (%rax)
movq -0x90(%rbp), %rax
movaps (%rax), %xmm1
movaps -0xa0(%rbp), %xmm0
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps -0x40(%rbp), %xmm0
movaps -0x50(%rbp), %xmm1
pcmpeqb %xmm1, %xmm0
movdqa %xmm0, -0x70(%rbp)
movdqa -0x70(%rbp), %xmm0
pmovmskb %xmm0, %eax
xorl $0xffff, %eax           # imm = 0xFFFF
movw %ax, -0xa2(%rbp)
jmp 0x8413
cmpl $0x10, -0x84(%rbp)
jge 0x84e1
movl -0x84(%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
movzwl -0xa2(%rbp), %eax
andl %ecx, %eax
movw %ax, -0xa2(%rbp)
cmpw $0x0, -0xa2(%rbp)
jne 0x84f4
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
jmp 0x8554
movzwl -0xa2(%rbp), %edi
callq 0x8310
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %ecx
movq -0x90(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x80(%rbp), %rcx
subq %rcx, %rax
shlq $0x3, %rax
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
movslq -0x88(%rbp), %rcx
movzbl (%rax,%rcx), %edi
callq 0x8310
movl %eax, %ecx
movq -0xb0(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq