// File: /workspace/github_c_makefile_star2_O3/DReichLab[P]adna/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 >= 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(void*));
		idx->lidx = (lidx_t*) realloc(idx->lidx, idx->m * sizeof(lidx_t));
		memset(&idx->bidx[oldm], 0, (idx->m - oldm) * sizeof(void*));
		memset(&idx->lidx[oldm], 0, (idx->m - oldm) * sizeof(lidx_t));
	}
	if (idx->n < tid + 1) idx->n = tid + 1;
	if (tid < 0) ++idx->n_no_coor;
	if (idx->z.finished) return 0;
	if (idx->bidx[tid] == 0) idx->bidx[tid] = kh_init(bin);
	if (idx->z.last_tid < tid || (idx->z.last_tid >= 0 && tid < 0)) { // change of chromosome
		idx->z.last_tid = tid;
		idx->z.last_bin = 0xffffffffu;
	} else if ((uint32_t)idx->z.last_tid > (uint32_t)tid) { // test if chromosomes are out of order
		if (hts_verbose >= 1) fprintf(stderr, "[E::%s] unsorted chromosomes\n", __func__);
		return -1;
	} 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 && 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
	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], idx->n_bins + 1, idx->z.off_beg, idx->z.off_end);
			insert_to_b(idx->bidx[idx->z.save_tid], idx->n_bins + 1, 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 (tid < 0) { // come to the end of the records having coordinates
			hts_idx_finish(idx, offset);
			return 0;
		}
	}
	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, %r13d
movq %r8, %rbp
movl %ecx, 0x4(%rsp)
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %r14
movslq 0x18(%rdi), %rbx
cmpl %esi, %ebx
jg 0x6986
leal (%rbx,%rbx), %eax
testl %ebx, %ebx
movl $0x2, %ecx
cmovnel %eax, %ecx
movl %ecx, 0x18(%r14)
movq 0x28(%r14), %rdi
movslq %ecx, %rsi
shlq $0x3, %rsi
callq 0x22e0
movq %rax, 0x28(%r14)
movq 0x30(%r14), %rdi
movslq 0x18(%r14), %rsi
shlq $0x4, %rsi
callq 0x22e0
movq %rax, 0x30(%r14)
leaq (,%rbx,8), %rdi
addq 0x28(%r14), %rdi
movslq 0x18(%r14), %rdx
subq %rbx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x21b0
movq %rbx, %rdi
shlq $0x4, %rdi
addq 0x30(%r14), %rdi
movslq 0x18(%r14), %rdx
subq %rbx, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x21b0
cmpl %r15d, 0x14(%r14)
jg 0x6994
leal 0x1(%r15), %eax
movl %eax, 0x14(%r14)
testl %r15d, %r15d
jns 0x699d
incq 0x20(%r14)
xorl %ebx, %ebx
cmpl $0x0, 0x54(%r14)
jne 0x6e8d
movl %r12d, (%rsp)
movq 0x28(%r14), %rbx
movslq %r15d, %r12
cmpq $0x0, (%rbx,%r12,8)
jne 0x69cf
movl $0x1, %edi
movl $0x28, %esi
callq 0x21f0
movq %rax, (%rbx,%r12,8)
testl %r15d, %r15d
sets %cl
movl 0x4c(%r14), %eax
testl %eax, %eax
setns %dl
cmpl %r15d, %eax
jl 0x6a0c
andb %dl, %cl
jne 0x6a0c
cmpl %r15d, %eax
jbe 0x6add
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x0, 0xb824(%rip)      # 0x12220
jle 0x6e8d
callq 0x24e2
jmp 0x6e8d
movl %r15d, 0x4c(%r14)
movl $0xffffffff, 0x40(%r14) # imm = 0xFFFFFFFF
testl %r15d, %r15d
sets %al
testl %r13d, %r13d
setne %r13b
sete %cl
orb %al, %cl
jne 0x6b4d
movq %rbp, 0x8(%rsp)
movq 0x30(%r14), %rax
shlq $0x4, %r12
movslq (%rsp), %r13
movslq 0x4(%rsp), %rbx
movb 0x4(%r14), %cl
sarq %cl, %r13
decq %rbx
sarq %cl, %rbx
leaq (%rax,%r12), %rbp
movq 0x58(%r14), %rdx
movslq 0x4(%rax,%r12), %r12
cmpl %ebx, %r12d
jg 0x6ac7
movl %ebx, %eax
sarl %eax
orl %ebx, %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(%rbp)
movq 0x8(%rbp), %rdi
leal 0x8(,%rax,8), %eax
movslq %eax, %rsi
movq %rdx, 0x10(%rsp)
callq 0x22e0
movq %rax, 0x8(%rbp)
leaq (%rax,%r12,8), %rdi
movslq 0x4(%rbp), %rdx
subq %r12, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x21b0
movq 0x10(%rsp), %rdx
cmpl %ebx, %r13d
jne 0x6b0b
movq 0x8(%rbp), %rax
cmpq $-0x1, (%rax,%r13,8)
jne 0x6b32
movq %rdx, (%rax,%r13,8)
jmp 0x6b32
testl %r15d, %r15d
js 0x6b46
movl (%rsp), %eax
cmpl %eax, 0x48(%r14)
jle 0x6a18
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x0, 0xb725(%rip)      # 0x12220
jle 0x6e8d
callq 0x24c3
jmp 0x6e8d
jg 0x6b32
movl %ebx, %eax
subl %r13d, %eax
incl %eax
shlq $0x3, %r13
addq 0x8(%rbp), %r13
xorl %ecx, %ecx
cmpq $-0x1, (%r13,%rcx,8)
jne 0x6b2b
movq %rdx, (%r13,%rcx,8)
incq %rcx
cmpl %ecx, %eax
jne 0x6b1e
movb $0x1, %r13b
cmpl %ebx, (%rbp)
jg 0x6b3f
incl %ebx
movl %ebx, (%rbp)
movq 0x8(%rsp), %rbp
jmp 0x6b4d
testl %r13d, %r13d
setne %r13b
movl 0x8(%r14), %edx
xorl %ebx, %ebx
testl %edx, %edx
jle 0x6bc5
movl (%rsp), %r12d
movslq %r12d, %rsi
movslq 0x4(%rsp), %rdi
decq %rdi
leal (%rdx,%rdx,2), %ecx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
shll %cl, %r9d
movl 0x4(%r14), %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 0x6bcb
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 0x6b93
jmp 0x6bd1
movl (%rsp), %r12d
jmp 0x6bd1
addl %r10d, %r8d
movl %r8d, %ebx
movl 0x40(%r14), %eax
cmpl %ebx, %eax
je 0x6e76
movl 0x44(%r14), %esi
cmpl $-0x1, %esi
je 0x6ca9
movl %ebx, 0x4(%rsp)
movq %rbp, 0x8(%rsp)
movq 0x28(%r14), %rax
movslq 0x50(%r14), %rcx
movq (%rax,%rcx,8), %rbx
movups 0x58(%r14), %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x3c(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x8732
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%rbx), %rbp
cmpl $0x0, (%r12)
je 0x6c50
movl $0x1, (%rbp)
leaq 0x4(%rbp), %rbx
movl $0x1, %edi
movl $0x10, %esi
callq 0x21f0
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
jmp 0x6c7e
leaq 0x4(%rbp), %rbx
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
jne 0x6c7a
leal (%rcx,%rcx), %eax
movl %eax, (%rbp)
movq 0x10(%rbp), %rdi
shll $0x5, %ecx
movslq %ecx, %rsi
callq 0x22e0
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x6c7e
movq 0x10(%rbp), %rax
movl (%rsp), %r12d
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
incl %ecx
movl %ecx, (%rbx)
pshufd $0x4e, 0x10(%rsp), %xmm0 # xmm0 = mem[2,3,0,1]
movdqu %xmm0, (%rax,%rdx)
movl 0x40(%r14), %eax
movq 0x8(%rsp), %rbp
movl 0x4(%rsp), %ebx
cmpl $-0x1, %eax
jne 0x6e5d
cmpl $-0x1, 0x44(%r14)
je 0x6e5d
movl %ebx, 0x4(%rsp)
movq %rbp, 0x8(%rsp)
movq 0x58(%r14), %rax
movq %rax, 0x10(%rsp)
movq %rax, 0x70(%r14)
movq 0x28(%r14), %rax
movslq 0x50(%r14), %rcx
movq (%rax,%rcx,8), %rbx
movl 0xc(%r14), %esi
incl %esi
movq 0x68(%r14), %rax
movq %rax, 0x20(%rsp)
leaq 0x40(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x8732
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%rbx), %rbp
cmpl $0x0, (%r12)
je 0x6d35
movl $0x1, (%rbp)
leaq 0x4(%rbp), %rbx
movl $0x1, %edi
movl $0x10, %esi
callq 0x21f0
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
jmp 0x6d63
leaq 0x4(%rbp), %rbx
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
jne 0x6d5f
leal (%rcx,%rcx), %eax
movl %eax, (%rbp)
movq 0x10(%rbp), %rdi
shll $0x5, %ecx
movslq %ecx, %rsi
callq 0x22e0
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x6d63
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, (%rbx)
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax,%rdx)
movq 0x28(%r14), %rax
movslq 0x50(%r14), %rcx
movq (%rax,%rcx,8), %rbx
movl 0xc(%r14), %esi
incl %esi
leaq 0x78(%r14), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%r14), %xmm0
movaps %xmm0, 0x20(%rsp)
leaq 0x44(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x8732
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%rbx), %rbp
cmpl $0x0, (%r12)
je 0x6df4
movl $0x1, (%rbp)
leaq 0x4(%rbp), %rbx
movl $0x1, %edi
movl $0x10, %esi
callq 0x21f0
movq %rax, 0x10(%rbp)
xorl %ecx, %ecx
movl (%rsp), %r12d
jmp 0x6e26
leaq 0x4(%rbp), %rbx
movl 0x4(%rbp), %ecx
cmpl (%rbp), %ecx
movl (%rsp), %r12d
jne 0x6e22
leal (%rcx,%rcx), %eax
movl %eax, (%rbp)
movq 0x10(%rbp), %rdi
shll $0x5, %ecx
movslq %ecx, %rsi
callq 0x22e0
movq %rax, 0x10(%rbp)
movl 0x4(%rbp), %ecx
jmp 0x6e26
movq 0x10(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
incl %ecx
movl %ecx, (%rbx)
movdqa 0x20(%rsp), %xmm0
movdqu %xmm0, (%rax,%rdx)
pxor %xmm0, %xmm0
movq 0x10(%rsp), %rax
movdqu %xmm0, (%rax)
movq 0x70(%r14), %rax
movq %rax, 0x68(%r14)
movq 0x8(%rsp), %rbp
movl 0x4(%rsp), %ebx
movq 0x58(%r14), %rax
movq %rax, 0x60(%r14)
movl %ebx, 0x40(%r14)
movl %ebx, 0x44(%r14)
movl %r15d, 0x50(%r14)
testl %r15d, %r15d
js 0x6e9e
xorb $0x1, %r13b
movzbl %r13b, %eax
incq 0x78(%r14,%rax,8)
movq %rbp, 0x58(%r14)
movl %r12d, 0x48(%r14)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5fd7
jmp 0x6e8b