// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %r13
testq %rsi, %rsi
je 0x1255f
movq 0x30(%r13), %r9
movq 0x60(%r13), %r8
leaq 0x40(%rsp), %rax
leaq 0x38(%rsp), %rdx
movq %rsp, %rcx
movq %rsi, %rdi
movq %rax, %rsi
callq *0x28(%r13)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $-0x2, %eax
je 0x12a13
cmpl $-0x1, %eax
je 0x12a10
movq $0x0, 0x38(%r13)
movq 0x40(%rsp), %r12
movl 0x38(%rsp), %eax
subl %r12d, %eax
incl %eax
movslq %eax, %r15
leaq 0x1(%r15), %rax
cmpq 0x40(%r13), %rax
jb 0x124df
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(%r13)
movq 0x48(%r13), %rdi
callq 0x37b0
testq %rax, %rax
je 0x12503
movq %rax, 0x48(%r13)
movq 0x48(%r13), %rdi
addq 0x38(%r13), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3850
addq 0x38(%r13), %r15
movq %r15, 0x38(%r13)
movq 0x48(%r13), %rax
movb $0x0, (%rax,%r15)
movq 0x10(%r13), %r12
xorl %r15d, %r15d
testq %r12, %r12
je 0x12612
movl (%r12), %eax
testl %eax, %eax
je 0x1260a
movq %r13, 0x8(%rsp)
movq 0x48(%r13), %rsi
movq %rax, 0x10(%rsp)
leal -0x1(%rax), %edi
movsbl (%rsi), %r13d
testl %r13d, %r13d
je 0x1256c
movb 0x1(%rsi), %al
testb %al, %al
je 0x1256f
leaq 0x2(%rsi), %rcx
movl %r13d, %edx
shll $0x5, %edx
subl %r13d, %edx
movsbl %al, %r13d
addl %edx, %r13d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x12544
jmp 0x1256f
movq %r13, %rdi
callq 0x122df
jmp 0x12a10
xorl %r13d, %r13d
andl %edi, %r13d
movq 0x10(%r12), %rdx
movl $0x1, %ebx
movl %r13d, %r15d
movq %r12, 0x20(%rsp)
movl %edi, 0x18(%rsp)
movq %rsi, 0x30(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r14d
leal (%r15,%r15), %ebp
andl $0x1e, %ebp
movl %r14d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x125ed
testb $0x1, %al
jne 0x125d6
movq 0x18(%r12), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rdx, %r12
callq 0x3620
movq %r12, %rdx
movl 0x18(%rsp), %edi
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %r12
testl %eax, %eax
je 0x125ed
addl %ebx, %r15d
andl %edi, %r15d
incl %ebx
cmpl %r13d, %r15d
jne 0x1258d
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0x125ff
movl %ebp, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x10(%rsp), %rax
cmovnel %eax, %r15d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x8(%rsp), %r13
cmpl %eax, %r15d
jne 0x12614
xorl %r15d, %r15d
jmp 0x12622
movq 0x20(%r12), %rax
movl %r15d, %ecx
movl (%rax,%rcx,4), %ebp
movb $0x1, %r15b
testb %r15b, %r15b
jne 0x1292d
movl (%r13), %eax
leal 0x1(%rax), %ecx
movl %ecx, (%r13)
movslq 0x4(%r13), %r15
cmpl %r15d, %eax
jl 0x1269d
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(%r13)
movq 0x8(%r13), %rdi
movslq %ecx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x37b0
movq %rax, 0x8(%r13)
leaq (%r15,%r15,4), %rcx
leaq (%rax,%rcx,8), %rdi
movslq 0x4(%r13), %rax
subq %r15, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
xorl %esi, %esi
callq 0x3090
movl (%r13), %eax
cmpl %r15d, %eax
jle 0x126f9
decl %eax
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
movq 0x18(%r13), %rdi
movslq %ecx, %rbx
leaq 0x8(,%rbx,8), %rsi
callq 0x37b0
movq %rax, 0x18(%r13)
leaq (%rax,%r15,8), %rdi
subl %r15d, %ebx
incl %ebx
movslq %ebx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3090
movq 0x48(%r13), %rdi
callq 0x35f0
movq 0x18(%r13), %rdx
movslq (%r13), %rcx
movq %rax, -0x8(%rdx,%rcx,8)
movq 0x10(%r13), %r12
testq %r12, %r12
je 0x12740
movq 0x18(%r13), %rax
movq -0x8(%rax,%rcx,8), %rbp
movl 0x8(%r12), %eax
cmpl 0xc(%r12), %eax
jb 0x1275c
movl (%r12), %esi
movl 0x4(%r12), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x1274a
decl %esi
jmp 0x1274c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1292d
incl %esi
movq %r12, %rdi
callq 0x1323e
testl %eax, %eax
js 0x12845
movl (%r12), %esi
leal -0x1(%rsi), %r8d
movsbl (%rbp), %r15d
testl %r15d, %r15d
je 0x12794
movb 0x1(%rbp), %al
testb %al, %al
je 0x12797
leaq 0x2(%rbp), %rcx
movl %r15d, %edx
shll $0x5, %edx
subl %r15d, %edx
movsbl %al, %r15d
addl %edx, %r15d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x12779
jmp 0x12797
xorl %r15d, %r15d
movq %r13, 0x8(%rsp)
andl %r8d, %r15d
movq 0x10(%r12), %rdi
movl %r15d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %eax
leal (%r15,%r15), %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x12891
movq %rbp, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movl $0x1, %r12d
movl %r15d, %r13d
movq %rsi, 0x28(%rsp)
movl %esi, %ebx
movq %rdi, 0x30(%rsp)
movl %r8d, 0x10(%rsp)
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %r14d
leal (,%r13,2), %ebp
andl $0x1e, %ebp
movl %r14d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x1284e
testb $0x1, %al
jne 0x1282b
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x18(%rsp), %rsi
callq 0x3620
movl 0x10(%rsp), %r8d
movq 0x30(%rsp), %rdi
testl %eax, %eax
je 0x1284e
btl %ebp, %r14d
cmovbl %r13d, %ebx
addl %r12d, %r13d
andl %r8d, %r13d
incl %r12d
movl %ebx, %eax
cmpl %r15d, %r13d
jne 0x127df
jmp 0x12853
movl (%r12), %r15d
jmp 0x128d8
movq 0x28(%rsp), %rax
movl %eax, %r15d
movq 0x28(%rsp), %rdx
cmpl %edx, %eax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r12
movq 0x18(%rsp), %rbp
jne 0x12891
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %eax
leal (,%r13,2), %ecx
shrl %cl, %eax
cmpl %edx, %ebx
cmovel %r13d, %ebx
testb $0x2, %al
cmovel %r13d, %ebx
movl %ebx, %r15d
movl %r15d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %esi
leal (%r15,%r15), %ecx
andl $0x1e, %ecx
shrl %cl, %esi
testb $0x2, %sil
jne 0x128dc
movb $0x1, %dl
testb $0x1, %sil
movq 0x8(%rsp), %r13
je 0x1290a
movq 0x18(%r12), %rdx
movl %r15d, %esi
movq %rbp, (%rdx,%rsi,8)
movl $0x3, %edx
shll %cl, %edx
notl %edx
movq 0x10(%r12), %rcx
andl %edx, (%rcx,%rax,4)
incl 0x4(%r12)
xorl %edx, %edx
jmp 0x1290a
movq 0x18(%r12), %rdx
movl %r15d, %esi
movq %rbp, (%rdx,%rsi,8)
movl $0x3, %edx
shll %cl, %edx
notl %edx
movq 0x10(%r12), %rcx
andl %edx, (%rcx,%rax,4)
incl 0x4(%r12)
incl 0x8(%r12)
xorl %edx, %edx
movq 0x8(%rsp), %r13
testb %dl, %dl
je 0x1291b
movq 0x20(%r12), %rax
movl %r15d, %ecx
movl (%rax,%rcx,4), %ebp
jmp 0x1292d
movl 0x4(%r12), %ebp
decl %ebp
movq 0x20(%r12), %rax
movl %r15d, %ecx
movl %ebp, (%rax,%rcx,4)
movq 0x8(%r13), %rax
movslq %ebp, %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rbx
movl 0xc(%rbx), %eax
movl 0x10(%rbx), %r15d
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rbx)
cmpl %r15d, %eax
jl 0x1298e
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(%rbx)
movq 0x18(%rbx), %rdi
movslq %ecx, %rax
leaq 0x8(,%rax,8), %rsi
callq 0x37b0
movq %rax, 0x18(%rbx)
movq 0x18(%rbx), %rax
movslq 0xc(%rbx), %rcx
movq (%rsp), %rdx
movq %rdx, -0x8(%rax,%rcx,8)
movl 0x5c(%r13), %eax
testl %eax, %eax
je 0x129de
movl 0x10(%rbx), %ecx
cmpl %ecx, %r15d
jge 0x129c2
movq 0x20(%rbx), %rdi
imull %eax, %ecx
movslq %ecx, %rsi
callq 0x37b0
movq %rax, 0x20(%rbx)
movslq 0x5c(%r13), %rdx
movslq 0xc(%rbx), %rdi
decq %rdi
imulq %rdx, %rdi
addq 0x20(%rbx), %rdi
movq 0x60(%r13), %rsi
callq 0x3850
cmpl %ebp, 0x50(%r13)
jne 0x129fd
movl 0x54(%r13), %ecx
movl (%rsp), %r10d
cmpl %r10d, %ecx
ja 0x12a25
jne 0x129fd
movl 0x58(%r13), %eax
cmpl 0x4(%rsp), %eax
ja 0x12a25
movl %ebp, 0x50(%r13)
movl (%rsp), %eax
movl %eax, 0x54(%r13)
movl 0x4(%rsp), %eax
movl %eax, 0x58(%r13)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4b5bc(%rip), %rax     # 0x5dfe8
movq (%rax), %rdi
movq 0x48(%r13), %rdx
incl %ecx
movl 0x58(%r13), %r8d
incl %r8d
incl %r10d
movl 0x4(%rsp), %r11d
incl %r11d
leaq 0x3bd5a(%rip), %rsi     # 0x4e7a8
movq %rdx, %r9
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x37e0
addq $0x10, %rsp
jmp 0x12a13