// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/hts.c
// Function: hts_idx_push
int hts_idx_push(hts_idx_t *idx, int tid, hts_pos_t beg, hts_pos_t end, uint64_t offset, int is_mapped)
{
    int bin;
    if (tid<0) beg = -1, end = 0;
    if (hts_idx_check_range(idx, tid, beg, end) < 0)
        return -1;
    if (tid >= idx->m) { // enlarge the index
        uint32_t new_m = idx->m * 2 > tid + 1 ? idx->m * 2 : tid + 1;
        bidx_t **new_bidx;
        lidx_t *new_lidx;

        new_bidx = (bidx_t**)realloc(idx->bidx, new_m * sizeof(bidx_t*));
        if (!new_bidx) return -1;
        idx->bidx = new_bidx;

        new_lidx = (lidx_t*) realloc(idx->lidx, new_m * sizeof(lidx_t));
        if (!new_lidx) return -1;
        idx->lidx = new_lidx;

        memset(&idx->bidx[idx->m], 0, (new_m - idx->m) * sizeof(bidx_t*));
        memset(&idx->lidx[idx->m], 0, (new_m - idx->m) * sizeof(lidx_t));
        idx->m = new_m;
    }
    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 )
        {
            hts_log_error("NO_COOR reads not in a single block at the end %d %d", tid, idx->z.last_tid);
            return -1;
        }
        if (tid>=0 && idx->bidx[tid] != 0)
        {
            hts_log_error("Chromosome blocks not continuous");
            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
        hts_log_error("Unsorted positions on sequence #%d: %"PRIhts_pos" followed by %"PRIhts_pos, tid+1, idx->z.last_coor+1, beg+1);
        return -1;
    }
    if (end < beg) {
        // Malformed ranges are errors. (Empty ranges (beg==end) are unusual but acceptable.)
        hts_log_error("Invalid record on sequence #%d: end %"PRId64" < begin %"PRId64, tid+1, end, beg+1);
        return -1;
    }
    if ( tid>=0 )
    {
        if (idx->bidx[tid] == 0) idx->bidx[tid] = kh_init(bin);
        // shoehorn [-1,0) (VCF POS=0) into the leftmost bottom-level bin
        if (beg < 0)  beg = 0;
        if (end <= 0) end = 1;
        // idx->z.last_off points to the start of the current record
        if (insert_to_l(&idx->lidx[tid], beg, end,
                        idx->z.last_off, idx->min_shift) < 0) return -1;
    }
    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
            if (insert_to_b(idx->bidx[idx->z.save_tid], idx->z.save_bin,
                            idx->z.save_off, idx->z.last_off) < 0) return -1;
        }
        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;
            if (insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx),
                            idx->z.off_beg, idx->z.off_end) < 0) return -1;
            if (insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx),
                            idx->z.n_mapped, idx->z.n_unmapped) < 0) return -1;
            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 $0x38, %rsp
movl %r9d, 0xc(%rsp)
movq %r8, %rbx
movq %rcx, %r13
movq %rdx, %r12
movl %esi, %r14d
xorl %eax, %eax
testl %esi, %esi
cmovsq %rax, %r13
movq %rdi, %r15
movq $-0x1, %rax
cmovsq %rax, %r12
movq %r12, %rdx
movq %r13, %rcx
callq 0x16e2c
testl %eax, %eax
js 0x170bc
movl 0x18(%r15), %ebp
cmpl %r14d, %ebp
jg 0x16fd2
movq %rbx, (%rsp)
addl %ebp, %ebp
leal 0x1(%r14), %eax
cmpl %eax, %ebp
cmovlel %eax, %ebp
movq 0x28(%r15), %rdi
leaq (,%rbp,8), %rbx
movq %rbx, %rsi
callq 0x4840
testq %rax, %rax
je 0x170bc
movq %rax, 0x28(%r15)
movq 0x30(%r15), %rdi
leaq (%rbx,%rbx,2), %rsi
callq 0x4840
testq %rax, %rax
je 0x170bc
movq %rax, 0x30(%r15)
movslq 0x18(%r15), %rdi
movl %ebp, %edx
subl %edi, %edx
shlq $0x3, %rdi
addq 0x28(%r15), %rdi
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x4260
movslq 0x18(%r15), %rax
leaq (%rax,%rax,2), %rdi
shlq $0x3, %rdi
addq 0x30(%r15), %rdi
movl %ebp, %ecx
subl %eax, %ecx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rdx
xorl %esi, %esi
callq 0x4260
movl %ebp, 0x18(%r15)
movq (%rsp), %rbx
leal 0x1(%r14), %ecx
cmpl %r14d, 0x14(%r15)
jg 0x16fe0
movl %ecx, 0x14(%r15)
xorl %eax, %eax
cmpl $0x0, 0x60(%r15)
jne 0x170c1
testl %r14d, %r14d
sets %al
movl 0x58(%r15), %r8d
testl %r8d, %r8d
setns %dl
cmpl %r14d, %r8d
jne 0x17033
andb %dl, %al
jne 0x17033
testl %r14d, %r14d
js 0x17094
movq 0x50(%r15), %r8
cmpq %r12, %r8
jle 0x17094
incq %r8
incq %r12
leaq 0x82421(%rip), %rsi     # 0x99446
leaq 0x8247d(%rip), %rdx     # 0x994a9
movl $0x1, %edi
jmp 0x170b2
testl %r14d, %r14d
js 0x17088
cmpq $0x0, 0x20(%r15)
je 0x1705e
leaq 0x82400(%rip), %rsi     # 0x99446
leaq 0x82406(%rip), %rdx     # 0x99453
movl $0x1, %edi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x14378
jmp 0x170bc
movq 0x28(%r15), %rax
movl %r14d, %edx
cmpq $0x0, (%rax,%rdx,8)
je 0x17088
leaq 0x823d3(%rip), %rsi     # 0x99446
leaq 0x8240e(%rip), %rdx     # 0x99488
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x170bc
movl %r14d, 0x58(%r15)
movl $0xffffffff, 0x48(%r15) # imm = 0xFFFFFFFF
cmpq %r12, %r13
jge 0x170d0
incq %r12
leaq 0x823a3(%rip), %rsi     # 0x99446
leaq 0x82437(%rip), %rdx     # 0x994e1
movl $0x1, %edi
movq %r13, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x14378
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, (%rsp)
testl %r14d, %r14d
js 0x171ea
movq 0x28(%r15), %rbx
movl %r14d, %ebp
cmpq $0x0, (%rbx,%rbp,8)
jne 0x170fe
movl $0x1, %edi
movl $0x28, %esi
callq 0x4300
movq %rax, (%rbx,%rbp,8)
xorl %edx, %edx
testq %r12, %r12
cmovgq %r12, %rdx
cmpq $0x2, %r13
movl $0x1, %ebx
cmovgeq %r13, %rbx
movq 0x30(%r15), %rax
leaq (%rbp,%rbp,2), %rcx
leaq (%rax,%rcx,8), %rsi
movb 0x4(%r15), %cl
movq %rdx, 0x18(%rsp)
movq %rdx, %rax
shrq %cl, %rax
leaq -0x1(%rbx), %rbp
shrq %cl, %rbp
movq 0x68(%r15), %rdx
movq 0x8(%rsi), %r13
leaq 0x1(%rbp), %r12
cmpq %rbp, %r13
jg 0x171bd
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
addq %r13, %r13
cmpq %r12, %r13
cmovleq %r12, %r13
movq 0x10(%rsi), %rdi
movq %rsi, 0x10(%rsp)
leaq (,%r13,8), %rsi
callq 0x4840
testq %rax, %rax
je 0x170bc
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r13, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
movq %rax, 0x20(%rsp)
callq 0x4260
movq 0x10(%rsp), %rsi
movq %r13, 0x8(%rsi)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsi)
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rax
cltq
cmpq %rax, %rbp
jl 0x171db
movq 0x10(%rsi), %rcx
cmpq $-0x1, (%rcx,%rax,8)
jne 0x171d3
movq %rdx, (%rcx,%rax,8)
incq %rax
cmpq %rax, %r12
jne 0x171c8
cmpq %rbp, (%rsi)
jg 0x171e3
movq %r12, (%rsi)
movq 0x18(%rsp), %r13
jmp 0x171f4
incq 0x20(%r15)
movq %r13, %rbx
movq %r12, %r13
movl 0x8(%r15), %edx
xorl %r12d, %r12d
testl %edx, %edx
jle 0x1725f
decq %rbx
leal (%rdx,%rdx,2), %ecx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
shll %cl, %edi
movl 0x4(%r15), %eax
notl %edi
movl $0x92492493, %esi       # imm = 0x92492493
imulq %rdi, %rsi
shrq $0x22, %rsi
movl %edx, %edi
incl %edi
leal (%rdx,%rdx,2), %edx
addl $-0x3, %edx
movq %r13, %r8
movl %eax, %ecx
sarq %cl, %r8
movq %rbx, %r9
sarq %cl, %r9
cmpq %r9, %r8
je 0x17259
addl $0x3, %eax
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %edx, %ecx
shll %cl, %r8d
addl %r8d, %esi
decl %edi
addl $-0x3, %edx
cmpl $0x1, %edi
jg 0x17229
jmp 0x1725f
addl %r8d, %esi
movl %esi, %r12d
cmpl %r12d, 0x48(%r15)
movq (%rsp), %rbx
je 0x172ae
movl 0x4c(%r15), %esi
cmpl $-0x1, %esi
je 0x17293
movslq 0x5c(%r15), %rax
movq 0x28(%r15), %rdx
movq 0x68(%r15), %rcx
movq (%rdx,%rax,8), %rdi
movq 0x70(%r15), %rdx
callq 0x16c11
testl %eax, %eax
js 0x170bc
cmpl $-0x1, 0x48(%r15)
je 0x172cf
movq 0x68(%r15), %rax
movq %rax, 0x70(%r15)
movl %r12d, 0x48(%r15)
movl %r12d, 0x4c(%r15)
movl %r14d, 0x5c(%r15)
xorl %eax, %eax
cmpl $0x0, 0xc(%rsp)
sete %al
incq 0x88(%r15,%rax,8)
movq %rbx, 0x68(%r15)
movq %r13, 0x50(%r15)
xorl %eax, %eax
jmp 0x170c1
cmpl $-0x1, 0x4c(%r15)
je 0x1729a
movq 0x68(%r15), %rcx
movq %rcx, 0x80(%r15)
movq 0x28(%r15), %rax
movslq 0x5c(%r15), %rdx
movq (%rax,%rdx,8), %rdi
movl 0xc(%r15), %esi
incl %esi
movq 0x78(%r15), %rdx
callq 0x16c11
testl %eax, %eax
js 0x170bc
movq 0x28(%r15), %rax
movslq 0x5c(%r15), %rcx
movq (%rax,%rcx,8), %rdi
movl 0xc(%r15), %esi
incl %esi
movq 0x88(%r15), %rdx
movq 0x90(%r15), %rcx
callq 0x16c11
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
js 0x170c1
leaq 0x88(%r15), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x80(%r15), %rax
movq %rax, 0x78(%r15)
jmp 0x1729a