// File: /workspace/github_c_makefile_star2_O3/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, 0x1c(%rsp)
movq %r8, %rbx
movq %rdx, %r13
movl %esi, %r14d
xorl %ebp, %ebp
testl %esi, %esi
movq %rcx, 0x10(%rsp)
cmovnsq %rcx, %rbp
movq %rdi, %r15
movq $-0x1, %r12
cmovnsq %rdx, %r12
movq %r12, %rdx
movq %rbp, %rcx
callq 0x168d9
testl %eax, %eax
js 0x16b88
movq %r13, (%rsp)
movl 0x18(%r15), %r13d
cmpl %r14d, %r13d
movq %rbx, 0x30(%rsp)
jle 0x169ff
leal 0x1(%r14), %ecx
jmp 0x16a94
addl %r13d, %r13d
leal 0x1(%r14), %eax
cmpl %eax, %r13d
movl %eax, 0x8(%rsp)
cmovlel %eax, %r13d
movq 0x28(%r15), %rdi
leaq (,%r13,8), %rbx
movq %rbx, %rsi
callq 0x4840
testq %rax, %rax
je 0x16b88
movq %rax, 0x28(%r15)
movq 0x30(%r15), %rdi
leaq (%rbx,%rbx,2), %rsi
callq 0x4840
testq %rax, %rax
je 0x16b88
movq %rax, 0x30(%r15)
movslq 0x18(%r15), %rdi
movl %r13d, %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 %r13d, %ecx
subl %eax, %ecx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rdx
xorl %esi, %esi
callq 0x4260
movl %r13d, 0x18(%r15)
movl 0x8(%rsp), %ecx
cmpl %r14d, 0x14(%r15)
movq (%rsp), %r13
jg 0x16aa2
movl %ecx, 0x14(%r15)
xorl %eax, %eax
cmpl $0x0, 0x60(%r15)
jne 0x16b8d
testl %r14d, %r14d
sets %al
movl 0x58(%r15), %r8d
testl %r8d, %r8d
setns %dl
cmpl %r14d, %r8d
jne 0x16aff
andb %dl, %al
jne 0x16aff
testl %r14d, %r14d
js 0x16b60
movq 0x50(%r15), %r8
cmpq %r13, %r8
jle 0x16b60
incq %r8
incq %r13
leaq 0x7f9fb(%rip), %rsi     # 0x964e6
leaq 0x7fa57(%rip), %rdx     # 0x96549
movl $0x1, %edi
movq %r13, %r9
jmp 0x16b81
testl %r14d, %r14d
js 0x16b54
cmpq $0x0, 0x20(%r15)
je 0x16b2a
leaq 0x7f9d4(%rip), %rsi     # 0x964e6
leaq 0x7f9da(%rip), %rdx     # 0x964f3
movl $0x1, %edi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x13de5
jmp 0x16b88
movq 0x28(%r15), %rax
movl %r14d, %edx
cmpq $0x0, (%rax,%rdx,8)
je 0x16b54
leaq 0x7f9a7(%rip), %rsi     # 0x964e6
leaq 0x7f9e2(%rip), %rdx     # 0x96528
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x16b88
movl %r14d, 0x58(%r15)
movl $0xffffffff, 0x48(%r15) # imm = 0xFFFFFFFF
cmpq %r12, %rbp
jge 0x16b9c
incq %r12
leaq 0x7f977(%rip), %rsi     # 0x964e6
leaq 0x7fa0b(%rip), %rdx     # 0x96581
movl $0x1, %edi
movq %rbp, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x13de5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r14d, %r14d
js 0x16cb8
movq 0x28(%r15), %r12
movl %r14d, %ebx
cmpq $0x0, (%r12,%rbx,8)
jne 0x16bc6
movl $0x1, %edi
movl $0x28, %esi
callq 0x4300
movq %rax, (%r12,%rbx,8)
xorl %r12d, %r12d
testq %r13, %r13
cmovgq %r13, %r12
movq 0x10(%rsp), %rax
cmpq $0x2, %rax
movl $0x1, %r13d
cmovgeq %rax, %r13
movq 0x30(%r15), %rax
movb 0x4(%r15), %cl
movq %r12, %r8
shrq %cl, %r8
leaq (%rbx,%rbx,2), %rdx
leaq (%rax,%rdx,8), %rdx
decq %r13
movq %r13, %rsi
shrq %cl, %rsi
movq 0x68(%r15), %rdi
movq 0x8(%rdx), %rbx
leaq 0x1(%rsi), %rbp
cmpq %rsi, %rbx
jg 0x16c8f
movq %r8, 0x28(%rsp)
movq %rdi, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
addq %rbx, %rbx
cmpq %rbp, %rbx
cmovleq %rbp, %rbx
movq 0x10(%rdx), %rdi
leaq (,%rbx,8), %rsi
movq %rdx, (%rsp)
callq 0x4840
testq %rax, %rax
je 0x16b88
movq (%rsp), %rcx
movq 0x8(%rcx), %rcx
leaq (%rax,%rcx,8), %rdi
movq %rbx, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
movq %rax, 0x20(%rsp)
callq 0x4260
movq (%rsp), %rdx
movq %rbx, 0x8(%rdx)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rdx)
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %r8
movslq %r8d, %rax
cmpq %rax, %rsi
jl 0x16cae
movq 0x10(%rdx), %rcx
cmpq $-0x1, (%rcx,%rax,8)
jne 0x16ca6
movq %rdi, (%rcx,%rax,8)
incq %rax
cmpq %rax, %rbp
jne 0x16c9b
cmpq %rsi, (%rdx)
jg 0x16cc3
movq %rbp, (%rdx)
jmp 0x16cc3
incq 0x20(%r15)
movq $-0x1, %r13
movl 0x8(%r15), %edx
xorl %ebx, %ebx
testl %edx, %edx
jle 0x16d29
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 %r12, %r8
movl %eax, %ecx
sarq %cl, %r8
movq %r13, %r9
sarq %cl, %r9
cmpq %r9, %r8
je 0x16d24
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 0x16cf4
jmp 0x16d29
addl %r8d, %esi
movl %esi, %ebx
movl 0x48(%r15), %eax
cmpl %ebx, %eax
je 0x16d78
movl 0x4c(%r15), %esi
cmpl $-0x1, %esi
je 0x16d5f
movslq 0x5c(%r15), %rax
movq 0x28(%r15), %rdx
movq 0x68(%r15), %rcx
movq (%rdx,%rax,8), %rdi
movq 0x70(%r15), %rdx
callq 0x166b3
testl %eax, %eax
js 0x16b88
movl 0x48(%r15), %eax
cmpl $-0x1, %eax
je 0x16d9e
movq 0x68(%r15), %rax
movq %rax, 0x70(%r15)
movl %ebx, 0x48(%r15)
movl %ebx, 0x4c(%r15)
movl %r14d, 0x5c(%r15)
xorl %eax, %eax
cmpl $0x0, 0x1c(%rsp)
sete %al
incq 0x88(%r15,%rax,8)
movq 0x30(%rsp), %rax
movq %rax, 0x68(%r15)
movq %r12, 0x50(%r15)
xorl %eax, %eax
jmp 0x16b8d
cmpl $-0x1, 0x4c(%r15)
je 0x16d64
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 0x166b3
testl %eax, %eax
js 0x16b88
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 0x166b3
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
js 0x16b8d
leaq 0x88(%r15), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x80(%r15), %rax
movq %rax, 0x78(%r15)
jmp 0x16d64