// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movl %r9d, 0x1c(%rsp)
movq %r8, %rbp
movq %rdx, %r13
movl %esi, %r14d
movq %rdi, %r15
xorl %ebx, %ebx
testl %esi, %esi
movq %rcx, 0x10(%rsp)
cmovnsq %rcx, %rbx
pushq $-0x1
popq %rax
movq %rdx, %r12
movq %rax, 0x20(%rsp)
cmovsq %rax, %r12
movq %r12, %rdx
movq %rbx, %rcx
callq 0x13858
pushq $-0x1
popq %rdx
testl %eax, %eax
js 0x13973
movq %rbp, 0x40(%rsp)
movl 0x18(%r15), %ebp
cmpl %r14d, %ebp
jle 0x1397a
leal 0x1(%r14), %ecx
jmp 0x13a02
movl %edx, %ebp
jmp 0x13cdc
addl %ebp, %ebp
leal 0x1(%r14), %eax
cmpl %eax, %ebp
movl %eax, 0x8(%rsp)
cmovlel %eax, %ebp
movq 0x28(%r15), %rdi
leaq (,%rbp,8), %rsi
callq 0x4840
testq %rax, %rax
je 0x13a6e
movq %rax, 0x28(%r15)
movq 0x30(%r15), %rdi
imulq $0x18, %rbp, %rsi
callq 0x4840
testq %rax, %rax
je 0x13a6e
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
imulq $0x18, %rax, %rdi
addq 0x30(%r15), %rdi
movl %ebp, %ecx
subl %eax, %ecx
imulq $0x18, %rcx, %rdx
xorl %esi, %esi
callq 0x4260
movl %ebp, 0x18(%r15)
pushq $-0x1
popq %rdx
movl 0x8(%rsp), %ecx
cmpl %r14d, 0x14(%r15)
jg 0x13a0c
movl %ecx, 0x14(%r15)
xorl %ebp, %ebp
cmpl $0x0, 0x60(%r15)
jne 0x13cdc
testl %r14d, %r14d
sets %al
movl 0x58(%r15), %r8d
testl %r8d, %r8d
setns %sil
movl %r14d, %ebp
cmpl %r14d, %r8d
jne 0x13a76
andb %sil, %al
jne 0x13a76
testl %r14d, %r14d
js 0x13ad7
movq 0x50(%r15), %r8
cmpq %r13, %r8
jle 0x13ad7
incq %r8
incq %r13
leaq 0x64a7d(%rip), %rsi     # 0x784d7
movl %edx, %ebp
leaq 0x64ad7(%rip), %rdx     # 0x7853a
pushq $0x1
popq %rdi
movq %r13, %r9
jmp 0x13af8
pushq $-0x1
popq %rbp
jmp 0x13cdc
testl %r14d, %r14d
js 0x13ace
cmpq $0x0, 0x20(%r15)
je 0x13aa4
leaq 0x64a4e(%rip), %rsi     # 0x784d7
movl %edx, %ebp
leaq 0x64a52(%rip), %rdx     # 0x784e4
pushq $0x1
popq %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x110c6
jmp 0x13cdc
movq 0x28(%r15), %rax
cmpq $0x0, (%rax,%rbp,8)
je 0x13ace
leaq 0x64a21(%rip), %rsi     # 0x784d7
movl %edx, %ebp
leaq 0x64a5a(%rip), %rdx     # 0x78519
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x13cdc
movl %r14d, 0x58(%r15)
orl $-0x1, 0x48(%r15)
cmpq %r12, %rbx
jge 0x13b04
incq %r12
leaq 0x649f1(%rip), %rsi     # 0x784d7
movl %edx, %ebp
leaq 0x64a83(%rip), %rdx     # 0x78572
pushq $0x1
popq %rdi
movq %rbx, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x110c6
jmp 0x13cdc
testl %r14d, %r14d
js 0x13c13
movq 0x28(%r15), %rbx
cmpq $0x0, (%rbx,%rbp,8)
jne 0x13b21
callq 0x13d64
movq %rax, (%rbx,%rbp,8)
xorl %r12d, %r12d
testq %r13, %r13
cmovgq %r13, %r12
movq 0x10(%rsp), %rax
cmpq $0x2, %rax
pushq $0x1
popq %rbx
cmovgeq %rax, %rbx
movq 0x30(%r15), %rax
movb 0x4(%r15), %cl
movq %r12, %rdi
shrq %cl, %rdi
imulq $0x18, %rbp, %rdx
leaq (%rax,%rdx), %r13
decq %rbx
movq %rbx, 0x20(%rsp)
shrq %cl, %rbx
movq 0x68(%r15), %rsi
movq 0x8(%rax,%rdx), %rax
leaq 0x1(%rbx), %rdx
cmpq %rbx, %rax
jg 0x13beb
movq %rdi, 0x38(%rsp)
movq %rsi, 0x8(%rsp)
addq %rax, %rax
cmpq %rdx, %rax
movq %rdx, 0x10(%rsp)
cmovleq %rdx, %rax
movq 0x10(%r13), %rdi
movq %rax, 0x30(%rsp)
leaq (,%rax,8), %rsi
callq 0x4840
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x13cdc
movq 0x8(%r13), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x30(%rsp), %rbp
movq %rbp, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
movq %rax, 0x28(%rsp)
callq 0x4260
movq %rbp, 0x8(%r13)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%r13)
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rsi
movq 0x38(%rsp), %rdi
movslq %edi, %rax
cmpq %rax, %rbx
jl 0x13c07
movq 0x10(%r13), %rcx
cmpq $-0x1, (%rcx,%rax,8)
jne 0x13c02
movq %rsi, (%rcx,%rax,8)
incq %rax
jmp 0x13bee
cmpq %rbx, (%r13)
jg 0x13c17
movq %rdx, (%r13)
jmp 0x13c17
incq 0x20(%r15)
movl 0x4(%r15), %esi
movl 0x8(%r15), %edi
leal (%rdi,%rdi,2), %ecx
pushq $-0x1
popq %rbp
movl %ebp, %eax
shll %cl, %eax
notl %eax
xorl %ebx, %ebx
pushq $0x7
popq %rcx
xorl %edx, %edx
divl %ecx
leal (%rdi,%rdi,2), %edx
addl $-0x3, %edx
movq 0x20(%rsp), %r10
testl %edi, %edi
jle 0x13c70
movq %r12, %r8
movl %esi, %ecx
sarq %cl, %r8
movq %r10, %r9
sarq %cl, %r9
cmpq %r9, %r8
je 0x13c6b
movl %ebp, %r8d
movl %edx, %ecx
shll %cl, %r8d
decl %edi
addl $0x3, %esi
addl %r8d, %eax
addl $-0x3, %edx
jmp 0x13c3f
addl %r8d, %eax
movl %eax, %ebx
movl 0x48(%r15), %eax
cmpl %ebx, %eax
je 0x13cbb
movl 0x4c(%r15), %esi
cmpl $-0x1, %esi
je 0x13ca2
movslq 0x5c(%r15), %rax
movq 0x28(%r15), %rdx
movq 0x68(%r15), %rcx
movq (%rdx,%rax,8), %rdi
movq 0x70(%r15), %rdx
callq 0x1364a
testl %eax, %eax
js 0x13cdc
movl 0x48(%r15), %eax
cmpl $-0x1, %eax
je 0x13ced
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 0x40(%rsp), %rax
movq %rax, 0x68(%r15)
movq %r12, 0x50(%r15)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x1, 0x4c(%r15)
je 0x13ca7
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 0x1364a
testl %eax, %eax
js 0x13cdc
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 0x1364a
testl %eax, %eax
js 0x13cdc
leaq 0x88(%r15), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x80(%r15), %rax
movq %rax, 0x78(%r15)
jmp 0x13ca7