// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movl %r9d, 0x8(%rsp)
movq %r8, 0x30(%rsp)
movl %ecx, %r13d
movl %edx, %r12d
movl %esi, %ebx
movq %rdi, %r15
xorl %ebp, %ebp
testl %esi, %esi
cmovnsl %ecx, %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnsl %edx, %eax
movl %eax, 0xc(%rsp)
movslq 0x18(%rdi), %r14
cmpl %esi, %r14d
jg 0x1186f
leal (%r14,%r14), %eax
testl %r14d, %r14d
movl $0x2, %ecx
cmovnel %eax, %ecx
movl %ecx, 0x18(%r15)
movq 0x28(%r15), %rdi
movslq %ecx, %rsi
shlq $0x3, %rsi
callq 0x48d0
movq %rax, 0x28(%r15)
movq 0x30(%r15), %rdi
movslq 0x18(%r15), %rsi
shlq $0x4, %rsi
callq 0x48d0
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 0x42d0
movq %r14, %rdi
shlq $0x4, %rdi
addq 0x30(%r15), %rdi
movslq 0x18(%r15), %rdx
subq %r14, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x42d0
leal 0x1(%rbx), %ecx
cmpl %ebx, 0x14(%r15)
jg 0x1187c
movl %ecx, 0x14(%r15)
xorl %r14d, %r14d
cmpl $0x0, 0x54(%r15)
jne 0x11dcf
testl %ebx, %ebx
sets %al
movl 0x4c(%r15), %r8d
testl %r8d, %r8d
setns %dl
cmpl %ebx, %r8d
jne 0x118f7
andb %dl, %al
jne 0x118f7
testl %ebx, %ebx
js 0x1194b
movl 0x48(%r15), %r8d
cmpl %r12d, %r8d
jle 0x11a44
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x50c8c(%rip)     # 0x62550
jle 0x11dcf
movq 0x506f7(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
incl %r8d
incl %r12d
leaq 0x3f646(%rip), %rsi     # 0x50f27
leaq 0x3f608(%rip), %rdx     # 0x50ef0
movl %r12d, %r9d
xorl %eax, %eax
callq 0x4770
jmp 0x11dcf
testl %ebx, %ebx
js 0x1193f
cmpq $0x0, 0x20(%r15)
je 0x11a58
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x50c3d(%rip)     # 0x62550
jle 0x11dcf
movq 0x506a8(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0x3f588(%rip), %rsi     # 0x50eb2
leaq 0x3f5bf(%rip), %rdx     # 0x50ef0
movl %ebx, %ecx
xorl %eax, %eax
callq 0x4770
jmp 0x11dcf
movl %ebx, 0x4c(%r15)
movl $0xffffffff, 0x40(%r15) # imm = 0xFFFFFFFF
incq 0x20(%r15)
movl 0x8(%r15), %edx
xorl %r13d, %r13d
testl %edx, %edx
jle 0x119ca
movslq 0xc(%rsp), %rsi
movslq %ebp, %rdi
decq %rdi
leal (%rdx,%rdx,2), %ecx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
shll %cl, %r9d
movl 0x4(%r15), %eax
notl %r9d
movl $0x92492493, %r8d       # imm = 0x92492493
imulq %r9, %r8
shrq $0x22, %r8
movl %edx, %r9d
incl %r9d
leal (%rdx,%rdx,2), %edx
addl $-0x3, %edx
movq %rsi, %r10
movl %eax, %ecx
sarq %cl, %r10
movq %rdi, %r11
sarq %cl, %r11
cmpq %r11, %r10
je 0x119c4
addl $0x3, %eax
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl %edx, %ecx
shll %cl, %r10d
addl %r10d, %r8d
decl %r9d
addl $-0x3, %edx
cmpl $0x1, %r9d
jg 0x11992
jmp 0x119ca
addl %r10d, %r8d
movl %r8d, %r13d
movl 0x40(%r15), %eax
cmpl %r13d, %eax
je 0x11dac
movl 0x44(%r15), %esi
cmpl $-0x1, %esi
je 0x11bfc
movq 0x28(%r15), %rax
movslq 0x50(%r15), %rcx
movq (%rax,%rcx,8), %r14
movups 0x58(%r15), %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x3c(%rsp), %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x139ac
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r14), %rbp
cmpl $0x0, (%r12)
je 0x11a83
movl $0x1, (%rbp)
leaq 0x4(%rbp), %r14
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
jmp 0x11bdd
movq 0x28(%r15), %rax
movl %ebx, %r14d
cmpq $0x0, (%rax,%r14,8)
jne 0x11add
jmp 0x11ac0
movq 0x28(%r15), %rax
movl %ebx, %r14d
cmpq $0x0, (%rax,%r14,8)
je 0x11ab4
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x50add(%rip)     # 0x62550
jle 0x11dcf
callq 0x4dc3
jmp 0x11dcf
leaq 0x4(%rbp), %r14
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
jne 0x11bd9
addl %ecx, %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x11bdd
movl %ebx, 0x4c(%r15)
movl $0xffffffff, 0x40(%r15) # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x4360
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
cmpl $0x0, 0x8(%rsp)
je 0x1194f
movq 0x30(%r15), %rax
shlq $0x4, %r14
movslq %r12d, %r12
movslq %r13d, %r13
movb 0x4(%r15), %cl
sarq %cl, %r12
decq %r13
sarq %cl, %r13
leaq (%rax,%r14), %rdx
movq 0x58(%r15), %rsi
movslq 0x4(%rax,%r14), %rax
cmpl %r13d, %eax
jg 0x11b89
movq %rax, 0x20(%rsp)
movl %r13d, %eax
sarl %eax
orl %r13d, %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(%rdx)
movq 0x8(%rdx), %rdi
cltq
movq %rsi, 0x10(%rsp)
leaq 0x8(,%rax,8), %rsi
movq %rdx, %r14
callq 0x48d0
movq %rax, 0x8(%r14)
movq 0x20(%rsp), %rcx
leaq (%rax,%rcx,8), %rdi
movslq 0x4(%r14), %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x42d0
movq 0x10(%rsp), %rsi
movq %r14, %rdx
cmpl %r13d, %r12d
jne 0x11b9f
movq 0x8(%rdx), %rax
cmpq $-0x1, (%rax,%r12,8)
jne 0x11bc5
movq %rsi, (%rax,%r12,8)
jmp 0x11bc5
jg 0x11bc5
movl %r13d, %eax
subl %r12d, %eax
incl %eax
shlq $0x3, %r12
addq 0x8(%rdx), %r12
xorl %ecx, %ecx
cmpq $-0x1, (%r12,%rcx,8)
jne 0x11bbe
movq %rsi, (%r12,%rcx,8)
incq %rcx
cmpl %ecx, %eax
jne 0x11bb3
cmpl %r13d, (%rdx)
jg 0x1194f
incl %r13d
movl %r13d, (%rdx)
jmp 0x1194f
movq 0x10(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
incl %ecx
movl %ecx, (%r14)
pshufd $0x4e, 0x10(%rsp), %xmm0 # xmm0 = mem[2,3,0,1]
movdqu %xmm0, (%rax,%rdx)
movl 0x40(%r15), %eax
cmpl $-0x1, %eax
jne 0x11d98
cmpl $-0x1, 0x44(%r15)
je 0x11d98
movq 0x58(%r15), %rax
movq %rax, 0x10(%rsp)
movq %rax, 0x70(%r15)
movq 0x28(%r15), %rax
movslq 0x50(%r15), %rcx
movq (%rax,%rcx,8), %r14
movl 0xc(%r15), %esi
incl %esi
movq 0x68(%r15), %rax
movq %rax, 0x20(%rsp)
leaq 0x40(%rsp), %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x139ac
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r14), %rbp
cmpl $0x0, (%r12)
je 0x11c7f
movl $0x1, (%rbp)
leaq 0x4(%rbp), %r14
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
jmp 0x11cad
leaq 0x4(%rbp), %r14
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
jne 0x11ca9
addl %ecx, %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x11cad
movq 0x10(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
movq 0x20(%rsp), %rsi
movq %rsi, (%rax,%rdx)
incl %ecx
movl %ecx, (%r14)
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax,%rdx)
movq 0x28(%r15), %rax
movslq 0x50(%r15), %rcx
movq (%rax,%rcx,8), %r14
movl 0xc(%r15), %esi
incl %esi
leaq 0x78(%r15), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%r15), %xmm0
movaps %xmm0, 0x20(%rsp)
leaq 0x44(%rsp), %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x139ac
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r14), %rbp
cmpl $0x0, (%r12)
je 0x11d3b
movl $0x1, (%rbp)
leaq 0x4(%rbp), %r14
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
jmp 0x11d69
leaq 0x4(%rbp), %r14
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
jne 0x11d65
addl %ecx, %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x11d69
movq 0x10(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
incl %ecx
movl %ecx, (%r14)
movdqa 0x20(%rsp), %xmm0
movdqu %xmm0, (%rax,%rdx)
pxor %xmm0, %xmm0
movq 0x10(%rsp), %rax
movdqu %xmm0, (%rax)
movq 0x70(%r15), %rax
movq %rax, 0x68(%r15)
movq 0x58(%r15), %rax
movq %rax, 0x60(%r15)
movl %r13d, 0x40(%r15)
movl %r13d, 0x44(%r15)
movl %ebx, 0x50(%r15)
xorl %eax, %eax
cmpl $0x0, 0x8(%rsp)
sete %al
incq 0x78(%r15,%rax,8)
movq 0x30(%rsp), %rax
movq %rax, 0x58(%r15)
movl 0xc(%rsp), %eax
movl %eax, 0x48(%r15)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq