// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x174d6
movq -0x28(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x16260
cmpl $0x0, %eax
je 0x174fc
movl $0x0, -0x4(%rbp)
jmp 0x1770a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x17529
movl $0x0, -0x4(%rbp)
jmp 0x1770a
movl -0x1c(%rbp), %eax
shrl $0xd, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x17551
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
jmp 0x1756b
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x175e2
movl -0x40(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0x1758d
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x175bc
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x175af
jmp 0x175bc
jmp 0x175b1
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x17596
cmpl $0x0, -0x3c(%rbp)
jl 0x175d5
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
jmp 0x175dc
xorl %eax, %eax
movl %eax, -0x4c(%rbp)
jmp 0x175dc
movl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x1764c
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,8), %eax
cmpl -0x20(%rbp), %eax
jbe 0x17614
movl $0x0, -0x4(%rbp)
jmp 0x1770a
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %eax
cmpl -0x1c(%rbp), %eax
jb 0x1763f
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,8), %eax
cmpl -0x20(%rbp), %eax
ja 0x1763f
jmp 0x1764c
jmp 0x17641
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x175e8
movl -0x3c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jl 0x17664
movl $0x0, -0x4(%rbp)
jmp 0x1770a
cmpq $0x0, -0x28(%rbp)
jne 0x17677
movl $0x1, -0x4(%rbp)
jmp 0x1770a
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
subl -0x3c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movslq -0x3c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
je 0x176f7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rcx
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rdx
imull 0x5c(%rdx), %eax
cltq
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x17703
movq -0x28(%rbp), %rax
movq $0x0, 0x10(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)