// File: /workspace/github_c_makefile_star2_O2/zhou-lab[P]tbmate/htslib/regidx.c
// Function: regidx_insert
int regidx_insert(regidx_t *idx, char *line)
{
    if ( !line )
        return _regidx_build_index(idx);

    char *chr_from, *chr_to;
    reg_t reg;
    int ret = idx->parse(line,&chr_from,&chr_to,&reg,idx->payload,idx->usr);
    if ( ret==-2 ) return -1;   // error
    if ( ret==-1 ) return 0;    // skip the line

    int rid;
    idx->str.l = 0;
    kputsn(chr_from, chr_to-chr_from+1, &idx->str);
    if ( khash_str2int_get(idx->seq2regs, idx->str.s, &rid)!=0 )
    {
        idx->nseq++;
        int m_prev = idx->mseq;
        hts_expand0(reglist_t,idx->nseq,idx->mseq,idx->seq);
        hts_expand0(char*,idx->nseq,m_prev,idx->seq_names);
        idx->seq_names[idx->nseq-1] = strdup(idx->str.s);
        rid = khash_str2int_inc(idx->seq2regs, idx->seq_names[idx->nseq-1]);
    }

    reglist_t *list = &idx->seq[rid];
    list->nregs++;
    int m_prev = list->mregs;
    hts_expand(reg_t,list->nregs,list->mregs,list->regs);
    list->regs[list->nregs-1] = reg;
    if ( idx->payload_size )
    {
        if ( m_prev < list->mregs ) list->payload = realloc(list->payload,idx->payload_size*list->mregs);
        memcpy(list->payload + idx->payload_size*(list->nregs-1), idx->payload, idx->payload_size);
    }

    if ( idx->rid_prev==rid )
    {
        if ( idx->start_prev > reg.start || (idx->start_prev==reg.start && idx->end_prev>reg.end) ) 
        { 
            fprintf(stderr,"The regions are not sorted: %s:%d-%d is before %s:%d-%d\n", 
                idx->str.s,idx->start_prev+1,idx->end_prev+1,idx->str.s,reg.start+1,reg.end+1); 
            return -1;
        }
    }
    idx->rid_prev = rid;
    idx->start_prev = reg.start;
    idx->end_prev = reg.end;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
testq %rsi, %rsi
je 0xead8
movq 0x30(%rbx), %r9
movq 0x60(%rbx), %r8
leaq 0x50(%rsp), %rax
leaq 0x48(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rsi, %rdi
movq %rax, %rsi
callq *0x28(%rbx)
cmpl $-0x2, %eax
je 0xef5c
cmpl $-0x1, %eax
je 0xef1f
andq $0x0, 0x38(%rbx)
movq 0x50(%rsp), %r15
movl 0x48(%rsp), %eax
subl %r15d, %eax
incl %eax
movslq %eax, %r14
leaq 0x1(%r14), %rax
cmpq 0x40(%rbx), %rax
jae 0xeae5
movq 0x48(%rbx), %rax
xorl %edi, %edi
jmp 0xeb33
movq %rbx, %rdi
callq 0xe958
jmp 0xef1f
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x40(%rbx)
movq 0x48(%rbx), %rdi
callq 0x37c0
testq %rax, %rax
je 0xeb52
movq %rax, 0x48(%rbx)
movq 0x38(%rbx), %rdi
addq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3860
addq 0x38(%rbx), %r14
movq %r14, 0x38(%rbx)
movq 0x48(%rbx), %rax
movb $0x0, (%rax,%r14)
movq 0x10(%rbx), %rdi
movq 0x48(%rbx), %rsi
leaq 0xc(%rsp), %rdx
callq 0xe839
testl %eax, %eax
je 0xec32
movl (%rbx), %eax
leal 0x1(%rax), %ebp
movl %ebp, (%rbx)
movslq 0x4(%rbx), %r15
cmpl %r15d, %eax
jl 0xebd2
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
incl %ecx
movl %ecx, 0x4(%rbx)
movq 0x8(%rbx), %rdi
movslq %ecx, %rax
imulq $0x28, %rax, %rsi
callq 0x37c0
movq %rax, 0x8(%rbx)
imulq $0x28, %r15, %rdi
addq %rax, %rdi
movslq 0x4(%rbx), %rax
subq %r15, %rax
imulq $0x28, %rax, %rdx
xorl %esi, %esi
callq 0x3090
movl (%rbx), %ebp
cmpl %r15d, %ebp
jle 0xec3b
decl %ebp
movl %ebp, %eax
sarl %eax
orl %ebp, %eax
movl %eax, %ecx
sarl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x10, %eax
orl %ecx, %eax
movq 0x18(%rbx), %rdi
movslq %eax, %r12
leaq 0x8(,%r12,8), %rsi
callq 0x37c0
movq %rax, %r14
movq %rax, 0x18(%rbx)
leaq (%rax,%r15,8), %rdi
subl %r15d, %r12d
incl %r12d
movslq %r12d, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3090
movl (%rbx), %ebp
jmp 0xec3f
movl 0xc(%rsp), %eax
jmp 0xee2b
movq 0x18(%rbx), %r14
movq 0x48(%rbx), %rdi
callq 0x3600
movslq %ebp, %rcx
movq %rax, -0x8(%r14,%rcx,8)
movq 0x10(%rbx), %r14
testq %r14, %r14
je 0xec87
movq 0x18(%rbx), %rax
movq -0x8(%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
movq %rbx, 0x38(%rsp)
jb 0xeca1
movl (%r14), %esi
movl 0x4(%r14), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0xec8f
decl %esi
jmp 0xec91
pushq $-0x1
popq %rax
jmp 0xee27
incl %esi
movq %r14, %rdi
callq 0xf5a9
testl %eax, %eax
js 0xed65
movl (%r14), %r13d
leal -0x1(%r13), %ebx
movq 0x18(%rsp), %rdi
callq 0xf58e
movl %eax, %edi
andl %ebx, %edi
movq 0x10(%r14), %rdx
movl %edi, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %eax
leal (%rdi,%rdi), %ecx
shrl %cl, %eax
testb $0x2, %al
je 0xecd3
movl %edi, %r13d
jmp 0xed96
movq %r14, 0x20(%rsp)
pushq $0x1
popq %r14
movl %edi, %r12d
movq %r13, 0x30(%rsp)
movq %rdi, 0x40(%rsp)
movl %ebx, 0x2c(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r15d
leal (%r12,%r12), %ebp
andl $0x1e, %ebp
movl %r15d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0xed6d
testb $0x1, %al
jne 0xed3a
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x18(%rsp), %rsi
movq %rdx, %rbx
callq 0x3630
movq 0x40(%rsp), %rdi
movq %rbx, %rdx
movl 0x2c(%rsp), %ebx
testl %eax, %eax
je 0xed6d
btl %ebp, %r15d
cmovbl %r12d, %r13d
addl %r14d, %r12d
andl %ebx, %r12d
incl %r14d
cmpl %edi, %r12d
jne 0xeced
movb $0x1, %al
movq 0x30(%rsp), %rsi
movl %esi, %ecx
cmpl %esi, %r13d
movq 0x20(%rsp), %r14
je 0xed89
jmp 0xed96
movl (%r14), %r13d
jmp 0xee12
movl %ebp, %ecx
shrl %cl, %r15d
testb $0x2, %r15b
sete %al
movl %r13d, %ecx
movl %r12d, %edi
movq 0x20(%rsp), %r14
movq 0x30(%rsp), %rsi
cmpl %esi, %ecx
cmovel %edi, %ecx
testb %al, %al
cmovnel %edi, %ecx
movl %ecx, %r13d
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %edx
leal (,%r13,2), %ecx
andl $0x1e, %ecx
shrl %cl, %edx
movl %r13d, %esi
testb $0x2, %dl
jne 0xedc2
testb $0x1, %dl
jne 0xedf3
movq 0x20(%r14), %rax
movl (%rax,%rsi,4), %eax
jmp 0xee22
movq 0x18(%r14), %rdx
movq 0x18(%rsp), %rdi
movq %rdi, (%rdx,%rsi,8)
pushq $0x3
popq %rdx
shll %cl, %edx
notl %edx
movq 0x10(%r14), %rcx
andl %edx, (%rcx,%rax,4)
movq 0x4(%r14), %xmm0
pcmpeqd %xmm1, %xmm1
psubd %xmm1, %xmm0
movq %xmm0, 0x4(%r14)
jmp 0xee12
movq 0x18(%r14), %rdx
movq 0x18(%rsp), %rdi
movq %rdi, (%rdx,%rsi,8)
pushq $0x3
popq %rdx
shll %cl, %edx
notl %edx
movq 0x10(%r14), %rcx
andl %edx, (%rcx,%rax,4)
incl 0x4(%r14)
movl 0x4(%r14), %eax
decl %eax
movq 0x20(%r14), %rcx
movl %r13d, %edx
movl %eax, (%rcx,%rdx,4)
movq 0x38(%rsp), %rbx
movl %eax, 0xc(%rsp)
movq 0x8(%rbx), %rdx
cltq
imulq $0x28, %rax, %rsi
leaq (%rdx,%rsi), %r14
movl 0xc(%rdx,%rsi), %eax
movl 0x10(%rdx,%rsi), %ebp
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rdx,%rsi)
cmpl %ebp, %eax
jge 0xee52
movq 0x18(%r14), %rax
jmp 0xee97
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x10(%r14)
movq 0x18(%r14), %rdi
movslq %ecx, %rax
leaq 0x8(,%rax,8), %rsi
callq 0x37c0
movq %rax, 0x18(%r14)
movl 0xc(%r14), %ecx
movslq %ecx, %rcx
movq 0x10(%rsp), %rdx
movq %rdx, -0x8(%rax,%rcx,8)
movl 0x5c(%rbx), %ecx
testl %ecx, %ecx
je 0xeee6
movl 0x10(%r14), %edx
movq 0x20(%r14), %rax
cmpl %edx, %ebp
jge 0xeecc
imull %ecx, %edx
movslq %edx, %rsi
movq %rax, %rdi
callq 0x37c0
movq %rax, 0x20(%r14)
movl 0x5c(%rbx), %ecx
movslq 0xc(%r14), %rdi
decq %rdi
movslq %ecx, %rdx
imulq %rdx, %rdi
addq %rax, %rdi
movq 0x60(%rbx), %rsi
callq 0x3860
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %r10d
cmpl %eax, 0x50(%rbx)
jne 0xef11
movl 0x54(%rbx), %ecx
cmpl %r10d, %ecx
ja 0xef23
jne 0xef11
movl 0x58(%rbx), %r8d
movl 0x14(%rsp), %r11d
cmpl %r11d, %r8d
ja 0xef2c
movl 0x10(%rsp), %r10d
movl %eax, 0x50(%rbx)
movl %r10d, 0x54(%rbx)
movl 0x14(%rsp), %eax
movl %eax, 0x58(%rbx)
xorl %eax, %eax
jmp 0xef5f
movl 0x58(%rbx), %r8d
movl 0x14(%rsp), %r11d
movq 0x440b5(%rip), %rax     # 0x52fe8
movq (%rax), %rdi
movq 0x48(%rbx), %rdx
incl %ecx
incl %r8d
incl %r10d
incl %r11d
leaq 0x318be(%rip), %rsi     # 0x4080a
movq %rdx, %r9
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x37f0
popq %rcx
popq %rdx
pushq $-0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq