// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movl %r9d, 0x14(%rsp)
movq %r8, %r15
movl %ecx, %r13d
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %r14
movslq 0x18(%rdi), %rbx
cmpl %esi, %ebx
jg 0x67be
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 %r12d, 0x14(%r14)
jg 0x67cd
leal 0x1(%r12), %eax
movl %eax, 0x14(%r14)
testl %r12d, %r12d
jns 0x67d6
incq 0x20(%r14)
xorl %ebx, %ebx
cmpl $0x0, 0x54(%r14)
jne 0x6c6c
movq %r15, 0x18(%rsp)
movq 0x28(%r14), %rbx
movslq %r12d, %r15
cmpq $0x0, (%rbx,%r15,8)
jne 0x6809
movl $0x1, %edi
movl $0x28, %esi
callq 0x21f0
movq %rax, (%rbx,%r15,8)
testl %r12d, %r12d
sets %cl
movl 0x4c(%r14), %eax
testl %eax, %eax
setns %dl
cmpl %r12d, %eax
jl 0x6846
andb %dl, %cl
jne 0x6846
cmpl %r12d, %eax
jbe 0x692b
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x0, 0xb9ea(%rip)      # 0x12220
jle 0x6c6c
callq 0x24e2
jmp 0x6c6c
movl %r12d, 0x4c(%r14)
movl $0xffffffff, 0x40(%r14) # imm = 0xFFFFFFFF
testl %r12d, %r12d
sets %al
cmpl $0x0, 0x14(%rsp)
sete %cl
orb %al, %cl
movl %ebp, 0x10(%rsp)
movslq %ebp, %rbp
movslq %r13d, %r13
jne 0x6986
movq 0x30(%r14), %rax
shlq $0x4, %r15
movb 0x4(%r14), %cl
movq %rbp, %rbx
sarq %cl, %rbx
leaq -0x1(%r13), %rdx
sarq %cl, %rdx
leaq (%rax,%r15), %rsi
movq 0x58(%r14), %rdi
movslq 0x4(%rax,%r15), %rax
cmpl %edx, %eax
jg 0x6916
movq %rax, 0x20(%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, (%rsp)
movq 0x8(%rsi), %rdi
leal 0x8(,%rax,8), %eax
movq %rsi, %r15
movslq %eax, %rsi
movq %rdx, 0x8(%rsp)
callq 0x22e0
movq %rax, 0x8(%r15)
movq 0x20(%rsp), %rcx
leaq (%rax,%rcx,8), %rdi
movslq 0x4(%r15), %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x21b0
movq (%rsp), %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
cmpl %edx, %ebx
jne 0x695a
movq 0x8(%rsi), %rax
cmpq $-0x1, (%rax,%rbx,8)
jne 0x697e
movq %rdi, (%rax,%rbx,8)
jmp 0x697e
testl %r12d, %r12d
js 0x6852
cmpl %ebp, 0x48(%r14)
jle 0x6852
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x0, 0xb8d6(%rip)      # 0x12220
jle 0x6c6c
callq 0x24c3
jmp 0x6c6c
jg 0x697e
movl %edx, %eax
subl %ebx, %eax
incl %eax
shlq $0x3, %rbx
addq 0x8(%rsi), %rbx
xorl %ecx, %ecx
cmpq $-0x1, (%rbx,%rcx,8)
jne 0x6977
movq %rdi, (%rbx,%rcx,8)
incq %rcx
cmpl %ecx, %eax
jne 0x696c
cmpl %edx, (%rsi)
jg 0x6986
incl %edx
movl %edx, (%rsi)
movl 0x8(%r14), %edx
xorl %r15d, %r15d
testl %edx, %edx
jle 0x69f1
decq %r13
leal (%rdx,%rdx,2), %ecx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
shll %cl, %edi
movl 0x4(%r14), %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 %rbp, %r8
movl %eax, %ecx
sarq %cl, %r8
movq %r13, %r9
sarq %cl, %r9
cmpq %r9, %r8
je 0x69eb
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 0x69bb
jmp 0x69f1
addl %r8d, %esi
movl %esi, %r15d
cmpl %r15d, 0x40(%r14)
movl 0x10(%rsp), %ecx
je 0x6c4e
movl 0x44(%r14), %esi
cmpl $-0x1, %esi
je 0x6ab2
movslq 0x50(%r14), %rax
movq 0x28(%r14), %rcx
movq 0x58(%r14), %rdx
movq %rdx, 0x8(%rsp)
movq (%rcx,%rax,8), %rbx
movq 0x60(%r14), %rax
movq %rax, (%rsp)
leaq 0x2c(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rdx
callq 0x851b
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%rbx), %rbp
cmpl $0x0, (%r13)
je 0x6a69
movq $0x1, (%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x21f0
movq %rax, 0x10(%rbp)
movl (%rbp), %eax
cmpl %eax, 0x4(%rbp)
jne 0x6a8a
leal (%rax,%rax), %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
shll $0x5, %eax
movslq %eax, %rsi
callq 0x22e0
movq %rax, 0x10(%rbp)
movq 0x10(%rbp), %rax
movslq 0x4(%rbp), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq (%rsp), %rsi
movq %rsi, (%rax,%rcx)
movl %edx, 0x4(%rbp)
movq 0x8(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
movl 0x10(%rsp), %ecx
cmpl $-0x1, 0x40(%r14)
jne 0x6c35
cmpl $-0x1, 0x44(%r14)
je 0x6c35
movq 0x58(%r14), %rax
movq %rax, 0x8(%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, (%rsp)
leaq 0x30(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rdx
callq 0x851b
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%rbx), %rbp
cmpl $0x0, (%r13)
je 0x6b2f
movq $0x1, (%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x21f0
movq %rax, 0x10(%rbp)
movl (%rbp), %eax
cmpl %eax, 0x4(%rbp)
jne 0x6b50
leal (%rax,%rax), %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
shll $0x5, %eax
movslq %eax, %rsi
callq 0x22e0
movq %rax, 0x10(%rbp)
movq 0x10(%rbp), %rax
movslq 0x4(%rbp), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq (%rsp), %rsi
movq %rsi, (%rax,%rcx)
movl %edx, 0x4(%rbp)
movq 0x8(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
movq 0x28(%r14), %rax
movslq 0x50(%r14), %rcx
movq (%rax,%rcx,8), %rbx
movl 0xc(%r14), %esi
incl %esi
movq 0x78(%r14), %rax
movq %rax, (%rsp)
movq 0x80(%r14), %rax
movq %rax, 0x8(%rsp)
leaq 0x34(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rdx
callq 0x851b
movl %eax, %eax
leaq (%rax,%rax,2), %rbp
shlq $0x3, %rbp
addq 0x20(%rbx), %rbp
cmpl $0x0, (%r13)
je 0x6bda
movq $0x1, (%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x21f0
movq %rax, 0x10(%rbp)
leaq 0x78(%r14), %rbx
movl (%rbp), %eax
cmpl %eax, 0x4(%rbp)
jne 0x6bff
leal (%rax,%rax), %ecx
movl %ecx, (%rbp)
movq 0x10(%rbp), %rdi
shll $0x5, %eax
movslq %eax, %rsi
callq 0x22e0
movq %rax, 0x10(%rbp)
movq 0x10(%rbp), %rax
movslq 0x4(%rbp), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq (%rsp), %rsi
movq %rsi, (%rax,%rcx)
movl %edx, 0x4(%rbp)
movq 0x8(%rsp), %rdx
movq %rdx, 0x8(%rax,%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq 0x70(%r14), %rax
movq %rax, 0x68(%r14)
movl 0x10(%rsp), %ecx
movq 0x58(%r14), %rax
movq %rax, 0x60(%r14)
movl %r15d, 0x40(%r14)
movl %r15d, 0x44(%r14)
movl %r12d, 0x50(%r14)
testl %r12d, %r12d
js 0x6c7d
xorl %eax, %eax
cmpl $0x0, 0x14(%rsp)
sete %al
incq 0x78(%r14,%rax,8)
movq 0x18(%rsp), %rax
movq %rax, 0x58(%r14)
movl %ecx, 0x48(%r14)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x5ef7
jmp 0x6c6a