// File: /workspace/github_cpp_makefile_star2_O1/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, 0x24(%rsp)
movq %r8, 0x30(%rsp)
movl %esi, %r14d
movq %rdi, %r12
xorl %ebp, %ebp
testl %esi, %esi
cmovnsl %ecx, %ebp
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmovnsl %edx, %r15d
movslq 0x18(%rdi), %rbx
cmpl %esi, %ebx
jg 0x117db
leal (%rbx,%rbx), %eax
testl %ebx, %ebx
movl $0x2, %ecx
cmovnel %eax, %ecx
movl %ecx, 0x18(%r12)
movq 0x28(%r12), %rdi
movslq %ecx, %rsi
shlq $0x3, %rsi
callq 0x48d0
movq %rax, 0x28(%r12)
movq 0x30(%r12), %rdi
movslq 0x18(%r12), %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x30(%r12)
leaq (,%rbx,8), %rdi
addq 0x28(%r12), %rdi
movslq 0x18(%r12), %rdx
subq %rbx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x42d0
movq %rbx, %rdi
shlq $0x4, %rdi
addq 0x30(%r12), %rdi
movslq 0x18(%r12), %rdx
subq %rbx, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x42d0
leal 0x1(%r14), %ecx
cmpl %r14d, 0x14(%r12)
jg 0x117eb
movl %ecx, 0x14(%r12)
xorl %r13d, %r13d
cmpl $0x0, 0x54(%r12)
jne 0x11d21
testl %r14d, %r14d
sets %al
movl 0x4c(%r12), %r8d
testl %r8d, %r8d
setns %dl
cmpl %r14d, %r8d
jne 0x1186b
andb %dl, %al
jne 0x1186b
testl %r14d, %r14d
js 0x118ec
movl 0x48(%r12), %r8d
cmpl %r15d, %r8d
jle 0x118ec
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x52d18(%rip)     # 0x64550
jle 0x11d21
movq 0x52783(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
incl %r8d
incl %r15d
leaq 0x4169e(%rip), %rsi     # 0x52ef3
leaq 0x41660(%rip), %rdx     # 0x52ebc
movl %r15d, %r9d
xorl %eax, %eax
callq 0x4770
jmp 0x11d21
testl %r14d, %r14d
js 0x118de
cmpq $0x0, 0x20(%r12)
je 0x118b2
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x52ccb(%rip)     # 0x64550
jle 0x11d21
movq 0x52736(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0x415e2(%rip), %rsi     # 0x52e7e
leaq 0x41619(%rip), %rdx     # 0x52ebc
movl %r14d, %ecx
xorl %eax, %eax
callq 0x4770
jmp 0x11d21
movq 0x28(%r12), %rax
movl %r14d, %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x118de
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x52c82(%rip)     # 0x64550
jle 0x11d21
callq 0x4db7
jmp 0x11d21
movl %r14d, 0x4c(%r12)
movl $0xffffffff, 0x40(%r12) # imm = 0xFFFFFFFF
movl %r15d, 0xc(%rsp)
movslq %r15d, %rbx
movslq %ebp, %r13
testl %r14d, %r14d
js 0x119ec
movq 0x28(%r12), %r15
movl %r14d, %ebp
cmpq $0x0, (%r15,%rbp,8)
jne 0x11922
movl $0x1, %edi
movl $0x28, %esi
callq 0x4360
movq %rax, (%r15,%rbp,8)
cmpl $0x0, 0x24(%rsp)
je 0x11a20
movq 0x30(%r12), %rax
shlq $0x4, %rbp
movb 0x4(%r12), %cl
movq %rbx, %r15
sarq %cl, %r15
leaq -0x1(%r13), %rdx
sarq %cl, %rdx
leaq (%rax,%rbp), %rsi
movq 0x58(%r12), %rdi
movslq 0x4(%rax,%rbp), %rax
cmpl %edx, %eax
jg 0x119d6
movq %rax, 0x28(%rsp)
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(%rsi)
movq %rdi, 0x10(%rsp)
movq 0x8(%rsi), %rdi
cltq
movq %rsi, %rbp
leaq 0x8(,%rax,8), %rsi
movq %rdx, 0x18(%rsp)
callq 0x48d0
movq %rax, 0x8(%rbp)
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx,8), %rdi
movslq 0x4(%rbp), %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x42d0
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
cmpl %edx, %r15d
jne 0x119f3
movq 0x8(%rsi), %rax
cmpq $-0x1, (%rax,%r15,8)
jne 0x11a18
movq %rdi, (%rax,%r15,8)
jmp 0x11a18
incq 0x20(%r12)
jmp 0x11a20
jg 0x11a18
movl %edx, %eax
subl %r15d, %eax
incl %eax
shlq $0x3, %r15
addq 0x8(%rsi), %r15
xorl %ecx, %ecx
cmpq $-0x1, (%r15,%rcx,8)
jne 0x11a11
movq %rdi, (%r15,%rcx,8)
incq %rcx
cmpl %ecx, %eax
jne 0x11a06
cmpl %edx, (%rsi)
jg 0x11a20
incl %edx
movl %edx, (%rsi)
movl 0x8(%r12), %edx
xorl %r11d, %r11d
testl %edx, %edx
jle 0x11a8c
decq %r13
leal (%rdx,%rdx,2), %ecx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
shll %cl, %edi
movl 0x4(%r12), %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
movl 0xc(%rsp), %r10d
movq %rbx, %r8
movl %eax, %ecx
sarq %cl, %r8
movq %r13, %r9
sarq %cl, %r9
cmpq %r9, %r8
je 0x11a93
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 0x11a5c
jmp 0x11a99
movl 0xc(%rsp), %r10d
jmp 0x11a99
addl %r8d, %esi
movl %esi, %r11d
cmpl %r11d, 0x40(%r12)
je 0x11d00
movl 0x44(%r12), %esi
cmpl $-0x1, %esi
je 0x11b5b
movl %r11d, 0x18(%rsp)
movslq 0x50(%r12), %rax
movq 0x28(%r12), %rcx
movq 0x58(%r12), %rdx
movq %rdx, 0x10(%rsp)
movq (%rcx,%rax,8), %r13
movq 0x60(%r12), %rbp
leaq 0x3c(%rsp), %r15
movq %r13, %rdi
movq %r15, %rdx
callq 0x138fc
movl %eax, %eax
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
addq 0x20(%r13), %rbx
cmpl $0x0, (%r15)
je 0x11b12
movq $0x1, (%rbx)
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%rbx)
movl (%rbx), %eax
cmpl %eax, 0x4(%rbx)
jne 0x11b31
addl %eax, %eax
movl %eax, (%rbx)
movq 0x10(%rbx), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%rbx)
movq 0x10(%rbx), %rax
movslq 0x4(%rbx), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq %rbp, (%rax,%rcx)
movl %edx, 0x4(%rbx)
movq 0x10(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
movl 0xc(%rsp), %r10d
movl 0x18(%rsp), %r11d
cmpl $-0x1, 0x40(%r12)
jne 0x11ce7
cmpl $-0x1, 0x44(%r12)
je 0x11ce7
movl %r11d, 0x18(%rsp)
movq 0x58(%r12), %rbx
movq %rbx, 0x70(%r12)
movq 0x28(%r12), %rax
movslq 0x50(%r12), %rcx
movq (%rax,%rcx,8), %r15
movl 0xc(%r12), %esi
incl %esi
movq 0x68(%r12), %rax
movq %rax, 0x10(%rsp)
leaq 0x40(%rsp), %r13
movq %r15, %rdi
movq %r13, %rdx
callq 0x138fc
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r15), %rbp
cmpl $0x0, (%r13)
je 0x11be1
movq $0x1, (%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%rbp)
movl (%rbp), %eax
cmpl %eax, 0x4(%rbp)
jne 0x11c02
addl %eax, %eax
movl %eax, (%rbp)
movq 0x10(%rbp), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%rbp)
movq 0x10(%rbp), %rax
movslq 0x4(%rbp), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq 0x10(%rsp), %rsi
movq %rsi, (%rax,%rcx)
movl %edx, 0x4(%rbp)
movq %rbx, 0x8(%rax,%rcx)
movq 0x28(%r12), %rax
movslq 0x50(%r12), %rcx
movq (%rax,%rcx,8), %r15
movl 0xc(%r12), %esi
incl %esi
movq 0x78(%r12), %rbp
movq 0x80(%r12), %rax
movq %rax, 0x10(%rsp)
leaq 0x44(%rsp), %r13
movq %r15, %rdi
movq %r13, %rdx
callq 0x138fc
movl %eax, %eax
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
addq 0x20(%r15), %rbx
cmpl $0x0, (%r13)
je 0x11c88
movq $0x1, (%rbx)
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%rbx)
leaq 0x78(%r12), %r15
movl (%rbx), %eax
cmpl %eax, 0x4(%rbx)
jne 0x11cac
addl %eax, %eax
movl %eax, (%rbx)
movq 0x10(%rbx), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%rbx)
movq 0x10(%rbx), %rax
movslq 0x4(%rbx), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq %rbp, (%rax,%rcx)
movl %edx, 0x4(%rbx)
movq 0x10(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq 0x70(%r12), %rax
movq %rax, 0x68(%r12)
movl 0xc(%rsp), %r10d
movl 0x18(%rsp), %r11d
movq 0x58(%r12), %rax
movq %rax, 0x60(%r12)
movl %r11d, 0x40(%r12)
movl %r11d, 0x44(%r12)
movl %r14d, 0x50(%r12)
xorl %eax, %eax
cmpl $0x0, 0x24(%rsp)
sete %al
incq 0x78(%r12,%rax,8)
movq 0x30(%rsp), %rax
movq %rax, 0x58(%r12)
movl %r10d, 0x48(%r12)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq