// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/htslib/hts.c
// Function: hts_idx_push
int hts_idx_push(hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int is_mapped)
{
    int bin;
    if (tid<0) beg = -1, end = 0;
    if (tid >= idx->m) { // enlarge the index
        int32_t oldm = idx->m;
        idx->m = idx->m? idx->m<<1 : 2;
        idx->bidx = (bidx_t**)realloc(idx->bidx, idx->m * sizeof(bidx_t*));
        idx->lidx = (lidx_t*) realloc(idx->lidx, idx->m * sizeof(lidx_t));
        memset(&idx->bidx[oldm], 0, (idx->m - oldm) * sizeof(bidx_t*));
        memset(&idx->lidx[oldm], 0, (idx->m - oldm) * sizeof(lidx_t));
    }
    if (idx->n < tid + 1) idx->n = tid + 1;
    if (idx->z.finished) return 0;
    if (idx->z.last_tid != tid || (idx->z.last_tid >= 0 && tid < 0)) { // change of chromosome
        if ( tid>=0 && idx->n_no_coor )
        {
            if (hts_verbose >= 1) fprintf(stderr,"[E::%s] NO_COOR reads not in a single block at the end %d %d\n", __func__, tid,idx->z.last_tid);
            return -1;
        }
        if (tid>=0 && idx->bidx[tid] != 0)
        {
            if (hts_verbose >= 1) fprintf(stderr, "[E::%s] chromosome blocks not continuous\n", __func__);
            return -1;
        }
        idx->z.last_tid = tid;
        idx->z.last_bin = 0xffffffffu;
    } else if (tid >= 0 && idx->z.last_coor > beg) { // test if positions are out of order
        if (hts_verbose >= 1) fprintf(stderr, "[E::%s] unsorted positions\n", __func__);
        return -1;
    }
    if ( tid>=0 )
    {
        if (idx->bidx[tid] == 0) idx->bidx[tid] = kh_init(bin);
        if ( is_mapped)
            insert_to_l(&idx->lidx[tid], beg, end, idx->z.last_off, idx->min_shift); // last_off points to the start of the current record
    }
    else idx->n_no_coor++;
    bin = hts_reg2bin(beg, end, idx->min_shift, idx->n_lvls);
    if ((int)idx->z.last_bin != bin) { // then possibly write the binning index
        if (idx->z.save_bin != 0xffffffffu) // save_bin==0xffffffffu only happens to the first record
            insert_to_b(idx->bidx[idx->z.save_tid], idx->z.save_bin, idx->z.save_off, idx->z.last_off);
        if (idx->z.last_bin == 0xffffffffu && idx->z.save_bin != 0xffffffffu) { // change of chr; keep meta information
            idx->z.off_end = idx->z.last_off;
            insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx), idx->z.off_beg, idx->z.off_end);
            insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx), idx->z.n_mapped, idx->z.n_unmapped);
            idx->z.n_mapped = idx->z.n_unmapped = 0;
            idx->z.off_beg = idx->z.off_end;
        }
        idx->z.save_off = idx->z.last_off;
        idx->z.save_bin = idx->z.last_bin = bin;
        idx->z.save_tid = tid;
    }
    if (is_mapped) ++idx->z.n_mapped;
    else ++idx->z.n_unmapped;
    idx->z.last_off = offset;
    idx->z.last_coor = beg;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x4(%rsp)
movq %r8, 0x20(%rsp)
movl %ecx, %r12d
movl %edx, %r13d
movl %esi, %ebx
movq %rdi, %r15
xorl %ebp, %ebp
testl %esi, %esi
cmovnsl %ecx, %ebp
pushq $-0x1
popq %rdx
movl %r13d, %eax
cmovsl %edx, %eax
movl %eax, 0x14(%rsp)
movslq 0x18(%rdi), %r14
cmpl %esi, %r14d
jg 0x48f7e
leal (%r14,%r14), %eax
testl %r14d, %r14d
pushq $0x2
popq %rcx
cmovnel %eax, %ecx
movl %ecx, 0x18(%r15)
movq 0x28(%r15), %rdi
movslq %ecx, %rsi
shlq $0x3, %rsi
callq 0x6c80
movq %rax, 0x28(%r15)
movq 0x30(%r15), %rdi
movslq 0x18(%r15), %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x30(%r15)
leaq (,%r14,8), %rdi
addq 0x28(%r15), %rdi
movslq 0x18(%r15), %rdx
subq %r14, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x63b0
movq %r14, %rdi
shlq $0x4, %rdi
addq 0x30(%r15), %rdi
movslq 0x18(%r15), %rdx
subq %r14, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x63b0
pushq $-0x1
popq %rdx
cmpl %ebx, 0x14(%r15)
jg 0x48f8b
leal 0x1(%rbx), %eax
movl %eax, 0x14(%r15)
xorl %eax, %eax
cmpl $0x0, 0x54(%r15)
jne 0x4918c
testl %ebx, %ebx
sets %al
movl 0x4c(%r15), %r8d
testl %r8d, %r8d
setns %cl
movl %ebx, %edi
cmpl %ebx, %r8d
jne 0x48fe3
andb %cl, %al
jne 0x48fe3
testl %ebx, %ebx
js 0x49032
cmpl %r13d, 0x48(%r15)
jle 0x49165
cmpl $0x0, 0x6be21(%rip)     # 0xb4de8
jle 0x4918a
movq 0x6a004(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x3e6db(%rip), %rsi     # 0x876b9
jmp 0x492b9
testl %ebx, %ebx
js 0x49029
cmpq $0x0, 0x20(%r15)
je 0x49172
cmpl $0x0, 0x6bdef(%rip)     # 0xb4de8
jle 0x4918a
movq 0x69fd2(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x3e634(%rip), %rsi     # 0x87644
movl %edx, %ebp
leaq 0x3e669(%rip), %rdx     # 0x87682
movl %ebx, %ecx
xorl %eax, %eax
callq 0x6a90
movl %ebp, %eax
jmp 0x4918c
movl %ebx, 0x4c(%r15)
orl $-0x1, 0x40(%r15)
incq 0x20(%r15)
movl 0x14(%rsp), %r12d
movslq %r12d, %rdi
movslq %ebp, %r8
movl 0x4(%r15), %esi
movl 0x8(%r15), %r9d
leal (%r9,%r9,2), %ecx
pushq $-0x1
popq %r10
movl %r10d, %eax
shll %cl, %eax
notl %eax
xorl %ebp, %ebp
pushq $0x7
popq %rcx
xorl %edx, %edx
divl %ecx
decq %r8
leal (%r9,%r9,2), %edx
addl $-0x3, %edx
testl %r9d, %r9d
jle 0x4909e
movq %rdi, %r11
movl %esi, %ecx
sarq %cl, %r11
movq %r8, %r14
sarq %cl, %r14
cmpq %r14, %r11
je 0x49099
movl %r10d, %r11d
movl %edx, %ecx
shll %cl, %r11d
decl %r9d
addl $0x3, %esi
addl %r11d, %eax
addl $-0x3, %edx
jmp 0x4906b
addl %r11d, %eax
movl %eax, %ebp
movl 0x40(%r15), %eax
cmpl %ebp, %eax
je 0x49145
movl 0x44(%r15), %esi
cmpl $-0x1, %esi
je 0x490d0
movslq 0x50(%r15), %rax
movq 0x28(%r15), %rdx
movq 0x58(%r15), %rcx
movq (%rdx,%rax,8), %rdi
movq 0x60(%r15), %rdx
callq 0x48cb0
movl 0x40(%r15), %eax
cmpl $-0x1, %eax
jne 0x49131
cmpl $-0x1, 0x44(%r15)
je 0x49131
movq 0x58(%r15), %rcx
movq %rcx, 0x70(%r15)
movq 0x28(%r15), %rax
movslq 0x50(%r15), %rdx
movq (%rax,%rdx,8), %rdi
movl 0xc(%r15), %esi
incl %esi
movq 0x68(%r15), %rdx
callq 0x48cb0
movq 0x28(%r15), %rax
movslq 0x50(%r15), %rcx
movq (%rax,%rcx,8), %rdi
movl 0xc(%r15), %esi
incl %esi
movq 0x78(%r15), %rdx
movq 0x80(%r15), %rcx
callq 0x48cb0
xorps %xmm0, %xmm0
movups %xmm0, 0x78(%r15)
movq 0x70(%r15), %rax
movq %rax, 0x68(%r15)
movq 0x58(%r15), %rax
movq %rax, 0x60(%r15)
movl %ebp, 0x40(%r15)
movl %ebp, 0x44(%r15)
movl %ebx, 0x50(%r15)
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
sete %al
incq 0x78(%r15,%rax,8)
movq 0x20(%rsp), %rax
movq %rax, 0x58(%r15)
movl %r12d, 0x48(%r15)
xorl %eax, %eax
jmp 0x4918c
movq 0x28(%r15), %r14
cmpq $0x0, (%r14,%rdi,8)
jne 0x491b7
jmp 0x491a4
movq 0x28(%r15), %r14
cmpq $0x0, (%r14,%rdi,8)
je 0x4919b
cmpl $0x0, 0x6bc64(%rip)     # 0xb4de8
jg 0x492a8
movl %edx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, 0x4c(%r15)
orl $-0x1, 0x40(%r15)
movq %rdi, 0x8(%rsp)
callq 0x492d0
movq 0x8(%rsp), %rdi
movq %rax, (%r14,%rdi,8)
cmpl $0x0, 0x4(%rsp)
je 0x49036
movq 0x30(%r15), %rax
shlq $0x4, %rdi
movslq %r13d, %r13
movslq %r12d, %rdx
movb 0x4(%r15), %cl
sarq %cl, %r13
decq %rdx
sarq %cl, %rdx
leaq (%rax,%rdi), %r12
movq 0x58(%r15), %rsi
movslq 0x4(%rax,%rdi), %r14
cmpl %edx, %r14d
jg 0x49260
movl %edx, %eax
sarl %eax
orl %edx, %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
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%r12)
movq 0x8(%r12), %rdi
cltq
movq %rsi, 0x18(%rsp)
leaq 0x8(,%rax,8), %rsi
movq %rdx, 0x8(%rsp)
callq 0x6c80
movq %rax, 0x8(%r12)
leaq (%rax,%r14,8), %rdi
movslq 0x4(%r12), %rdx
subq %r14, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x63b0
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdx
cmpl %edx, %r13d
jne 0x4928b
movq 0x8(%r12), %rax
cmpq $-0x1, (%rax,%r13,8)
jne 0x49275
movq %rsi, (%rax,%r13,8)
cmpl %edx, (%r12)
jg 0x49036
leal 0x1(%rdx), %eax
movl %eax, (%r12)
jmp 0x49036
movslq %edx, %rax
cmpq %rax, %r13
jg 0x49275
movq 0x8(%r12), %rcx
cmpq $-0x1, (%rcx,%r13,8)
jne 0x492a3
movq %rsi, (%rcx,%r13,8)
incq %r13
jmp 0x4928e
movq 0x69d29(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x3e3d6(%rip), %rsi     # 0x8768f
movl %edx, %ebx
leaq 0x3e3c0(%rip), %rdx     # 0x87682
xorl %eax, %eax
callq 0x6a90
movl %ebx, %eax
jmp 0x4918c