// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/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\n", __func__);
        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 $0x38, %rsp
movq %r8, %r11
movl %esi, %ebx
movq %rdi, %r15
xorl %r13d, %r13d
testl %esi, %esi
cmovnsl %ecx, %r13d
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
cmovnsl %edx, %r10d
movslq 0x18(%rdi), %r12
cmpl %esi, %r12d
jg 0x4ff58
leal (%r12,%r12), %eax
testl %r12d, %r12d
movl $0x2, %ecx
cmovnel %eax, %ecx
movl %ecx, 0x18(%r15)
movq 0x28(%r15), %rdi
movslq %ecx, %rsi
shlq $0x3, %rsi
movl %r10d, (%rsp)
movl %r9d, %r14d
movq %rbx, %rbp
movq %r11, %rbx
callq 0x6c80
movq %rax, 0x28(%r15)
movq 0x30(%r15), %rdi
movslq 0x18(%r15), %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x30(%r15)
leaq (,%r12,8), %rdi
addq 0x28(%r15), %rdi
movslq 0x18(%r15), %rdx
subq %r12, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x63b0
movq %r12, %rdi
shlq $0x4, %rdi
addq 0x30(%r15), %rdi
movslq 0x18(%r15), %rdx
subq %r12, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x63b0
movq %rbx, %r11
movq %rbp, %rbx
movl %r14d, %r9d
movl (%rsp), %r10d
cmpl %ebx, 0x14(%r15)
jg 0x4ff65
leal 0x1(%rbx), %eax
movl %eax, 0x14(%r15)
xorl %r12d, %r12d
cmpl $0x0, 0x54(%r15)
jne 0x5048a
testl %ebx, %ebx
sets %al
movl 0x4c(%r15), %r8d
testl %r8d, %r8d
setns %cl
cmpl %ebx, %r8d
jne 0x4ffba
andb %cl, %al
jne 0x4ffba
testl %ebx, %ebx
js 0x50034
cmpl %r10d, 0x48(%r15)
jle 0x50034
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x70e1e(%rip)     # 0xc0dc8
jle 0x5048a
callq 0x7646
jmp 0x5048a
testl %ebx, %ebx
js 0x50028
cmpq $0x0, 0x20(%r15)
je 0x4fffe
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x70df6(%rip)     # 0xc0dc8
jle 0x5048a
movq 0x6eff9(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x48639(%rip), %rsi     # 0x98622
leaq 0x48670(%rip), %rdx     # 0x98660
movl %ebx, %ecx
xorl %eax, %eax
callq 0x6a90
jmp 0x5048a
movq 0x28(%r15), %rax
movl %ebx, %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x50028
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x70db0(%rip)     # 0xc0dc8
jle 0x5048a
callq 0x7665
jmp 0x5048a
movl %ebx, 0x4c(%r15)
movl $0xffffffff, 0x40(%r15) # imm = 0xFFFFFFFF
movl %r9d, 0x4(%rsp)
movq %r11, 0x20(%rsp)
movslq %r10d, %rbp
movslq %r13d, %r13
testl %ebx, %ebx
js 0x50148
movq 0x28(%r15), %r12
movl %ebx, %r14d
cmpq $0x0, (%r12,%r14,8)
jne 0x50075
movl $0x1, %edi
movl $0x28, %esi
movl %r10d, (%rsp)
callq 0x6470
movl (%rsp), %r10d
movq %rax, (%r12,%r14,8)
cmpl $0x0, 0x4(%rsp)
je 0x5017b
movq 0x30(%r15), %rax
shlq $0x4, %r14
movb 0x4(%r15), %cl
movq %rbp, %r12
sarq %cl, %r12
leaq -0x1(%r13), %rdx
sarq %cl, %rdx
leaq (%rax,%r14), %rsi
movq 0x58(%r15), %rdi
movslq 0x4(%rax,%r14), %rax
cmpl %edx, %eax
jg 0x50132
movq %rax, 0x10(%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, 0x8(%rsp)
movq 0x8(%rsi), %rdi
cltq
movq %rsi, %r14
leaq 0x8(,%rax,8), %rsi
movl %r10d, (%rsp)
movq %rdx, 0x18(%rsp)
callq 0x6c80
movq %rax, 0x8(%r14)
movq 0x10(%rsp), %rcx
leaq (%rax,%rcx,8), %rdi
movslq 0x4(%r14), %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x63b0
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movl (%rsp), %r10d
cmpl %edx, %r12d
jne 0x5014e
movq 0x8(%rsi), %rax
cmpq $-0x1, (%rax,%r12,8)
jne 0x50173
movq %rdi, (%rax,%r12,8)
jmp 0x50173
incq 0x20(%r15)
jmp 0x5017b
jg 0x50173
movl %edx, %eax
subl %r12d, %eax
incl %eax
shlq $0x3, %r12
addq 0x8(%rsi), %r12
xorl %ecx, %ecx
cmpq $-0x1, (%r12,%rcx,8)
jne 0x5016c
movq %rdi, (%r12,%rcx,8)
incq %rcx
cmpl %ecx, %eax
jne 0x50161
cmpl %edx, (%rsi)
jg 0x5017b
incl %edx
movl %edx, (%rsi)
movl 0x8(%r15), %edx
xorl %r11d, %r11d
testl %edx, %edx
jle 0x501e5
decq %r13
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 0x20(%rsp), %r14
movq %rbp, %r8
movl %eax, %ecx
sarq %cl, %r8
movq %r13, %r9
sarq %cl, %r9
cmpq %r9, %r8
je 0x501ec
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 0x501b5
jmp 0x501f2
movq 0x20(%rsp), %r14
jmp 0x501f2
addl %r8d, %esi
movl %esi, %r11d
cmpl %r11d, 0x40(%r15)
movl 0x4(%rsp), %ecx
je 0x50473
movl 0x44(%r15), %esi
cmpl $-0x1, %esi
je 0x502c8
movl %r11d, 0x18(%rsp)
movl %r10d, (%rsp)
movslq 0x50(%r15), %rax
movq 0x28(%r15), %rcx
movq 0x58(%r15), %rdx
movq %rdx, 0x8(%rsp)
movq (%rcx,%rax,8), %r12
movq 0x60(%r15), %rax
movq %rax, 0x10(%rsp)
leaq 0x2c(%rsp), %r13
movq %r12, %rdi
movq %r13, %rdx
callq 0x51f24
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r12), %rbp
cmpl $0x0, (%r13)
je 0x50275
movq $0x1, (%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%rbp)
movl (%rbp), %eax
cmpl %eax, 0x4(%rbp)
jne 0x50296
addl %eax, %eax
movl %eax, (%rbp)
movq 0x10(%rbp), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x6c80
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 0x8(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
movl 0x4(%rsp), %ecx
movl (%rsp), %r10d
movl 0x18(%rsp), %r11d
cmpl $-0x1, 0x40(%r15)
jne 0x5045f
cmpl $-0x1, 0x44(%r15)
je 0x5045f
movl %r11d, 0x18(%rsp)
movl %r10d, (%rsp)
movq 0x58(%r15), %r14
movq %r14, 0x70(%r15)
movq 0x28(%r15), %rax
movslq 0x50(%r15), %rcx
movq (%rax,%rcx,8), %r12
movl 0xc(%r15), %esi
incl %esi
movq 0x68(%r15), %rax
movq %rax, 0x8(%rsp)
leaq 0x30(%rsp), %r13
movq %r12, %rdi
movq %r13, %rdx
callq 0x51f24
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r12), %rbp
cmpl $0x0, (%r13)
je 0x5034b
movq $0x1, (%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%rbp)
movl (%rbp), %eax
cmpl %eax, 0x4(%rbp)
jne 0x5036c
addl %eax, %eax
movl %eax, (%rbp)
movq 0x10(%rbp), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x10(%rbp)
movq 0x10(%rbp), %rax
movslq 0x4(%rbp), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq 0x8(%rsp), %rsi
movq %rsi, (%rax,%rcx)
movl %edx, 0x4(%rbp)
movq %r14, 0x8(%rax,%rcx)
movq 0x28(%r15), %rax
movslq 0x50(%r15), %rcx
movq (%rax,%rcx,8), %r12
movl 0xc(%r15), %esi
incl %esi
movq 0x78(%r15), %rax
movq %rax, 0x10(%rsp)
movq 0x80(%r15), %rax
movq %rax, 0x8(%rsp)
leaq 0x34(%rsp), %r13
movq %r12, %rdi
movq %r13, %rdx
callq 0x51f24
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r12), %rbp
cmpl $0x0, (%r13)
je 0x503f4
movq $0x1, (%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%rbp)
leaq 0x78(%r15), %r14
movl (%rbp), %eax
cmpl %eax, 0x4(%rbp)
jne 0x50419
addl %eax, %eax
movl %eax, (%rbp)
movq 0x10(%rbp), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x6c80
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 0x8(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq 0x70(%r15), %rax
movq %rax, 0x68(%r15)
movq 0x20(%rsp), %r14
movl 0x4(%rsp), %ecx
movl (%rsp), %r10d
movl 0x18(%rsp), %r11d
movq 0x58(%r15), %rax
movq %rax, 0x60(%r15)
movl %r11d, 0x40(%r15)
movl %r11d, 0x44(%r15)
movl %ebx, 0x50(%r15)
xorl %eax, %eax
testl %ecx, %ecx
sete %al
incq 0x78(%r15,%rax,8)
movq %r14, 0x58(%r15)
movl %r10d, 0x48(%r15)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq