// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %r8, %rbx
movq %rsi, %r13
testq %r8, %r8
je 0x213c4
movq $0x0, 0x18(%rbx)
movq 0x10(%rdi), %r8
xorl %r12d, %r12d
testq %r8, %r8
je 0x214d7
movl (%r8), %eax
testl %eax, %eax
je 0x214cf
movq %rax, 0x10(%rsp)
leal -0x1(%rax), %r10d
movb (%r13), %r9b
testb %r9b, %r9b
movq %rbx, 0x20(%rsp)
movq %rdi, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
je 0x2142a
leaq 0x1(%r13), %rax
movl $0x811c9dc5, %r15d      # imm = 0x811C9DC5
movzbl %r9b, %ecx
xorl %r15d, %ecx
imull $0x1000193, %ecx, %r15d # imm = 0x1000193
movb (%rax), %r9b
incq %rax
testb %r9b, %r9b
jne 0x2140f
jmp 0x21430
movl $0x811c9dc5, %r15d      # imm = 0x811C9DC5
andl %r10d, %r15d
movq 0x10(%r8), %rdx
movl $0x1, %r14d
movl %r15d, %r12d
movq %r8, 0x40(%rsp)
movl %r10d, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %ebx
leal (%r12,%r12), %ebp
andl $0x1e, %ebp
movl %ebx, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x214ab
testb $0x1, %al
jne 0x21493
movq 0x18(%r8), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r13, %rsi
callq 0x46c0
movq 0x30(%rsp), %rdx
movl 0x38(%rsp), %r10d
movq 0x40(%rsp), %r8
testl %eax, %eax
je 0x214ab
addl %r14d, %r12d
andl %r10d, %r12d
incl %r14d
cmpl %r15d, %r12d
jne 0x2144f
movq 0x10(%rsp), %rax
movl %eax, %r12d
jmp 0x214bb
movl %ebp, %ecx
shrl %cl, %ebx
testb $0x3, %bl
movq 0x10(%rsp), %rax
cmovnel %eax, %r12d
movq 0x20(%rsp), %rbx
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
cmpl %eax, %r12d
jne 0x214db
xorl %r12d, %r12d
xorl %eax, %eax
jmp 0x214e8
movq 0x20(%r8), %rax
movl %r12d, %esi
movslq (%rax,%rsi,4), %r12
movb $0x1, %al
xorl %ebp, %ebp
testb %al, %al
je 0x21961
movq 0x8(%rdi), %r14
imulq $0x38, %r12, %rax
movl 0xc(%r14,%rax), %r15d
testq %r15, %r15
je 0x21530
addq %rax, %r14
cmpl $0x1, %r15d
jne 0x21538
movq 0x18(%r14), %rsi
cmpq %rdx, 0x8(%rsi)
jl 0x21961
xorl %eax, %eax
movl $0x0, %ebp
cmpq %rcx, (%rsi)
jle 0x217a9
jmp 0x21961
movl %r15d, %ebp
jmp 0x21961
movq %rdx, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
cmpq $0x0, (%r14)
je 0x215c5
movq 0x28(%rsp), %rdx
movq %rdx, %rax
shrq $0xd, %rax
movl 0x8(%r14), %esi
xorl %ebp, %ebp
cmpl %eax, %esi
jbe 0x215b3
movq (%r14), %r8
movslq %eax, %rcx
movl (%r8,%rcx,4), %r11d
testl %r11d, %r11d
movq 0x18(%rsp), %rcx
jne 0x2176b
movq %rcx, %r9
shrq $0xd, %r9
cmpl %r9d, %esi
cmovbl %esi, %r9d
cmpl %eax, %r9d
setb %sil
jb 0x2175e
movl %eax, %edi
cmpl $0x0, (%r8,%rdi,4)
jne 0x21753
incl %eax
cmpl %r9d, %eax
seta %sil
jbe 0x21596
jmp 0x2175e
xorl %r10d, %r10d
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rcx
jmp 0x2179f
cmpl $0x0, 0x30(%r14)
movq 0x8(%rsp), %rax
je 0x21880
cmpl $0x0, 0x38(%rax)
je 0x21736
leaq (,%r15,8), %rdi
callq 0x4680
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x21961
movq %rax, %r13
testl %r15d, %r15d
je 0x21619
movq 0x18(%r14), %rax
xorl %ecx, %ecx
movq %rax, (%r13,%rcx,8)
incq %rcx
addq $0x10, %rax
cmpq %rcx, %r15
jne 0x21608
leaq 0xa4e(%rip), %rcx       # 0x2206e
movl $0x8, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x4990
movq 0x8(%rsp), %rax
movslq 0x38(%rax), %r15
movl 0xc(%r14), %r12d
movl %r12d, %edi
imull %r15d, %edi
callq 0x4680
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x21843
movq %r14, 0x10(%rsp)
movq %rbx, 0x20(%rsp)
testq %r12, %r12
je 0x216c0
movq %r12, %rax
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rdx
movq %rdx, 0x40(%rsp)
movq 0x20(%rcx), %rcx
movq %rcx, 0x38(%rsp)
xorl %ebx, %ebx
movq 0x30(%rsp), %r12
movq (%r13,%rbx,8), %rsi
subq 0x40(%rsp), %rsi
sarq $0x4, %rsi
imulq %r15, %rsi
addq 0x38(%rsp), %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %r13, %r14
movq %rax, %r13
callq 0x43c0
movq %r13, %rax
movq %r14, %r13
incq %rbx
addq %r15, %r12
cmpq %rbx, %rax
jne 0x21687
movq 0x10(%rsp), %r14
movq 0x20(%r14), %rdi
callq 0x45c0
movq 0x30(%rsp), %rax
movq %rax, 0x20(%r14)
movl 0xc(%r14), %ebx
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x4680
movq %rax, %r15
testq %rax, %rax
je 0x21862
testq %rbx, %rbx
je 0x21714
shlq $0x3, %rbx
xorl %eax, %eax
movq (%r13,%rax), %rcx
movups (%rcx), %xmm0
movups %xmm0, (%r15,%rax,2)
addq $0x8, %rax
cmpq %rax, %rbx
jne 0x216fe
movq %r13, %rdi
callq 0x45c0
movq 0x18(%r14), %rdi
callq 0x45c0
movq %r15, 0x18(%r14)
movl 0xc(%r14), %eax
movl %eax, 0x10(%r14)
jmp 0x2186a
movq 0x18(%r14), %rdi
leaq 0x8f4(%rip), %rcx       # 0x22035
movl $0x10, %edx
movq %r15, %rsi
callq 0x4990
jmp 0x21878
testb %sil, %sil
jne 0x2175e
movl %eax, %eax
movl (%r8,%rax,4), %eax
movl %eax, %r11d
testb %sil, %sil
je 0x2176b
xorl %r10d, %r10d
jmp 0x2179a
leal -0x1(%r11), %eax
movl 0xc(%r14), %esi
cmpl %esi, %eax
setb %r10b
jae 0x2179a
movq 0x18(%r14), %r9
movslq %eax, %r8
shlq $0x4, %r8
cmpq %rcx, (%r9,%r8)
movq 0x8(%rsp), %rdi
jle 0x21815
xorl %r10d, %r10d
jmp 0x2179f
movq 0x8(%rsp), %rdi
testb $0x1, %r10b
je 0x21961
movl $0x1, %ebp
testq %rbx, %rbx
je 0x21961
movq 0x20(%rbx), %rsi
movq %rdi, 0x18(%rsi)
movq %r14, 0x20(%rsi)
movq %rdx, (%rsi)
movq %rcx, 0x8(%rsi)
movl %eax, 0x10(%rsi)
movl $0x0, 0x28(%rsi)
movq 0x28(%r14), %rcx
movq %rcx, 0x18(%rbx)
movq 0x18(%r14), %rcx
movslq %eax, %rdx
shlq $0x4, %rdx
movq (%rcx,%rdx), %rsi
movq %rsi, (%rbx)
movq 0x8(%rcx,%rdx), %rcx
movq %rcx, 0x8(%rbx)
movl 0x38(%rdi), %ecx
testl %ecx, %ecx
je 0x21961
imull %eax, %ecx
movslq %ecx, %rax
addq 0x20(%r14), %rax
movq %rax, 0x10(%rbx)
jmp 0x21961
leaq (%r8,%r9), %rax
addq $0x10, %rax
cmpq %rdx, -0x8(%rax)
jge 0x21850
cmpl %r11d, %esi
seta %r10b
jbe 0x2185b
incl %r11d
leaq 0x10(%rax), %r8
cmpq %rcx, (%rax)
movq %r8, %rax
jle 0x2181d
decl %r11d
xorl %r10d, %r10d
jmp 0x21853
movq %r13, %rdi
callq 0x45c0
jmp 0x21961
decl %r11d
movl %r11d, %eax
jmp 0x2179f
movl %esi, %eax
jmp 0x2179f
movq %r13, %rdi
callq 0x45c0
testq %r15, %r15
movq 0x20(%rsp), %rbx
je 0x21961
movl $0x0, 0x30(%r14)
movq %rbx, %r15
movl $0x0, 0x8(%r14)
movl 0xc(%r14), %eax
testq %rax, %rax
je 0x218bd
movq 0x18(%r14), %rcx
shlq $0x4, %rax
xorl %edx, %edx
xorl %ebx, %ebx
movl %ebx, %esi
movq 0x8(%rcx,%rdx), %rbx
shrq $0xd, %rbx
cmpl %ebx, %esi
cmoval %esi, %ebx
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x218a0
incl %ebx
jmp 0x218c2
movl $0x1, %ebx
movl %ebx, %edi
movl $0x4, %esi
callq 0x4300
testq %rax, %rax
je 0x2195c
movq %rax, %r13
movq (%r14), %rdi
callq 0x45c0
movq %r13, (%r14)
movl %ebx, 0x8(%r14)
movl 0xc(%r14), %eax
testq %rax, %rax
movq %r15, %rbx
je 0x2154d
movq 0x18(%r14), %rcx
xorl %edx, %edx
movq %rdx, %rdi
shlq $0x4, %rdi
movq (%rcx,%rdi), %rsi
movq 0x8(%rcx,%rdi), %rdi
shrq $0xd, %rsi
shrq $0xd, %rdi
cmpl %edi, %esi
jne 0x21934
movslq %esi, %rsi
cmpl $0x0, (%r13,%rsi,4)
jne 0x2194f
shlq $0x2, %rsi
leal 0x1(%rdx), %edi
movl %edi, (%r13,%rsi)
jmp 0x2194f
ja 0x2194f
leal 0x1(%rdx), %r8d
movl %esi, %esi
cmpl $0x0, (%r13,%rsi,4)
jne 0x21949
movl %r8d, (%r13,%rsi,4)
incl %esi
cmpl %edi, %esi
jbe 0x2193a
incq %rdx
cmpq %rax, %rdx
jne 0x218ff
jmp 0x2154d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq