// File: /workspace/github_c_makefile_star2_O1/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 0x4f683
movq %rdi, %r8
cmpl $0x0, 0x54(%rdi)
je 0x4f684
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, (%rsp)
js 0x4f872
movq %rsi, %r14
movq 0x28(%r8), %rcx
movq (%rcx,%rax,8), %r15
movl 0x44(%r8), %esi
movq 0x60(%r8), %rbx
leaq 0x3c(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x51f24
movl %eax, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x20(%r15), %r13
cmpl $0x0, (%r12)
je 0x4f6f6
movq $0x1, (%r13)
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%r13)
movl (%r13), %eax
cmpl %eax, 0x4(%r13)
jne 0x4f71a
addl %eax, %eax
movl %eax, (%r13)
movq 0x10(%r13), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x10(%r13)
movq 0x10(%r13), %rax
movslq 0x4(%r13), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq %rbx, (%rax,%rcx)
movl %edx, 0x4(%r13)
movq %r14, 0x8(%rax,%rcx)
movq (%rsp), %rdx
movq 0x28(%rdx), %rax
movslq 0x50(%rdx), %rcx
movq (%rax,%rcx,8), %r15
movl 0xc(%rdx), %esi
incl %esi
movq 0x68(%rdx), %rbx
leaq 0x40(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x51f24
movl %eax, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x20(%r15), %r13
cmpl $0x0, (%r12)
je 0x4f78f
movq $0x1, (%r13)
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%r13)
movl (%r13), %eax
cmpl %eax, 0x4(%r13)
jne 0x4f7b3
addl %eax, %eax
movl %eax, (%r13)
movq 0x10(%r13), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x10(%r13)
movq 0x10(%r13), %rax
movslq 0x4(%r13), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq %rbx, (%rax,%rcx)
movl %edx, 0x4(%r13)
movq %r14, 0x8(%rax,%rcx)
movq (%rsp), %rdx
movq 0x28(%rdx), %rax
movslq 0x50(%rdx), %rcx
movq (%rax,%rcx,8), %r14
movl 0xc(%rdx), %esi
incl %esi
movq 0x78(%rdx), %r12
movq 0x80(%rdx), %rbx
leaq 0x44(%rsp), %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x51f24
movl %eax, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x20(%r14), %r13
cmpl $0x0, (%r15)
je 0x4f82e
movq $0x1, (%r13)
movl $0x1, %edi
movl $0x10, %esi
callq 0x6470
movq %rax, 0x10(%r13)
movl (%r13), %eax
cmpl %eax, 0x4(%r13)
jne 0x4f852
addl %eax, %eax
movl %eax, (%r13)
movq 0x10(%r13), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x6c80
movq %rax, 0x10(%r13)
movq 0x10(%r13), %rax
movslq 0x4(%r13), %rcx
leal 0x1(%rcx), %edx
shlq $0x4, %rcx
movq %r12, (%rax,%rcx)
movl %edx, 0x4(%r13)
movq %rbx, 0x8(%rax,%rcx)
movq (%rsp), %r8
cmpl $0x0, 0x14(%r8)
jle 0x4fc9b
xorl %r14d, %r14d
xorl %edx, %edx
cmpl $0x0, (%r8)
sete %dl
movq %r8, %rdi
movl %r14d, %esi
callq 0x4fcb2
movq (%rsp), %r8
movq 0x28(%r8), %rax
movq (%rax,%r14,8), %rdx
testq %rdx, %rdx
je 0x4fc8b
movq %r14, 0x20(%rsp)
movl 0x8(%r8), %r9d
testl %r9d, %r9d
movq %rdx, 0x8(%rsp)
jle 0x4fb20
leal (%r9,%r9,2), %ecx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shll %cl, %r10d
cmpl $0x0, (%rdx)
je 0x4fb0f
notl %r10d
movl $0x92492493, %eax       # imm = 0x92492493
imulq %rax, %r10
shrq $0x22, %r10
xorl %r14d, %r14d
movq %r9, 0x18(%rsp)
movq %r10, 0x10(%rsp)
movq 0x10(%rdx), %rax
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl $0x3, %r13d
movl %ebp, %ecx
shll %cl, %r13d
movl %r14d, %ebx
shrl $0x4, %ebx
testl %r13d, (%rax,%rbx,4)
je 0x4f922
incl %r14d
cmpl (%rdx), %r14d
jne 0x4f8f3
jmp 0x4fb0f
movq 0x18(%rdx), %rax
movl %r14d, %r12d
movl (%rax,%r12,4), %eax
cmpl 0xc(%r8), %eax
jae 0x4f915
cmpl %r10d, %eax
jb 0x4f915
leaq (%r12,%r12,2), %r15
shlq $0x3, %r15
addq 0x20(%rdx), %r15
cmpl 0x8(%r8), %r9d
jge 0x4f970
movslq 0x4(%r15), %rdi
cmpq $0x2, %rdi
jl 0x4f970
movq 0x10(%r15), %rsi
callq 0x4f17b
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rdx
movq (%rsp), %r8
movq 0x10(%r15), %rax
movslq 0x4(%r15), %rdi
movq %rdi, %rcx
shlq $0x4, %rcx
movq -0x8(%rax,%rcx), %rcx
shrq $0x10, %rcx
movq (%rax), %rax
shrq $0x10, %rax
subq %rax, %rcx
cmpq $0xffff, %rcx           # imm = 0xFFFF
ja 0x4f915
movl (%rdx), %eax
testl %eax, %eax
je 0x4fa3b
movq %rdi, 0x30(%rsp)
movq 0x18(%rdx), %rdi
movl (%rdi,%r12,4), %r8d
decl %r8d
shrl $0x3, %r8d
movq %rax, 0x28(%rsp)
leal -0x1(%rax), %r9d
movl %r9d, %r10d
andl %r8d, %r10d
movq 0x10(%rdx), %r11
movl $0x1, %r12d
movl %r10d, %esi
movl %esi, %eax
shrl $0x4, %eax
movl (%r11,%rax,4), %eax
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %eax, %edx
shrl %cl, %edx
testb $0x2, %dl
jne 0x4fa15
testb $0x1, %dl
jne 0x4f9fe
movl %esi, %edx
cmpl %r8d, (%rdi,%rdx,4)
je 0x4fa15
addl %r12d, %esi
andl %r9d, %esi
incl %r12d
cmpl %r10d, %esi
jne 0x4f9d9
movq 0x28(%rsp), %rax
movl %eax, %esi
jmp 0x4fa21
shrl %cl, %eax
testb $0x3, %al
movq 0x28(%rsp), %rax
cmovnel %eax, %esi
movq (%rsp), %r8
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x30(%rsp), %rdi
jmp 0x4fa3d
xorl %esi, %esi
cmpl %eax, %esi
je 0x4f915
movq 0x20(%rdx), %rax
movl %esi, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r12
addl 0x4(%r12), %edi
cmpl (%r12), %edi
jle 0x4faa4
decl %edi
movl %edi, %eax
sarl %eax
orl %edi, %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
cltq
movq %rax, %rsi
shlq $0x4, %rsi
incl %eax
movl %eax, (%r12)
movq 0x10(%r12), %rdi
addq $0x10, %rsi
callq 0x6c80
movq %rax, 0x10(%r12)
movslq 0x4(%r12), %rdi
shlq $0x4, %rdi
addq 0x10(%r12), %rdi
movq 0x10(%r15), %rsi
movslq 0x4(%r15), %rdx
shlq $0x4, %rdx
callq 0x6570
movl 0x4(%r15), %eax
addl %eax, 0x4(%r12)
movq 0x10(%r15), %rdi
callq 0x68a0
movq 0x8(%rsp), %rdx
cmpl %r14d, (%rdx)
movq (%rsp), %r8
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %r10
je 0x4f915
movq 0x10(%rdx), %rax
movl (%rax,%rbx,4), %ecx
testl %r13d, %ecx
jne 0x4f915
btsl %ebp, %ecx
movl %ecx, (%rax,%rbx,4)
decl 0x4(%rdx)
jmp 0x4f915
leal -0x1(%r9), %eax
cmpl $0x1, %r9d
movl %eax, %r9d
jg 0x4f8c0
movl (%rdx), %eax
testl %eax, %eax
je 0x4fb8c
leal -0x1(%rax), %esi
movq 0x10(%rdx), %rdi
xorl %edx, %edx
movl $0x1, %r8d
movq 0x20(%rsp), %r14
movl %edx, %ecx
shrl $0x4, %ecx
movl (%rdi,%rcx,4), %r9d
leal (%rdx,%rdx), %ecx
andl $0x1e, %ecx
movl %r9d, %r10d
shrl %cl, %r10d
testb $0x2, %r10b
jne 0x4fb7c
testb $0x1, %r10b
jne 0x4fb6e
movq 0x8(%rsp), %r10
movq 0x18(%r10), %r10
movl %edx, %r11d
cmpl $0x0, (%r10,%r11,4)
je 0x4fb7c
addl %r8d, %edx
incl %r8d
andl %esi, %edx
jne 0x4fb3a
movl %eax, %edx
jmp 0x4fb86
shrl %cl, %r9d
testb $0x3, %r9b
cmovnel %eax, %edx
movq (%rsp), %r8
jmp 0x4fb93
xorl %edx, %edx
movq 0x20(%rsp), %r14
cmpl %eax, %edx
je 0x4fbb9
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movl %edx, %ecx
leaq (%rcx,%rcx,2), %rcx
movslq 0x4(%rax,%rcx,8), %rdi
movq 0x10(%rax,%rcx,8), %rsi
callq 0x4f17b
movq (%rsp), %r8
movq 0x8(%rsp), %rsi
cmpl $0x0, (%rsi)
je 0x4fc8b
xorl %eax, %eax
movq 0x10(%rsi), %rcx
movl %eax, %edx
shrl $0x4, %edx
movl (%rcx,%rdx,4), %edx
leal (%rax,%rax), %ecx
shrl %cl, %edx
testb $0x3, %dl
jne 0x4fc81
movq 0x18(%rsi), %rdx
movl %eax, %ecx
movl (%rdx,%rcx,4), %edx
cmpl 0xc(%r8), %edx
jae 0x4fc81
movq 0x20(%rsi), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rcx
movl $0x1, %edx
cmpl $0x2, 0x4(%rcx)
jl 0x4fc79
xorl %edx, %edx
movl $0x1, %esi
movl $0x10, %edi
movq 0x10(%rcx), %r8
movslq %edx, %r9
shlq $0x4, %r9
movq 0x8(%r8,%r9), %r10
movq %r10, %r11
shrq $0x10, %r11
movq (%r8,%rdi), %rbx
shrq $0x10, %rbx
cmpq %rbx, %r11
jae 0x4fc4f
leaq (%r8,%rdi), %r10
incl %edx
movups (%r10), %xmm0
movups %xmm0, 0x10(%r9,%r8)
jmp 0x4fc63
movq 0x8(%r8,%rdi), %r11
cmpq %r11, %r10
jae 0x4fc63
addq %r9, %r8
addq $0x8, %r8
movq %r11, (%r8)
incq %rsi
movslq 0x4(%rcx), %r8
addq $0x10, %rdi
cmpq %r8, %rsi
jl 0x4fc19
incl %edx
movq (%rsp), %r8
movl %edx, 0x4(%rcx)
movq 0x8(%rsp), %rsi
incl %eax
cmpl (%rsi), %eax
jne 0x4fbc9
incq %r14
movslq 0x14(%r8), %rax
cmpq %rax, %r14
jl 0x4f880
movl $0x1, 0x54(%r8)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq