// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jl 0x9421
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x936f
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
shll %eax
movl %eax, -0x38(%rbp)
jmp 0x9379
movl $0x2, %eax
movl %eax, -0x38(%rbp)
jmp 0x9379
movl -0x38(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rsi
shlq $0x3, %rsi
callq 0x22f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rsi
shlq $0x4, %rsi
callq 0x22f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movslq -0x34(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
subl -0x34(%rbp), %eax
movslq %eax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x21b0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movslq -0x34(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
subl -0x34(%rbp), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x21b0
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x943f
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
cmpl $0x0, -0x14(%rbp)
jge 0x9455
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x946b
movl $0x0, -0x4(%rbp)
jmp 0x974e
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x14(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x9496
callq 0xc520
movq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %eax
cmpl -0x14(%rbp), %eax
jl 0x94b2
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
jl 0x94cc
cmpl $0x0, -0x14(%rbp)
jge 0x94cc
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4c(%rax)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x40(%rax) # imm = 0xFFFFFFFF
jmp 0x9556
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %eax
cmpl -0x14(%rbp), %eax
jbe 0x950c
cmpl $0x1, 0xdd51(%rip)      # 0x17230
jl 0x9500
movq 0xdb10(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x9e5a(%rip), %rsi      # 0x1334c
leaq 0x9e71(%rip), %rdx      # 0x1336a
movb $0x0, %al
callq 0x2230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x974e
cmpl $0x0, -0x14(%rbp)
jl 0x9552
movq -0x10(%rbp), %rax
movl 0x48(%rax), %eax
cmpl -0x18(%rbp), %eax
jle 0x9552
cmpl $0x1, 0xdd0b(%rip)      # 0x17230
jl 0x9546
movq 0xdaca(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x9e3f(%rip), %rsi      # 0x13377
leaq 0x9e2b(%rip), %rdx      # 0x1336a
movb $0x0, %al
callq 0x2230
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x974e
jmp 0x9554
jmp 0x9556
cmpl $0x0, -0x14(%rbp)
jl 0x9592
cmpl $0x0, -0x2c(%rbp)
je 0x9592
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movslq -0x14(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movslq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x10(%rbp), %rax
movl 0x4(%rax), %r8d
callq 0x9760
movslq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
callq 0x9930
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x40(%rax), %eax
cmpl -0x30(%rbp), %eax
je 0x9703
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x44(%rax)
je 0x95fa
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x50(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movl 0x44(%rax), %esi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rcx
callq 0x8b10
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x40(%rax)
jne 0x96ba
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x44(%rax)
je 0x96ba
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x50(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
addl $0x1, %esi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rcx
callq 0x8b10
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x50(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
addl $0x1, %esi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
callq 0x8b10
movq -0x10(%rbp), %rax
movq $0x0, 0x80(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x78(%rax)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rax
movl %ecx, 0x44(%rax)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
cmpl $0x0, -0x14(%rbp)
jge 0x9701
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x89f0
movl $0x0, -0x4(%rbp)
jmp 0x974e
jmp 0x9703
cmpl $0x0, -0x2c(%rbp)
je 0x971b
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x78(%rax)
jmp 0x9731
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x80(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x48(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)