// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/htslib/hts.c
// Function: hts_idx_finish
void hts_idx_finish(hts_idx_t *idx, uint64_t final_offset)
{
    int i;
    if (idx == NULL || idx->z.finished) return; // do not run this function on an empty index or 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], META_BIN(idx), idx->z.off_beg, final_offset);
        insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx), 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:
testq %rdi, %rdi
je 0x48889
movq %rdi, %r8
cmpl $0x0, 0x54(%rdi)
je 0x4888a
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movslq 0x50(%r8), %rax
testq %rax, %rax
movq %r8, 0x8(%rsp)
js 0x4893e
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 0x48cb0
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 0x48cb0
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 0x48cb0
movq 0x8(%rsp), %r8
xorl %esi, %esi
movslq 0x14(%r8), %rax
cmpq %rax, %rsi
jge 0x48c99
xorl %edx, %edx
cmpl $0x0, (%r8)
sete %dl
movq %r8, %rdi
movq %rsi, %rbx
callq 0x48d5d
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 0x48c8c
movl 0x8(%r8), %r9d
movq %rdx, 0x10(%rsp)
testl %r9d, %r9d
jle 0x48b97
leal (%r9,%r9,2), %ecx
pushq $-0x1
popq %rax
shll %cl, %eax
notl %eax
xorl %ebx, %ebx
xorl %edx, %edx
pushq $0x7
popq %rcx
divl %ecx
movq 0x10(%rsp), %rdx
movl %eax, 0x2c(%rsp)
xorl %ebp, %ebp
movq %r9, 0x18(%rsp)
cmpl (%rdx), %ebp
je 0x48b8f
movq 0x10(%rdx), %rax
movl %ebx, %r12d
andl $0x1e, %r12d
movl %esi, %r13d
movl %r12d, %ecx
shll %cl, %r13d
movl %ebp, %r14d
shrl $0x4, %r14d
testl %r13d, (%rax,%r14,4)
je 0x489e5
incl %ebp
addl $0x2, %ebx
jmp 0x489b5
movq 0x18(%rdx), %rax
movl %ebp, %r15d
movl (%rax,%r15,4), %eax
cmpl 0xc(%r8), %eax
jae 0x489de
cmpl 0x2c(%rsp), %eax
jb 0x489de
imulq $0x18, %r15, %rax
addq 0x20(%rdx), %rax
cmpl 0x8(%r8), %r9d
movq %rax, 0x20(%rsp)
jge 0x48a39
movslq 0x4(%rax), %rdi
cmpq $0x2, %rdi
jl 0x48a39
movq 0x10(%rax), %rsi
callq 0x483c1
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 0x489de
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 0x498fd
movq 0x40(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %rdx
pushq $0x3
popq %rsi
movq 0x8(%rsp), %r8
cmpl (%rdx), %eax
je 0x489de
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 0x48b1d
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
movslq %ecx, %rax
movq %rax, %rsi
shlq $0x4, %rsi
incl %eax
movl %eax, (%r15)
movq 0x10(%r15), %rdi
addq $0x10, %rsi
callq 0x6c80
movq %rax, 0x10(%r15)
movl 0x4(%r15), %ecx
movq 0x20(%rsp), %r15
movq 0x10(%r15), %r10
movslq 0x4(%r15), %r11
jmp 0x48b26
movq 0x10(%r15), %rax
movq 0x20(%rsp), %r15
movslq %ecx, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
shlq $0x4, %r11
movq %r10, %rsi
movq %r11, %rdx
callq 0x6570
movl 0x4(%r15), %eax
movq 0x38(%rsp), %rcx
addl %eax, 0x4(%rcx)
movq 0x10(%r15), %rdi
callq 0x68a0
movq 0x10(%rsp), %rdx
cmpl (%rdx), %ebp
movq 0x8(%rsp), %r8
pushq $0x3
popq %rsi
movq 0x18(%rsp), %r9
je 0x489de
movq 0x10(%rdx), %rax
movl (%rax,%r14,4), %ecx
testl %r13d, %ecx
jne 0x489de
btsl %r12d, %ecx
movl %ecx, (%rax,%r14,4)
decl 0x4(%rdx)
jmp 0x489de
decl %r9d
jmp 0x48988
movq %rdx, %rdi
xorl %esi, %esi
callq 0x498fd
movq 0x10(%rsp), %rcx
cmpl (%rcx), %eax
je 0x48bc8
movq 0x20(%rcx), %rcx
movl %eax, %eax
imulq $0x18, %rax, %rax
movslq 0x4(%rcx,%rax), %rdi
movq 0x10(%rcx,%rax), %rsi
callq 0x483c1
movq 0x10(%rsp), %rcx
xorl %eax, %eax
movq 0x8(%rsp), %r8
cmpl (%rcx), %eax
je 0x48c8c
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 0x48c80
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rdx
movl %eax, %ecx
movl (%rdx,%rcx,4), %edx
cmpl 0xc(%r8), %edx
jae 0x48c80
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 0x48c76
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 0x48c59
leaq (%r8,%rsi), %r10
incl %edx
movups (%r10), %xmm0
movups %xmm0, 0x10(%r9,%r8)
jmp 0x48c6d
movq 0x8(%r8,%rsi), %r11
cmpq %r11, %r10
jae 0x48c6d
addq %r9, %r8
addq $0x8, %r8
movq %r11, (%r8)
incq %rdi
addq $0x10, %rsi
jmp 0x48c1a
incl %edx
movl %edx, 0x4(%rcx)
movq 0x8(%rsp), %r8
incl %eax
movq 0x10(%rsp), %rcx
jmp 0x48bcf
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0x48940
movl $0x1, 0x54(%r8)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq