// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %r9d, 0x8(%rsp)
movq %r8, 0x30(%rsp)
movl %ecx, %r12d
movl %edx, %r13d
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 0x5028c
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 0x6c80
movq %rax, 0x28(%r15)
movq 0x30(%r15), %rdi
movslq 0x18(%r15), %rsi
shlq $0x4, %rsi
callq 0x6c80
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 0x63b0
movq %r14, %rdi
shlq $0x4, %rdi
addq 0x30(%r15), %rdi
movslq 0x18(%r15), %rdx
subq %r14, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x63b0
cmpl %ebx, 0x14(%r15)
jg 0x50299
leal 0x1(%rbx), %eax
movl %eax, 0x14(%r15)
xorl %r14d, %r14d
cmpl $0x0, 0x54(%r15)
jne 0x507c4
testl %ebx, %ebx
sets %al
movl 0x4c(%r15), %r8d
testl %r8d, %r8d
setns %cl
cmpl %ebx, %r8d
jne 0x502ea
andb %cl, %al
jne 0x502ea
testl %ebx, %ebx
js 0x5033e
cmpl %r13d, 0x48(%r15)
jle 0x50437
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x70aee(%rip)     # 0xc0dc8
jle 0x507c4
callq 0x7611
jmp 0x507c4
testl %ebx, %ebx
js 0x50332
cmpq $0x0, 0x20(%r15)
je 0x5044b
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x70ac2(%rip)     # 0xc0dc8
jle 0x507c4
movq 0x6ecc5(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x483f9(%rip), %rsi     # 0x98716
leaq 0x48430(%rip), %rdx     # 0x98754
movl %ebx, %ecx
xorl %eax, %eax
callq 0x6a90
jmp 0x507c4
movl %ebx, 0x4c(%r15)
movl $0xffffffff, 0x40(%r15) # imm = 0xFFFFFFFF
incq 0x20(%r15)
movl 0x8(%r15), %edx
xorl %r13d, %r13d
testl %edx, %edx
jle 0x503bd
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 0x503b7
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 0x50385
jmp 0x503bd
addl %r10d, %r8d
movl %r8d, %r13d
movl 0x40(%r15), %eax
cmpl %r13d, %eax
je 0x507a1
movl 0x44(%r15), %esi
cmpl $-0x1, %esi
je 0x505f1
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 0x52225
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r14), %rbp
cmpl $0x0, (%r12)
je 0x50476
movl $0x1, (%rbp)
leaq 0x4(%rbp), %r14
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
jmp 0x505d2
movq 0x28(%r15), %rax
movl %ebx, %r14d
cmpq $0x0, (%rax,%r14,8)
jne 0x504d0
jmp 0x504b3
movq 0x28(%r15), %rax
movl %ebx, %r14d
cmpq $0x0, (%rax,%r14,8)
je 0x504a7
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x70962(%rip)     # 0xc0dc8
jle 0x507c4
callq 0x7630
jmp 0x507c4
leaq 0x4(%rbp), %r14
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
jne 0x505ce
addl %ecx, %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x505d2
movl %ebx, 0x4c(%r15)
movl $0xffffffff, 0x40(%r15) # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x6470
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
cmpl $0x0, 0x8(%rsp)
je 0x50342
movq 0x30(%r15), %rax
shlq $0x4, %r14
movslq %r13d, %r13
movslq %r12d, %r12
movb 0x4(%r15), %cl
sarq %cl, %r13
decq %r12
sarq %cl, %r12
leaq (%rax,%r14), %rdx
movq 0x58(%r15), %rsi
movslq 0x4(%rax,%r14), %rax
cmpl %r12d, %eax
jg 0x5057c
movq %rax, 0x20(%rsp)
movl %r12d, %eax
sarl %eax
orl %r12d, %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 0x6c80
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 0x63b0
movq 0x10(%rsp), %rsi
movq %r14, %rdx
cmpl %r12d, %r13d
jne 0x50592
movq 0x8(%rdx), %rax
cmpq $-0x1, (%rax,%r13,8)
jne 0x505ba
movq %rsi, (%rax,%r13,8)
jmp 0x505ba
jg 0x505ba
movl %r12d, %eax
subl %r13d, %eax
incl %eax
shlq $0x3, %r13
addq 0x8(%rdx), %r13
xorl %ecx, %ecx
cmpq $-0x1, (%r13,%rcx,8)
jne 0x505b3
movq %rsi, (%r13,%rcx,8)
incq %rcx
cmpl %ecx, %eax
jne 0x505a6
cmpl %r12d, (%rdx)
jg 0x50342
incl %r12d
movl %r12d, (%rdx)
jmp 0x50342
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 0x5078d
cmpl $-0x1, 0x44(%r15)
je 0x5078d
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 0x52225
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r14), %rbp
cmpl $0x0, (%r12)
je 0x50674
movl $0x1, (%rbp)
leaq 0x4(%rbp), %r14
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
jmp 0x506a2
leaq 0x4(%rbp), %r14
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
jne 0x5069e
addl %ecx, %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x506a2
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 0x52225
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%r14), %rbp
cmpl $0x0, (%r12)
je 0x50730
movl $0x1, (%rbp)
leaq 0x4(%rbp), %r14
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
jmp 0x5075e
leaq 0x4(%rbp), %r14
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
jne 0x5075a
addl %ecx, %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x5075e
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