// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/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 on sequence #%d: %d followed by %d\n", __func__, tid+1, idx->z.last_coor+1, beg+1);
        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, %r13d
movl %edx, %r12d
movl %esi, %ebx
movq %rdi, %r15
xorl %ebp, %ebp
testl %esi, %esi
cmovnsl %ecx, %ebp
pushq $-0x1
popq %rsi
movl %edx, %eax
cmovsl %esi, %eax
movl %eax, 0x14(%rsp)
movslq 0x18(%rdi), %r14
cmpl %ebx, %r14d
jg 0xe923
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 0x48c0
movq %rax, 0x28(%r15)
movq 0x30(%r15), %rdi
movslq 0x18(%r15), %rsi
shlq $0x4, %rsi
callq 0x48c0
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 0x42e0
movq %r14, %rdi
shlq $0x4, %rdi
addq 0x30(%r15), %rdi
movslq 0x18(%r15), %rdx
subq %r14, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x42e0
pushq $-0x1
popq %rsi
leal 0x1(%rbx), %ecx
cmpl %ebx, 0x14(%r15)
jg 0xe930
movl %ecx, 0x14(%r15)
xorl %eax, %eax
cmpl $0x0, 0x54(%r15)
jne 0xeb51
testl %ebx, %ebx
sets %al
movl 0x4c(%r15), %r8d
testl %r8d, %r8d
setns %dl
movl %ebx, %edi
cmpl %ebx, %r8d
jne 0xe9a8
andb %dl, %al
jne 0xe9a8
testl %ebx, %ebx
js 0xe9f7
movl 0x48(%r15), %r8d
cmpl %r12d, %r8d
jle 0xeb2a
cmpl $0x0, 0x48bd5(%rip)     # 0x57548
jle 0xeb4f
movq 0x48650(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
incl %r8d
incl %r12d
movl %esi, %ebx
leaq 0x355d3(%rip), %rsi     # 0x43f65
leaq 0x35595(%rip), %rdx     # 0x43f2e
movl %r12d, %r9d
xorl %eax, %eax
callq 0x4770
jmp 0xec88
testl %ebx, %ebx
js 0xe9ee
cmpq $0x0, 0x20(%r15)
je 0xeb37
cmpl $0x0, 0x48b8a(%rip)     # 0x57548
jle 0xeb4f
movq 0x48605(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
movl %esi, %ebp
leaq 0x35519(%rip), %rsi     # 0x43ef0
leaq 0x35550(%rip), %rdx     # 0x43f2e
movl %ebx, %ecx
xorl %eax, %eax
callq 0x4770
movl %ebp, %eax
jmp 0xeb51
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 0xea63
movq %rdi, %r11
movl %esi, %ecx
sarq %cl, %r11
movq %r8, %r14
sarq %cl, %r14
cmpq %r14, %r11
je 0xea5e
movl %r10d, %r11d
movl %edx, %ecx
shll %cl, %r11d
decl %r9d
addl $0x3, %esi
addl %r11d, %eax
addl $-0x3, %edx
jmp 0xea30
addl %r11d, %eax
movl %eax, %ebp
movl 0x40(%r15), %eax
cmpl %ebp, %eax
je 0xeb0a
movl 0x44(%r15), %esi
cmpl $-0x1, %esi
je 0xea95
movslq 0x50(%r15), %rax
movq 0x28(%r15), %rdx
movq 0x58(%r15), %rcx
movq (%rdx,%rax,8), %rdi
movq 0x60(%r15), %rdx
callq 0xe656
movl 0x40(%r15), %eax
cmpl $-0x1, %eax
jne 0xeaf6
cmpl $-0x1, 0x44(%r15)
je 0xeaf6
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 0xe656
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 0xe656
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 0xeb51
movq 0x28(%r15), %r14
cmpq $0x0, (%r14,%rdi,8)
jne 0xeb7c
jmp 0xeb69
movq 0x28(%r15), %r14
cmpq $0x0, (%r14,%rdi,8)
je 0xeb60
cmpl $0x0, 0x489ff(%rip)     # 0x57548
jg 0xec67
movl %esi, %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 0xec8f
movq 0x8(%rsp), %rdi
movq %rax, (%r14,%rdi,8)
cmpl $0x0, 0x4(%rsp)
je 0xe9fb
movq 0x30(%r15), %rax
shlq $0x4, %rdi
movslq %r12d, %r12
movslq %r13d, %rdx
movb 0x4(%r15), %cl
sarq %cl, %r12
decq %rdx
sarq %cl, %rdx
leaq (%rax,%rdi), %r13
movq 0x58(%r15), %rsi
movslq 0x4(%rax,%rdi), %r14
cmpl %edx, %r14d
jg 0xec21
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(%r13)
movq 0x8(%r13), %rdi
cltq
movq %rsi, 0x18(%rsp)
leaq 0x8(,%rax,8), %rsi
movq %rdx, 0x8(%rsp)
callq 0x48c0
movq %rax, 0x8(%r13)
leaq (%rax,%r14,8), %rdi
movslq 0x4(%r13), %rdx
subq %r14, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x42e0
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdx
cmpl %edx, %r12d
jne 0xec4b
movq 0x8(%r13), %rax
cmpq $-0x1, (%rax,%r12,8)
jne 0xec35
movq %rsi, (%rax,%r12,8)
cmpl %edx, (%r13)
jg 0xe9fb
leal 0x1(%rdx), %eax
movl %eax, (%r13)
jmp 0xe9fb
movslq %edx, %rax
cmpq %rax, %r12
jg 0xec35
movq 0x8(%r13), %rcx
cmpq $-0x1, (%rcx,%r12,8)
jne 0xec62
movq %rsi, (%rcx,%r12,8)
incq %r12
jmp 0xec4e
movq 0x48362(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
movl %esi, %ebx
leaq 0x352c1(%rip), %rsi     # 0x43f3b
leaq 0x352ad(%rip), %rdx     # 0x43f2e
xorl %eax, %eax
callq 0x4770
movl %ebx, %eax
jmp 0xeb51