// File: /workspace/github_c_makefile_star2_O3/zhou-lab[P]tbmate/htslib/regidx.c
// Function: regidx_overlap
int regidx_overlap(regidx_t *idx, const char *chr, uint32_t from, uint32_t to, regitr_t *itr)
{
    if ( itr ) itr->i = itr->n = 0;

    int iseq;
    if ( khash_str2int_get(idx->seq2regs, chr, &iseq)!=0 ) return 0; // no such sequence

    reglist_t *list = &idx->seq[iseq];
    if ( !list->nregs ) return 0;

    int i, ibeg = from>>LIDX_SHIFT; 
    int ireg = ibeg < list->nidx ? list->idx[ibeg] : list->idx[ list->nidx - 1 ];
    if ( ireg < 0 )
    {
        // linear search; if slow, replace with binary search
        if ( ibeg > list->nidx ) ibeg = list->nidx;
        for (i=ibeg - 1; i>=0; i--)
            if ( list->idx[i] >=0 ) break;
        ireg = i>=0 ? list->idx[i] : 0;
    }
    for (i=ireg; i<list->nregs; i++)
    {
        if ( list->regs[i].start > to ) return 0;   // no match
        if ( list->regs[i].end >= from && list->regs[i].start <= to ) break; // found
    }

    if ( i>=list->nregs ) return 0;   // no match

    if ( !itr ) return 1;

    itr->i = 0;
    itr->n = list->nregs - i;
    itr->reg = &idx->seq[iseq].regs[i];
    if ( idx->payload_size )
        itr->payload = idx->seq[iseq].payload + i*idx->payload_size;
    else
        itr->payload = NULL;

    return 1;
}

// Assembly:
testq %r8, %r8
je 0x13221
movq $0x0, (%r8)
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x10(%rdi), %r13
testq %r13, %r13
je 0x13312
movl (%r13), %r9d
xorl %eax, %eax
movl $0x0, %r12d
testl %r9d, %r9d
je 0x1333f
movq %r8, 0x20(%rsp)
leal -0x1(%r9), %r8d
movsbl (%rsi), %r14d
testl %r14d, %r14d
movq %rdi, 0x18(%rsp)
movl %ecx, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq %r9, 0x10(%rsp)
je 0x1329b
movb 0x1(%rsi), %al
testb %al, %al
je 0x1329e
leaq 0x2(%rsi), %rcx
movl %r14d, %edx
shll $0x5, %edx
subl %r14d, %edx
movsbl %al, %r14d
addl %edx, %r14d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x13280
jmp 0x1329e
xorl %r14d, %r14d
andl %r8d, %r14d
movq 0x10(%r13), %rdx
movl $0x1, %ebx
movl %r14d, %r12d
movq %r13, 0x30(%rsp)
movl %r8d, 0xc(%rsp)
movq %rdx, 0x28(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r15d
leal (%r12,%r12), %ebp
andl $0x1e, %ebp
movl %r15d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x13319
testb $0x1, %al
jne 0x13305
movq 0x18(%r13), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rsi, %r13
callq 0x3620
movq 0x28(%rsp), %rdx
movl 0xc(%rsp), %r8d
movq %r13, %rsi
movq 0x30(%rsp), %r13
testl %eax, %eax
je 0x13319
addl %ebx, %r12d
andl %r8d, %r12d
incl %ebx
cmpl %r14d, %r12d
jne 0x132bc
xorl %eax, %eax
jmp 0x1340d
movl %ebp, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x10(%rsp), %r9
cmovnel %r9d, %r12d
xorl %eax, %eax
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %rdi
movl 0x8(%rsp), %ecx
movl 0x4(%rsp), %edx
cmpl %r9d, %r12d
je 0x1340d
movq 0x20(%r13), %r9
movl %r12d, %esi
movslq (%r9,%rsi,4), %rsi
movq 0x8(%rdi), %rbx
leaq (%rsi,%rsi,4), %r12
movl 0xc(%rbx,%r12,8), %ebp
testl %ebp, %ebp
je 0x1340d
leaq (%rbx,%r12,8), %rsi
movl %edx, %r15d
shrl $0xd, %r15d
movslq 0x8(%rsi), %r10
cmpl %r10d, %r15d
movq (%rsi), %r14
leaq (%r14,%r15,4), %r9
leaq -0x4(%r14,%r10,4), %r11
cmovlq %r9, %r11
movl (%r11), %r9d
testl %r9d, %r9d
jns 0x133b0
cmpl %r10d, %r15d
cmovgel %r10d, %r15d
testl %r15d, %r15d
jle 0x133ad
movl -0x4(%r14,%r15,4), %r9d
decq %r15
testl %r9d, %r9d
js 0x13399
jmp 0x133b0
xorl %r9d, %r9d
cmpl %ebp, %r9d
jge 0x1340d
movq 0x18(%rsi), %r10
movl %r9d, %esi
cmpl %ecx, (%r10,%rsi,8)
ja 0x1340d
cmpl %edx, 0x4(%r10,%rsi,8)
jae 0x133d2
incq %rsi
cmpl %esi, %ebp
jg 0x133bc
jmp 0x1340d
movl $0x1, %eax
testq %r8, %r8
je 0x1340d
movl $0x0, (%r8)
subl %esi, %ebp
movl %ebp, 0x4(%r8)
movl %esi, %edx
leaq (%r10,%rdx,8), %rdx
movq %rdx, 0x8(%r8)
movl 0x5c(%rdi), %edx
testl %edx, %edx
je 0x13407
imull %esi, %edx
movslq %edx, %rdx
addq 0x20(%rbx,%r12,8), %rdx
jmp 0x13409
xorl %edx, %edx
movq %rdx, 0x10(%r8)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq