// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/regidx.c
// Function: regidx_overlap
int regidx_overlap(regidx_t *regidx, const char *chr, hts_pos_t beg, hts_pos_t end, regitr_t *regitr)
{
    if ( regitr ) regitr->seq = NULL;

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

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

    if ( list->nreg==1 )
    {
        if ( beg > list->reg[0].end ) return 0;
        if ( end < list->reg[0].beg ) return 0;
        ireg = 0;
    }
    else
    {
        if ( !list->idx ) {
            if (reglist_build_index_(regidx,list) < 0) return -1;
        }

        int ibeg = iBIN(beg);
        if ( ibeg >= list->nidx ) return 0;     // beg is too big

        // find a matching region
        uint32_t i = list->idx[ibeg];
        if ( !i )
        {
            int iend = iBIN(end);
            if ( iend > list->nidx ) iend = list->nidx;
            for (i=ibeg; i<=iend; i++)
                if ( list->idx[i] ) break;
            if ( i>iend ) return 0;
            i = list->idx[i];
        }
        for (ireg=i-1; ireg<list->nreg; ireg++)
        {
            if ( list->reg[ireg].beg > end ) return 0;   // no match, past the query region
            if ( list->reg[ireg].end >= beg && list->reg[ireg].beg <= end ) break; // found
        }

        if ( ireg >= list->nreg ) return 0;   // no match
    }

    if ( !regitr ) return 1;    // match, but no more info to save

    // may need to iterate over the matching regions later
    itr_t_ *itr = (itr_t_*)regitr->itr;
    itr->ridx = regidx;
    itr->list = list;
    itr->beg  = beg;
    itr->end  = end;
    itr->ireg = ireg;
    itr->active = 0;

    regitr->seq = list->seq;
    regitr->beg = list->reg[ireg].beg;
    regitr->end = list->reg[ireg].end;
    if ( regidx->payload_size )
        regitr->payload = list->dat + regidx->payload_size*ireg;

    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2efbf
movq -0x30(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0x2d9c0
cmpl $0x0, %eax
je 0x2efe5
movl $0x0, -0x4(%rbp)
jmp 0x2f2b8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x2f012
movl $0x0, -0x4(%rbp)
jmp 0x2f2b8
movq -0x40(%rbp), %rax
cmpl $0x1, 0xc(%rax)
jne 0x2f063
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jle 0x2f03a
movl $0x0, -0x4(%rbp)
jmp 0x2f2b8
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq (%rcx), %rax
jge 0x2f057
movl $0x0, -0x4(%rbp)
jmp 0x2f2b8
movl $0x0, -0x38(%rbp)
jmp 0x2f1d8
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x2f08d
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2f2d0
cmpl $0x0, %eax
jge 0x2f08b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2f2b8
jmp 0x2f08d
movq -0x20(%rbp), %rax
sarq $0xd, %rax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jb 0x2f0b0
movl $0x0, -0x4(%rbp)
jmp 0x2f2b8
movq -0x40(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jne 0x2f139
movq -0x28(%rbp), %rax
sarq $0xd, %rax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jbe 0x2f0e8
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
ja 0x2f115
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x48(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0x2f108
jmp 0x2f115
jmp 0x2f10a
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2f0ee
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jbe 0x2f129
movl $0x0, -0x4(%rbp)
jmp 0x2f2b8
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x2f1be
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
cmpq -0x28(%rbp), %rax
jle 0x2f176
movl $0x0, -0x4(%rbp)
jmp 0x2f2b8
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
cmpq -0x20(%rbp), %rax
jl 0x2f1b1
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
cmpq -0x28(%rbp), %rax
jg 0x2f1b1
jmp 0x2f1be
jmp 0x2f1b3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2f142
movl -0x38(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jb 0x2f1d6
movl $0x0, -0x4(%rbp)
jmp 0x2f2b8
jmp 0x2f1d8
cmpq $0x0, -0x30(%rbp)
jne 0x2f1eb
movl $0x1, -0x4(%rbp)
jmp 0x2f2b8
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x38(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x2f2b1
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
imull -0x38(%rbp), %eax
cltq
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)