// File: /workspace/github_c_makefile_star2_O2/DReichLab[P]adna/hts.c
// Function: hts_idx_finish
void hts_idx_finish(hts_idx_t *idx, uint64_t final_offset)
{
	int i;
	if (idx->z.finished) return; // do not run this function multiple times
	if (idx->z.save_tid >= 0) {
		insert_to_b(idx->bidx[idx->z.save_tid], idx->z.save_bin, idx->z.save_off, final_offset);
		insert_to_b(idx->bidx[idx->z.save_tid], idx->n_bins + 1, idx->z.off_beg, final_offset);
		insert_to_b(idx->bidx[idx->z.save_tid], idx->n_bins + 1, idx->z.n_mapped, idx->z.n_unmapped);
	}
	for (i = 0; i < idx->n; ++i) {
		update_loff(idx, i, (idx->fmt == HTS_FMT_CSI));
		compress_binning(idx, i);
	}
	idx->z.finished = 1;
}

// Assembly:
cmpl $0x0, 0x54(%rdi)
je 0x594c
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r8
movslq 0x50(%rdi), %rax
testq %rax, %rax
movq %rdi, 0x8(%rsp)
js 0x5a03
movq %rsi, %r14
movq 0x28(%r8), %rcx
movq (%rcx,%rax,8), %rdi
movq 0x8(%rsp), %rax
movl 0x44(%rax), %esi
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rdx
movq %r14, %rcx
callq 0x5d6b
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rsp), %rcx
movslq 0x50(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
movq 0x8(%rsp), %rax
movq 0x68(%rax), %rdx
movq %r14, %rcx
callq 0x5d6b
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rsp), %rcx
movslq 0x50(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
movq 0x8(%rsp), %rax
movq 0x78(%rax), %rdx
movq 0x8(%rsp), %rax
movq 0x80(%rax), %rcx
callq 0x5d6b
movq 0x8(%rsp), %r8
xorl %esi, %esi
movslq 0x14(%r8), %rax
cmpq %rax, %rsi
jge 0x5d54
xorl %edx, %edx
cmpl $0x0, (%r8)
sete %dl
movq %r8, %rdi
movq %rsi, %rbx
callq 0x5e18
movq 0x8(%rsp), %r8
movq 0x28(%r8), %rax
movq %rbx, 0x30(%rsp)
movq (%rax,%rbx,8), %rdx
testq %rdx, %rdx
pushq $0x3
popq %rsi
je 0x5d47
movl 0x8(%r8), %r9d
movq %rdx, 0x10(%rsp)
testl %r9d, %r9d
jle 0x5c52
leal (%r9,%r9,2), %ecx
pushq $-0x1
popq %rax
shll %cl, %eax
notl %eax
xorl %r14d, %r14d
xorl %edx, %edx
pushq $0x7
popq %rcx
divl %ecx
movq 0x10(%rsp), %rdx
movl %eax, 0x2c(%rsp)
xorl %ebx, %ebx
movq %r9, 0x18(%rsp)
cmpl (%rdx), %ebx
je 0x5c4a
movq 0x10(%rdx), %rax
movl %r14d, %r12d
andl $0x1e, %r12d
movl %esi, %r13d
movl %r12d, %ecx
shll %cl, %r13d
movl %ebx, %ebp
shrl $0x4, %ebp
testl %r13d, (%rax,%rbp,4)
je 0x5aaa
incl %ebx
addl $0x2, %r14d
jmp 0x5a7b
movq 0x18(%rdx), %rax
movl %ebx, %r15d
movl (%rax,%r15,4), %eax
cmpl 0xc(%r8), %eax
jae 0x5aa2
cmpl 0x2c(%rsp), %eax
jb 0x5aa2
imulq $0x18, %r15, %rax
addq 0x20(%rdx), %rax
cmpl 0x8(%r8), %r9d
movq %rax, 0x20(%rsp)
jge 0x5afe
movslq 0x4(%rax), %rdi
cmpq $0x2, %rdi
jl 0x5afe
movq 0x10(%rax), %rsi
callq 0x5506
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %rdx
pushq $0x3
popq %rsi
movq 0x8(%rsp), %r8
movq 0x10(%rax), %r10
movslq 0x4(%rax), %r11
movq %r11, %rax
shlq $0x4, %rax
movq -0x8(%r10,%rax), %rax
shrq $0x10, %rax
movq (%r10), %rcx
shrq $0x10, %rcx
subq %rcx, %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x5aa2
movq 0x18(%rdx), %rax
movl (%rax,%r15,4), %esi
decl %esi
shrl $0x3, %esi
movq %rdx, %rdi
movq %r10, 0x40(%rsp)
movq %r11, %r15
callq 0x7063
movq 0x40(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %rdx
pushq $0x3
popq %rsi
movq 0x8(%rsp), %r8
cmpl (%rdx), %eax
je 0x5aa2
movq %r15, %r11
movq 0x20(%rdx), %rdx
movl %eax, %eax
imulq $0x18, %rax, %rsi
leaq (%rdx,%rsi), %r15
movl 0x4(%rdx,%rsi), %ecx
leal (%rcx,%r11), %eax
cmpl (%rdx,%rsi), %eax
movq %r15, 0x38(%rsp)
jle 0x5bda
decl %eax
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
incl %ecx
movl %ecx, (%r15)
movq 0x10(%r15), %rdi
shll $0x4, %ecx
movslq %ecx, %rsi
callq 0x22f0
movq %rax, 0x10(%r15)
movl 0x4(%r15), %ecx
movq 0x20(%rsp), %r15
movq 0x10(%r15), %r10
movl 0x4(%r15), %r11d
jmp 0x5be3
movq 0x10(%r15), %rax
movq 0x20(%rsp), %r15
movslq %ecx, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
shll $0x4, %r11d
movslq %r11d, %rdx
movq %r10, %rsi
callq 0x2240
movl 0x4(%r15), %eax
movq 0x38(%rsp), %rcx
addl %eax, 0x4(%rcx)
movq 0x10(%r15), %rdi
callq 0x2050
movq 0x10(%rsp), %rdx
cmpl (%rdx), %ebx
movq 0x8(%rsp), %r8
pushq $0x3
popq %rsi
movq 0x18(%rsp), %r9
je 0x5aa2
movq 0x10(%rdx), %rax
movl (%rax,%rbp,4), %ecx
testl %r13d, %ecx
jne 0x5aa2
btsl %r12d, %ecx
movl %ecx, (%rax,%rbp,4)
decl 0x4(%rdx)
jmp 0x5aa2
decl %r9d
jmp 0x5a4d
movq %rdx, %rdi
xorl %esi, %esi
callq 0x7063
movq 0x10(%rsp), %rcx
cmpl (%rcx), %eax
je 0x5c83
movq 0x20(%rcx), %rcx
movl %eax, %eax
imulq $0x18, %rax, %rax
movslq 0x4(%rcx,%rax), %rdi
movq 0x10(%rcx,%rax), %rsi
callq 0x5506
movq 0x10(%rsp), %rcx
xorl %eax, %eax
movq 0x8(%rsp), %r8
cmpl (%rcx), %eax
je 0x5d47
movq 0x10(%rcx), %rcx
movl %eax, %edx
shrl $0x4, %edx
movl (%rcx,%rdx,4), %edx
leal (%rax,%rax), %ecx
shrl %cl, %edx
testb $0x3, %dl
jne 0x5d3b
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rdx
movl %eax, %ecx
movl (%rdx,%rcx,4), %edx
cmpl 0xc(%r8), %edx
jae 0x5d3b
imulq $0x18, %rcx, %rcx
movq 0x10(%rsp), %rdx
addq 0x20(%rdx), %rcx
xorl %edx, %edx
pushq $0x10
popq %rsi
pushq $0x1
popq %rdi
movslq 0x4(%rcx), %r8
cmpq %r8, %rdi
jge 0x5d31
movq 0x10(%rcx), %r8
movslq %edx, %r9
shlq $0x4, %r9
movq 0x8(%r8,%r9), %r10
movq %r10, %r11
shrq $0x10, %r11
movq (%r8,%rsi), %rbx
shrq $0x10, %rbx
cmpq %rbx, %r11
jae 0x5d14
leaq (%r8,%rsi), %r10
incl %edx
movups (%r10), %xmm0
movups %xmm0, 0x10(%r9,%r8)
jmp 0x5d28
movq 0x8(%r8,%rsi), %r11
cmpq %r11, %r10
jae 0x5d28
addq %r9, %r8
addq $0x8, %r8
movq %r11, (%r8)
incq %rdi
addq $0x10, %rsi
jmp 0x5cd5
incl %edx
movl %edx, 0x4(%rcx)
movq 0x8(%rsp), %r8
incl %eax
movq 0x10(%rsp), %rcx
jmp 0x5c8a
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0x5a05
movl $0x1, 0x54(%r8)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq