// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movl %r9d, %r12d
movq %r8, %rbp
movl %ecx, %r13d
movl %edx, %r11d
movl %esi, %r15d
movq %rdi, %r14
movslq 0x18(%rdi), %rbx
cmpl %esi, %ebx
jg 0x6026
leal (%rbx,%rbx), %eax
testl %ebx, %ebx
pushq $0x2
popq %rcx
cmovnel %eax, %ecx
movl %ecx, 0x18(%r14)
movq 0x28(%r14), %rdi
movslq %ecx, %rsi
shlq $0x3, %rsi
movl %r13d, 0x8(%rsp)
movl %r12d, %r13d
movl %r11d, %r12d
callq 0x22f0
movq %rax, 0x28(%r14)
movq 0x30(%r14), %rdi
movslq 0x18(%r14), %rsi
shlq $0x4, %rsi
callq 0x22f0
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
movl %r12d, %r11d
movl %r13d, %r12d
movl 0x8(%rsp), %r13d
cmpl %r15d, 0x14(%r14)
jg 0x6034
leal 0x1(%r15), %eax
movl %eax, 0x14(%r14)
testl %r15d, %r15d
jns 0x603d
incq 0x20(%r14)
xorl %ebx, %ebx
cmpl $0x0, 0x54(%r14)
jne 0x6353
movq %rbp, 0x8(%rsp)
movq 0x28(%r14), %rbx
movslq %r15d, %rdi
cmpq $0x0, (%rbx,%rdi,8)
jne 0x6076
movl %r11d, 0x4(%rsp)
movq %rdi, %rbp
callq 0x7a7e
movq %rbp, %rdi
movl 0x4(%rsp), %r11d
movq %rax, (%rbx,%rbp,8)
testl %r15d, %r15d
sets %cl
movl 0x4c(%r14), %eax
testl %eax, %eax
setns %dl
movslq %r11d, %rbp
movslq %r13d, %r13
cmpl %r15d, %eax
jl 0x60c3
andb %dl, %cl
jne 0x60c3
cmpl %r15d, %eax
jbe 0x61bb
pushq $-0x1
popq %rbx
cmpl $0x0, 0xb189(%rip)      # 0x11230
jle 0x6353
movq 0xaf44(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x62ae(%rip), %rsi      # 0xc36c
jmp 0x61eb
movl %r15d, 0x4c(%r14)
orl $-0x1, 0x40(%r14)
testl %r15d, %r15d
sets %al
testl %r12d, %r12d
setne %dl
sete %cl
orb %al, %cl
jne 0x6221
movq 0x30(%r14), %rax
shlq $0x4, %rdi
movb 0x4(%r14), %cl
movq %rbp, %rbx
sarq %cl, %rbx
leaq -0x1(%r13), %rsi
sarq %cl, %rsi
leaq (%rax,%rdi), %r12
movq 0x58(%r14), %rdx
movslq 0x4(%rax,%rdi), %rax
cmpl %esi, %eax
jg 0x6196
movq %rax, 0x10(%rsp)
movl %esi, %eax
sarl %eax
orl %esi, %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(%r12)
movq 0x8(%r12), %rdi
leal 0x8(,%rax,8), %eax
movq %rsi, 0x20(%rsp)
movslq %eax, %rsi
movl %r11d, 0x4(%rsp)
movq %rdx, 0x18(%rsp)
callq 0x22f0
movq %rax, 0x8(%r12)
movq 0x10(%rsp), %rcx
leaq (%rax,%rcx,8), %rdi
movslq 0x4(%r12), %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x21b0
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rsi
movl 0x4(%rsp), %r11d
cmpl %esi, %ebx
jne 0x61fe
movq 0x8(%r12), %rax
cmpq $-0x1, (%rax,%rbx,8)
jne 0x61aa
movq %rdx, (%rax,%rbx,8)
movb $0x1, %dl
cmpl %esi, (%r12)
jg 0x6221
leal 0x1(%rsi), %eax
movl %eax, (%r12)
jmp 0x6221
testl %r15d, %r15d
js 0x621b
cmpl %r11d, 0x48(%r14)
jle 0x60cc
pushq $-0x1
popq %rbx
cmpl $0x0, 0xb05c(%rip)      # 0x11230
jle 0x6353
movq 0xae17(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x61ac(%rip), %rsi      # 0xc397
leaq 0x6198(%rip), %rdx      # 0xc38a
xorl %eax, %eax
callq 0x2220
jmp 0x6353
movslq %esi, %rax
cmpq %rax, %rbx
jg 0x61aa
movq 0x8(%r12), %rcx
cmpq $-0x1, (%rcx,%rbx,8)
jne 0x6216
movq %rdx, (%rcx,%rbx,8)
incq %rbx
jmp 0x6201
testl %r12d, %r12d
setne %dl
movb %dl, 0x4(%rsp)
movl 0x4(%r14), %esi
movl 0x8(%r14), %edi
leal (%rdi,%rdi,2), %ecx
pushq $-0x1
popq %r8
movl %r8d, %eax
shll %cl, %eax
notl %eax
xorl %ebx, %ebx
pushq $0x7
popq %rcx
xorl %edx, %edx
divl %ecx
decq %r13
leal (%rdi,%rdi,2), %edx
addl $-0x3, %edx
testl %edi, %edi
jle 0x627e
movq %rbp, %r9
movl %esi, %ecx
sarq %cl, %r9
movq %r13, %r10
sarq %cl, %r10
cmpq %r10, %r9
je 0x6279
movl %r8d, %r9d
movl %edx, %ecx
shll %cl, %r9d
decl %edi
addl $0x3, %esi
addl %r9d, %eax
addl $-0x3, %edx
jmp 0x624d
addl %r9d, %eax
movl %eax, %ebx
movl 0x40(%r14), %eax
cmpl %ebx, %eax
movq 0x8(%rsp), %r12
je 0x633b
movl 0x44(%r14), %esi
cmpl $-0x1, %esi
je 0x62bb
movslq 0x50(%r14), %rax
movq 0x28(%r14), %rdx
movq 0x58(%r14), %rcx
movq (%rdx,%rax,8), %rdi
movq 0x60(%r14), %rdx
movl %r11d, %ebp
callq 0x5d6b
movl %ebp, %r11d
movl 0x40(%r14), %eax
cmpl $-0x1, %eax
jne 0x6322
cmpl $-0x1, 0x44(%r14)
je 0x6322
movq 0x58(%r14), %rcx
movq %rcx, 0x70(%r14)
movq 0x28(%r14), %rax
movslq 0x50(%r14), %rdx
movq (%rax,%rdx,8), %rdi
movl 0xc(%r14), %esi
incl %esi
movq 0x68(%r14), %rdx
movl %r11d, %ebp
callq 0x5d6b
movq 0x28(%r14), %rax
movslq 0x50(%r14), %rcx
movq (%rax,%rcx,8), %rdi
movl 0xc(%r14), %esi
incl %esi
movq 0x78(%r14), %rdx
movq 0x80(%r14), %rcx
callq 0x5d6b
movl %ebp, %r11d
xorps %xmm0, %xmm0
movups %xmm0, 0x78(%r14)
movq 0x70(%r14), %rax
movq %rax, 0x68(%r14)
movq 0x58(%r14), %rax
movq %rax, 0x60(%r14)
movl %ebx, 0x40(%r14)
movl %ebx, 0x44(%r14)
movl %r15d, 0x50(%r14)
testl %r15d, %r15d
js 0x6364
movb 0x4(%rsp), %al
xorb $0x1, %al
movzbl %al, %eax
incq 0x78(%r14,%rax,8)
movq %r12, 0x58(%r14)
movl %r11d, 0x48(%r14)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %r12, %rsi
callq 0x5945
jmp 0x6351