// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %rbx
movq %rcx, %rbp
movq %rdx, %r13
movq %rdi, %r14
testq %r8, %r8
je 0x1c258
andq $0x0, 0x18(%rbx)
movq 0x10(%r14), %rdi
leaq 0x14(%rsp), %rdx
callq 0x1b329
testl %eax, %eax
je 0x1c27d
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %r12
movslq 0x14(%rsp), %rax
imulq $0x38, %rax, %rax
movl 0xc(%r12,%rax), %r15d
testq %r15, %r15
je 0x1c2c6
addq %rax, %r12
cmpl $0x1, %r15d
movq %rbp, (%rsp)
movq %r13, 0x8(%rsp)
jne 0x1c2cb
movq 0x18(%r12), %rcx
movl $0x0, %ebp
cmpq %r13, 0x8(%rcx)
jl 0x1c26c
xorl %eax, %eax
movq (%rsp), %rdx
cmpq %rdx, (%rcx)
jg 0x1c26c
jmp 0x1c35a
movl %r15d, %ebp
jmp 0x1c26c
movq (%r12), %r13
testq %r13, %r13
je 0x1c3c0
movq 0x8(%rsp), %rcx
shrq $0xd, %rcx
movl 0x8(%r12), %esi
cmpl %ecx, %esi
jbe 0x1c26a
movslq %ecx, %rax
movl (%r13,%rax,4), %eax
testl %eax, %eax
jne 0x1c314
shrq $0xd, %rbp
cmpl %ebp, %esi
cmovbl %esi, %ebp
cmpl %ebp, %ecx
ja 0x1c26a
movl %ecx, %eax
movl (%r13,%rax,4), %eax
incl %ecx
testl %eax, %eax
je 0x1c2ff
leal -0x1(%rax), %ecx
movl 0xc(%r12), %edx
movslq %ecx, %rsi
shlq $0x4, %rsi
orq $0x8, %rsi
addl $-0x2, %eax
movq 0x8(%rsp), %r8
incl %eax
cmpl %eax, %edx
jbe 0x1c26a
movq 0x18(%r12), %rcx
movq (%rsp), %rdi
cmpq %rdi, -0x8(%rcx,%rsi)
jg 0x1c26a
leaq 0x10(%rsi), %rdi
cmpq %r8, (%rcx,%rsi)
movq %rdi, %rsi
jl 0x1c32f
pushq $0x1
popq %rbp
testq %rbx, %rbx
je 0x1c26c
movq 0x20(%rbx), %rdx
movq %r14, 0x18(%rdx)
movq %r12, 0x20(%rdx)
movq 0x8(%rsp), %rsi
movq %rsi, (%rdx)
movq (%rsp), %rsi
movq %rsi, 0x8(%rdx)
movl %eax, 0x10(%rdx)
andl $0x0, 0x28(%rdx)
movq 0x28(%r12), %rdx
movq %rdx, 0x18(%rbx)
movslq %eax, %rdx
shlq $0x4, %rdx
movups (%rcx,%rdx), %xmm0
movups %xmm0, (%rbx)
movl 0x38(%r14), %ecx
testl %ecx, %ecx
je 0x1c26c
imull %eax, %ecx
movslq %ecx, %rax
addq 0x20(%r12), %rax
movq %rax, 0x10(%rbx)
jmp 0x1c26c
cmpl $0x0, 0x30(%r12)
pushq $-0x1
popq %rbp
je 0x1c542
cmpl $0x0, 0x38(%r14)
je 0x1c498
leaq (,%r15,8), %rdi
callq 0x4680
testq %rax, %rax
je 0x1c26c
movq %rax, %r13
movq %r15, %rax
shlq $0x4, %rax
xorl %ecx, %ecx
movq %r13, %rdx
cmpq %rcx, %rax
je 0x1c419
movq 0x18(%r12), %rsi
addq %rcx, %rsi
movq %rsi, (%rdx)
addq $0x8, %rdx
addq $0x10, %rcx
jmp 0x1c3ff
leaq 0x808(%rip), %rcx       # 0x1cc28
pushq $0x8
popq %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x4990
movq %r14, 0x28(%rsp)
movslq 0x38(%r14), %r15
movl 0xc(%r12), %edi
movq %rdi, 0x30(%rsp)
imull %r15d, %edi
callq 0x4680
testq %rax, %rax
je 0x1c509
movq %r13, 0x18(%rsp)
xorl %r14d, %r14d
movq %rax, 0x20(%rsp)
movq %rax, %r13
cmpq %r14, 0x30(%rsp)
je 0x1c4b9
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rsi
subq 0x18(%r12), %rsi
sarq $0x4, %rsi
imulq %r15, %rsi
addq 0x20(%r12), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x43c0
incq %r14
addq %r15, %r13
jmp 0x1c463
movq 0x18(%r12), %rdi
leaq 0x77f(%rip), %rcx       # 0x1cc23
pushq $0x10
popq %rdx
movq %r15, %rsi
callq 0x4990
movl 0xc(%r12), %r15d
jmp 0x1c53c
movq 0x20(%r12), %rdi
callq 0x45c0
movq 0x20(%rsp), %rax
movq %rax, 0x20(%r12)
movl 0xc(%r12), %r14d
movq %r14, %rdi
shlq $0x4, %rdi
callq 0x4680
testq %rax, %rax
movq 0x18(%rsp), %r13
je 0x1c509
movq %rax, %r15
shlq $0x3, %r14
xorl %eax, %eax
cmpq %rax, %r14
je 0x1c516
movq (%r13,%rax), %rcx
movups (%rcx), %xmm0
movups %xmm0, (%r15,%rax,2)
addq $0x8, %rax
jmp 0x1c4f1
movq %r13, %rdi
callq 0x45c0
jmp 0x1c26c
movq %r13, %rdi
callq 0x45c0
movq 0x18(%r12), %rdi
callq 0x45c0
movq %r15, 0x18(%r12)
movl 0xc(%r12), %r15d
movl %r15d, 0x10(%r12)
movq 0x28(%rsp), %r14
andl $0x0, 0x30(%r12)
andl $0x0, 0x8(%r12)
movl %r15d, %eax
shlq $0x4, %rax
xorl %ecx, %ecx
xorl %r15d, %r15d
cmpq %rcx, %rax
je 0x1c577
movq 0x18(%r12), %rdx
movq 0x8(%rdx,%rcx), %rdx
shrq $0xd, %rdx
cmpl %edx, %r15d
cmoval %r15d, %edx
addq $0x10, %rcx
movl %edx, %r15d
jmp 0x1c554
incl %r15d
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x4300
testq %rax, %rax
je 0x1c26c
movq %rax, %r13
movq (%r12), %rdi
callq 0x45c0
movq %r13, (%r12)
movl %r15d, 0x8(%r12)
movl 0xc(%r12), %eax
xorl %ecx, %ecx
movq (%rsp), %rbp
cmpq %rax, %rcx
je 0x1c2d8
movq 0x18(%r12), %rsi
movq %rcx, %rdi
shlq $0x4, %rdi
movq (%rsi,%rdi), %rdx
movq 0x8(%rsi,%rdi), %rsi
shrq $0xd, %rdx
shrq $0xd, %rsi
cmpl %esi, %edx
jne 0x1c5f1
movslq %edx, %rdx
incq %rcx
cmpl $0x0, (%r13,%rdx,4)
jne 0x1c5ae
shlq $0x2, %rdx
movl %ecx, (%r13,%rdx)
jmp 0x1c5ae
incq %rcx
cmpl %esi, %edx
ja 0x1c5ae
movl %edx, %edi
cmpl $0x0, (%r13,%rdi,4)
jne 0x1c607
movl %ecx, (%r13,%rdi,4)
incl %edx
jmp 0x1c5f4