// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rsi, %r12
testq %r8, %r8
je 0x20a51
movq $0x0, 0x18(%r15)
movq 0x10(%rdi), %r8
testq %r8, %r8
je 0x20b33
movl (%r8), %eax
xorl %r14d, %r14d
movl $0x0, %ebx
testl %eax, %eax
je 0x20b63
movq %rax, 0x28(%rsp)
leal -0x1(%rax), %r10d
movb (%r12), %r9b
testb %r9b, %r9b
movq %r15, 0x30(%rsp)
movq %rdi, 0x8(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
je 0x20abd
leaq 0x1(%r12), %rax
movl $0x811c9dc5, %r14d      # imm = 0x811C9DC5
movzbl %r9b, %ecx
xorl %r14d, %ecx
imull $0x1000193, %ecx, %r14d # imm = 0x1000193
movb (%rax), %r9b
incq %rax
testb %r9b, %r9b
jne 0x20aa2
jmp 0x20ac3
movl $0x811c9dc5, %r14d      # imm = 0x811C9DC5
andl %r10d, %r14d
movq 0x10(%r8), %rdx
movl $0x1, %r13d
movl %r14d, %ebx
movq %r8, 0x40(%rsp)
movl %r10d, 0x38(%rsp)
movq %rdx, 0x10(%rsp)
movl %ebx, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r15d
leal (%rbx,%rbx), %ebp
andl $0x1e, %ebp
movl %r15d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x20b3b
testb $0x1, %al
jne 0x20b25
movq 0x18(%r8), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rdi
movq %r12, %rsi
callq 0x46c0
movq 0x10(%rsp), %rdx
movl 0x38(%rsp), %r10d
movq 0x40(%rsp), %r8
testl %eax, %eax
je 0x20b3b
addl %r13d, %ebx
andl %r10d, %ebx
incl %r13d
cmpl %r14d, %ebx
jne 0x20ae2
xorl %r14d, %r14d
jmp 0x20fe9
movl %ebp, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x28(%rsp), %rax
cmovnel %eax, %ebx
xorl %r14d, %r14d
movq 0x30(%rsp), %r15
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
cmpl %eax, %ebx
je 0x20fe9
movq 0x20(%r8), %rax
movl %ebx, %esi
movslq (%rax,%rsi,4), %rax
movq 0x8(%rdi), %r13
imulq $0x38, %rax, %rax
movl 0xc(%r13,%rax), %r12d
testq %r12, %r12
je 0x20c1b
addq %rax, %r13
cmpl $0x1, %r12d
jne 0x20c23
movq 0x18(%r13), %r8
cmpq %rdx, 0x8(%r8)
jl 0x20fe9
xorl %eax, %eax
movl $0x0, %r14d
cmpq %rcx, (%r8)
jg 0x20fe9
movl $0x1, %r14d
testq %r15, %r15
je 0x20fe9
movq 0x20(%r15), %rsi
movq %rdi, 0x18(%rsi)
movq %r13, 0x20(%rsi)
movq %rdx, (%rsi)
movq %rcx, 0x8(%rsi)
movl %eax, 0x10(%rsi)
movl $0x0, 0x28(%rsi)
movq 0x28(%r13), %rdx
movq %rdx, 0x18(%r15)
movslq %eax, %rdx
shlq $0x4, %rdx
movdqu (%r8,%rdx), %xmm0
movdqu %xmm0, (%r15)
movl 0x38(%rdi), %ecx
testl %ecx, %ecx
je 0x20fe9
imull %eax, %ecx
movslq %ecx, %rax
addq 0x20(%r13), %rax
movq %rax, 0x10(%r15)
jmp 0x20fe9
movl %r12d, %r14d
jmp 0x20fe9
movq (%r13), %rbp
testq %rbp, %rbp
je 0x20c93
movq %rdx, %r8
shrq $0xd, %r8
movl 0x8(%r13), %esi
cmpl %r8d, %esi
jbe 0x20fe9
movslq %r8d, %rax
movl (%rbp,%rax,4), %eax
testl %eax, %eax
je 0x20e1b
decl %eax
movl 0xc(%r13), %r9d
cmpl %r9d, %eax
jae 0x20fe9
movq 0x18(%r13), %r8
movslq %eax, %rsi
shlq $0x4, %rsi
addq %r8, %rsi
addq $0x8, %rsi
cmpq %rcx, -0x8(%rsi)
jg 0x20fe9
cmpq %rdx, (%rsi)
jge 0x20bb7
incl %eax
addq $0x10, %rsi
cmpl %eax, %r9d
ja 0x20c70
jmp 0x20fe9
cmpl $0x0, 0x30(%r13)
movq %rdi, 0x8(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
je 0x20e4e
cmpl $0x0, 0x38(%rdi)
je 0x20e5b
leaq (,%r12,8), %rdi
callq 0x4680
testq %rax, %rax
je 0x20fe3
movq 0x18(%r13), %rdi
leaq 0x1(%r12), %rcx
andq $-0x2, %rcx
leaq -0x1(%r12), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x73b8f(%rip), %xmm1    # 0x94880
xorl %edx, %edx
movdqa 0x73b95(%rip), %xmm2    # 0x94890
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x761f5(%rip), %xmm4    # 0x96f00
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %esi
notl %esi
testb $0x1, %sil
je 0x20d41
movq %rdi, (%rax,%rdx,8)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x20d59
leaq 0x10(%rdi), %rsi
movq %rsi, 0x8(%rax,%rdx,8)
addq $0x2, %rdx
paddq %xmm4, %xmm1
addq $0x20, %rdi
cmpq %rdx, %rcx
jne 0x20d0b
leaq 0x925(%rip), %rcx       # 0x21696
movl $0x8, %edx
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r12, %rsi
callq 0x4990
movq 0x8(%rsp), %rax
movslq 0x38(%rax), %r12
movl 0xc(%r13), %ebp
movl %ebp, %edi
imull %r12d, %edi
callq 0x4680
testq %rax, %rax
je 0x20fd9
movq %rax, %rbx
testq %rbp, %rbp
je 0x20e79
movq %r15, 0x30(%rsp)
movq 0x18(%r13), %rax
movq %rax, 0x40(%rsp)
movq 0x20(%r13), %rdi
xorl %r15d, %r15d
movq %rbx, 0x28(%rsp)
movq %rbp, 0x38(%rsp)
movq %rbx, %rbp
movq 0x10(%rsp), %rbx
movq (%rbx,%r15,8), %rsi
subq 0x40(%rsp), %rsi
sarq $0x4, %rsi
imulq %r12, %rsi
addq %rdi, %rsi
movq %rdi, %r14
movq %rbp, %rdi
movq %r12, %rdx
callq 0x43c0
movq %r14, %rdi
incq %r15
addq %r12, %rbp
cmpq %r15, 0x38(%rsp)
jne 0x20dda
xorl %r14d, %r14d
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %rbx
jmp 0x20e7d
movq %rcx, %r9
shrq $0xd, %r9
cmpl %r9d, %esi
cmovbl %esi, %r9d
cmpl %r8d, %r9d
jb 0x20fe9
movl %r8d, %eax
movl (%rbp,%rax,4), %eax
testl %eax, %eax
jne 0x20c4f
incl %r8d
cmpl %r9d, %r8d
jbe 0x20e32
jmp 0x20fe9
movl $0x0, 0x8(%r13)
jmp 0x20ef9
movq 0x18(%r13), %rdi
leaq 0x7f7(%rip), %rcx       # 0x2165d
movl $0x10, %edx
movq %r12, %rsi
callq 0x4990
movl 0xc(%r13), %r12d
jmp 0x20ee6
movq 0x20(%r13), %rdi
callq 0x45c0
movq %rbx, 0x20(%r13)
movl 0xc(%r13), %ebx
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x4680
testq %rax, %rax
je 0x20fd9
movq %rax, %r12
movq 0x18(%r13), %rbp
testq %rbx, %rbx
movq 0x10(%rsp), %rdi
je 0x20ecd
shlq $0x3, %rbx
xorl %eax, %eax
movq (%rdi,%rax), %rcx
movdqu (%rcx), %xmm0
movdqu %xmm0, (%r12,%rax,2)
addq $0x8, %rax
cmpq %rax, %rbx
jne 0x20eb6
callq 0x45c0
movq %rbp, %rdi
callq 0x45c0
movq %r12, 0x18(%r13)
movl 0xc(%r13), %r12d
movl %r12d, 0x10(%r13)
xorl %eax, %eax
movl %eax, 0x30(%r13)
movl %eax, 0x8(%r13)
testl %r12d, %r12d
je 0x20ffb
movq 0x18(%r13), %rax
movl %r12d, %esi
addq $0x8, %rax
xorl %ebx, %ebx
movl %ebx, %r8d
movq (%rax), %rbx
shrq $0xd, %rbx
cmpl %ebx, %r8d
cmoval %r8d, %ebx
addq $0x10, %rax
decq %rsi
jne 0x20f06
incl %ebx
movl %ebx, %edi
movl $0x4, %esi
callq 0x4300
testq %rax, %rax
je 0x20fe3
movq %rax, %rbp
movq (%r13), %rdi
callq 0x45c0
movq %rbp, (%r13)
movl %ebx, 0x8(%r13)
movl 0xc(%r13), %eax
testq %rax, %rax
je 0x20fc5
movq 0x18(%r13), %rcx
xorl %r9d, %r9d
movq 0x18(%rsp), %rdx
movq %r9, %rdi
shlq $0x4, %rdi
movq (%rcx,%rdi), %rsi
movq 0x8(%rcx,%rdi), %rdi
shrq $0xd, %rsi
shrq $0xd, %rdi
cmpl %edi, %esi
jne 0x20f94
movslq %esi, %rsi
cmpl $0x0, (%rbp,%rsi,4)
jne 0x20fae
shlq $0x2, %rsi
leal 0x1(%r9), %edi
movl %edi, (%rbp,%rsi)
jmp 0x20fae
ja 0x20fae
leal 0x1(%r9), %r8d
movl %esi, %esi
cmpl $0x0, (%rbp,%rsi,4)
jne 0x20fa8
movl %r8d, (%rbp,%rsi,4)
incl %esi
cmpl %edi, %esi
jbe 0x20f9a
incq %r9
cmpq %rax, %r9
jne 0x20f60
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rcx
jmp 0x20c2c
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
jmp 0x20c2c
movq 0x10(%rsp), %rdi
callq 0x45c0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %ebx
jmp 0x20f22