// File: /workspace/github_c_makefile_star2_O1/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 0x13010
movq $0x0, (%r8)
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x10(%rdi), %r12
xorl %ebp, %ebp
testq %r12, %r12
je 0x1312c
movl (%r12), %eax
testl %eax, %eax
je 0x13126
movq %r8, 0x20(%rsp)
movq %rax, 0x10(%rsp)
leal -0x1(%rax), %r8d
movsbl (%rsi), %ebx
testl %ebx, %ebx
movq %rdi, 0x18(%rsp)
movl %ecx, 0x8(%rsp)
movl %edx, 0x4(%rsp)
je 0x1307d
movb 0x1(%rsi), %al
testb %al, %al
je 0x1307f
leaq 0x2(%rsi), %rcx
movl %ebx, %edx
shll $0x5, %edx
subl %ebx, %edx
movsbl %al, %ebx
addl %edx, %ebx
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x13066
jmp 0x1307f
xorl %ebx, %ebx
andl %r8d, %ebx
movq 0x10(%r12), %rdx
movl $0x1, %r14d
movl %ebx, %ebp
movq %r12, 0x30(%rsp)
movl %r8d, 0xc(%rsp)
movq %rdx, 0x28(%rsp)
movl %ebp, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r15d
leal (,%rbp,2), %r13d
andl $0x1e, %r13d
movl %r15d, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x13102
testb $0x1, %al
jne 0x130ec
movq 0x18(%r12), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rdi
movq %rsi, %r12
callq 0x3620
movq 0x28(%rsp), %rdx
movl 0xc(%rsp), %r8d
movq %r12, %rsi
movq 0x30(%rsp), %r12
testl %eax, %eax
je 0x13102
addl %r14d, %ebp
andl %r8d, %ebp
incl %r14d
cmpl %ebx, %ebp
jne 0x1309e
movq 0x10(%rsp), %rax
movl %eax, %ebp
jmp 0x13114
movl %r13d, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x10(%rsp), %rax
cmovnel %eax, %ebp
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %rdi
movl 0x8(%rsp), %ecx
movl 0x4(%rsp), %edx
cmpl %eax, %ebp
jne 0x13130
xorl %ebp, %ebp
xorl %esi, %esi
jmp 0x1313e
movq 0x20(%r12), %rax
movl %ebp, %esi
movslq (%rax,%rsi,4), %rbp
movb $0x1, %sil
xorl %eax, %eax
testb %sil, %sil
je 0x1322f
movq 0x8(%rdi), %r15
leaq (,%rbp,4), %r12
addq %rbp, %r12
movl 0xc(%r15,%r12,8), %esi
testl %esi, %esi
je 0x1322f
leaq (%r15,%r12,8), %rbx
movl %edx, %r9d
shrl $0xd, %r9d
movslq 0x8(%rbx), %r10
cmpl %r10d, %r9d
movq (%rbx), %r14
leaq (%r14,%r9,4), %r11
leaq -0x4(%r14,%r10,4), %r14
cmovlq %r11, %r14
movl (%r14), %ebp
testl %ebp, %ebp
jns 0x131ad
cmpl %r10d, %r9d
cmovgel %r10d, %r9d
testl %r9d, %r9d
jle 0x131ab
movq (%rbx), %r10
movl -0x4(%r10,%r9,4), %ebp
decq %r9
testl %ebp, %ebp
js 0x13195
jmp 0x131ad
xorl %ebp, %ebp
cmpl %esi, %ebp
setge %r9b
jge 0x131df
movq 0x18(%rbx), %r11
movl %ebp, %r10d
leaq (%r11,%r10,8), %r10
addq $0x4, %r10
cmpl %ecx, -0x4(%r10)
ja 0x1322f
cmpl %edx, (%r10)
jae 0x131df
incl %ebp
addq $0x8, %r10
cmpl %ebp, %esi
setle %r9b
jg 0x131c4
movl %esi, %ebp
movl %r9d, %eax
notb %al
movzbl %al, %eax
andl $0x1, %eax
testq %r8, %r8
je 0x1322f
testb $0x1, %r9b
jne 0x1322f
movl $0x0, (%r8)
subl %ebp, %esi
movl %esi, 0x4(%r8)
movl %ebp, %eax
shlq $0x3, %rax
addq 0x18(%r15,%r12,8), %rax
movq %rax, 0x8(%r8)
movl 0x5c(%rdi), %eax
testl %eax, %eax
je 0x13224
imull %ebp, %eax
cltq
addq 0x20(%r15,%r12,8), %rax
jmp 0x13226
xorl %eax, %eax
movq %rax, 0x10(%r8)
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq