// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/hts.c
// Function: hts_idx_finish
int hts_idx_finish(hts_idx_t *idx, uint64_t final_offset)
{
    int i, ret = 0;
    if (idx == NULL || idx->z.finished) return 0; // do not run this function on an empty index or multiple times
    if (idx->z.save_tid >= 0) {
        ret |= insert_to_b(idx->bidx[idx->z.save_tid], idx->z.save_bin, idx->z.save_off, final_offset);
        ret |= insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx), idx->z.off_beg, final_offset);
        ret |= 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));
        ret |= compress_binning(idx, i);
    }
    idx->z.finished = 1;

    return ret;
}

// Assembly:
xorl %eax, %eax
testq %rdi, %rdi
je 0x1665f
movq %rdi, %r8
cmpl $0x0, 0x60(%rdi)
je 0x16660
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movslq 0x5c(%r8), %rax
testq %rax, %rax
movq %r8, 0x8(%rsp)
js 0x16724
movq %rsi, %r14
movq 0x28(%r8), %rcx
movq (%rcx,%rax,8), %rdi
movq 0x8(%rsp), %rax
movl 0x4c(%rax), %esi
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rdx
movq %r14, %rcx
callq 0x16c11
movl %eax, %ebp
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rsp), %rcx
movslq 0x5c(%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 %r14, %rcx
callq 0x16c11
movl %eax, %r14d
orl %ebp, %r14d
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rsp), %rcx
movslq 0x5c(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x8(%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
movq 0x8(%rsp), %rax
movq 0x88(%rax), %rdx
movq 0x8(%rsp), %rax
movq 0x90(%rax), %rcx
callq 0x16c11
movq 0x8(%rsp), %r8
orl %r14d, %eax
jmp 0x16726
xorl %eax, %eax
movl %eax, 0x2c(%rsp)
cmpl $0x0, 0x14(%r8)
jle 0x16bf6
xorl %esi, %esi
xorl %edx, %edx
cmpl $0x0, (%r8)
sete %dl
movq %r8, %rdi
movq %rsi, %rbx
callq 0x16d0c
movq 0x8(%rsp), %r8
movq 0x28(%r8), %rax
movq %rbx, 0x40(%rsp)
movq (%rax,%rbx,8), %r11
movl $0x0, %eax
testq %r11, %r11
je 0x16bdd
movl 0x8(%r8), %esi
testl %esi, %esi
movq %r11, 0x10(%rsp)
jle 0x16a72
leal (%rsi,%rsi,2), %ecx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
shll %cl, %r9d
cmpl $0x0, (%r11)
je 0x16a64
notl %r9d
movl $0x92492493, %eax       # imm = 0x92492493
imulq %rax, %r9
shrq $0x22, %r9
xorl %r14d, %r14d
movq %rsi, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq 0x10(%r11), %rax
movl %r14d, %ebx
leal (%r14,%r14), %r15d
andl $0x1e, %r15d
movl $0x3, %r12d
movl %r15d, %ecx
shll %cl, %r12d
shrl $0x4, %ebx
movl $0x7, %r13d
testl %r12d, (%rax,%rbx,4)
je 0x167f5
cmpl $0x7, %r13d
je 0x167e8
testl %r13d, %r13d
jne 0x16a5b
incl %r14d
cmpl (%r11), %r14d
jne 0x167af
jmp 0x16a58
movq 0x18(%r11), %rax
movl %r14d, %ebp
movl (%rax,%rbp,4), %eax
cmpl 0xc(%r8), %eax
jae 0x167d9
cmpl %r9d, %eax
jb 0x167d9
leaq (,%rbp,2), %r13
addq %rbp, %r13
shlq $0x3, %r13
addq 0x20(%r11), %r13
cmpl 0x8(%r8), %esi
jge 0x1684a
movslq 0x4(%r13), %rdi
cmpq $0x2, %rdi
jl 0x1684a
movq 0x10(%r13), %rsi
callq 0x1ca00
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %r11
movq 0x8(%rsp), %r8
movq 0x10(%r13), %rax
movslq 0x4(%r13), %r10
movq %r10, %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 0x16a50
movl (%r11), %eax
testl %eax, %eax
je 0x16916
movq %r10, 0x30(%rsp)
movq %r13, 0x38(%rsp)
movq 0x18(%r11), %rsi
movl (%rsi,%rbp,4), %edi
decl %edi
shrl $0x3, %edi
leal -0x1(%rax), %r8d
movl %r8d, %r9d
andl %edi, %r9d
movq 0x10(%r11), %r10
movl $0x1, %r11d
movl %r9d, %edx
movl %edx, %ecx
shrl $0x4, %ecx
movl (%r10,%rcx,4), %ebp
leal (%rdx,%rdx), %ecx
andl $0x1e, %ecx
movl %ebp, %r13d
shrl %cl, %r13d
testb $0x2, %r13b
jne 0x168ed
testb $0x1, %r13b
jne 0x168db
movl %edx, %r13d
cmpl %edi, (%rsi,%r13,4)
je 0x168ed
addl %r11d, %edx
andl %r8d, %edx
incl %r11d
cmpl %r9d, %edx
jne 0x168b1
movl %eax, %edx
jmp 0x168f6
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %eax, %edx
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r11
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r9
movq 0x38(%rsp), %r13
movq 0x30(%rsp), %r10
jmp 0x16918
xorl %edx, %edx
cmpl %eax, %edx
jne 0x16929
movl $0x7, %r13d
xorl %eax, %eax
jmp 0x16a48
movq 0x20(%r11), %rax
movl %edx, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rbp
addl 0x4(%rbp), %r10d
cmpl (%rbp), %r10d
jle 0x169be
testl %r10d, %r10d
movq %r13, 0x38(%rsp)
je 0x1697d
leal -0x1(%r10), %eax
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
negl %r10d
shrl $0x1f, %r10d
addl %ecx, %r10d
jmp 0x16980
xorl %r10d, %r10d
movl $0x1, %r13d
testl %r10d, %r10d
js 0x16a29
movq 0x10(%rbp), %rdi
movl %r10d, %esi
shlq $0x4, %rsi
movq %r10, 0x30(%rsp)
callq 0x4840
testq %rax, %rax
je 0x16a32
movq 0x30(%rsp), %rcx
movl %ecx, (%rbp)
movq %rax, 0x10(%rbp)
movq 0x38(%rsp), %r13
movslq 0x4(%rbp), %rdi
shlq $0x4, %rdi
addq 0x10(%rbp), %rdi
movq 0x10(%r13), %rsi
movslq 0x4(%r13), %rdx
shlq $0x4, %rdx
callq 0x43c0
movl 0x4(%r13), %eax
addl %eax, 0x4(%rbp)
movq 0x10(%r13), %rdi
callq 0x45c0
movq 0x10(%rsp), %r11
xorl %r13d, %r13d
movb $0x1, %al
cmpl %r14d, (%r11)
jne 0x16a01
movq 0x8(%rsp), %r8
jmp 0x16a3e
movq 0x10(%r11), %rcx
movl (%rcx,%rbx,4), %edx
testl %r12d, %edx
movq 0x8(%rsp), %r8
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r9
jne 0x16a48
btsl %r15d, %edx
movl %edx, (%rcx,%rbx,4)
decl 0x4(%r11)
jmp 0x16a48
xorl %eax, %eax
movq 0x10(%rsp), %r11
jmp 0x16a48
xorl %eax, %eax
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r11
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r9
testb %al, %al
je 0x167d9
xorl %r13d, %r13d
jmp 0x167d9
xorl %r13d, %r13d
testl %r13d, %r13d
jne 0x16bd8
leal -0x1(%rsi), %eax
cmpl $0x2, %esi
movl %eax, %esi
jge 0x1677c
movl (%r11), %eax
testl %eax, %eax
je 0x16adb
leal -0x1(%rax), %esi
movq 0x10(%r11), %rdi
xorl %edx, %edx
movl $0x1, %r8d
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 0x16aca
testb $0x1, %r10b
jne 0x16abc
movq 0x18(%r11), %r10
movl %edx, %r11d
cmpl $0x0, (%r10,%r11,4)
movq 0x10(%rsp), %r11
je 0x16aca
addl %r8d, %edx
incl %r8d
andl %esi, %edx
jne 0x16a88
movl %eax, %edx
jmp 0x16ad4
shrl %cl, %r9d
testb $0x3, %r9b
cmovnel %eax, %edx
movq 0x8(%rsp), %r8
jmp 0x16add
xorl %edx, %edx
cmpl %eax, %edx
je 0x16b04
movq 0x20(%r11), %rax
movl %edx, %ecx
leaq (%rcx,%rcx,2), %rcx
movslq 0x4(%rax,%rcx,8), %rdi
movq 0x10(%rax,%rcx,8), %rsi
callq 0x1ca00
movq 0x10(%rsp), %r11
movq 0x8(%rsp), %r8
cmpl $0x0, (%r11)
je 0x16bd4
xorl %eax, %eax
movq 0x10(%r11), %rcx
movl %eax, %edx
shrl $0x4, %edx
movl (%rcx,%rdx,4), %edx
leal (%rax,%rax), %ecx
shrl %cl, %edx
testb $0x3, %dl
jne 0x16bc9
movq 0x18(%r11), %rdx
movl %eax, %ecx
movl (%rdx,%rcx,4), %edx
cmpl 0xc(%r8), %edx
jae 0x16bc9
movq 0x20(%r11), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rcx
movl $0x1, %edx
cmpl $0x2, 0x4(%rcx)
jl 0x16bc6
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 0x16b96
leaq (%r8,%rdi), %r10
incl %edx
movups (%r10), %xmm0
movups %xmm0, 0x10(%r9,%r8)
jmp 0x16baa
movq 0x8(%r8,%rdi), %r11
cmpq %r11, %r10
jae 0x16baa
addq %r9, %r8
addq $0x8, %r8
movq %r11, (%r8)
incq %rsi
movslq 0x4(%rcx), %r8
addq $0x10, %rdi
cmpq %r8, %rsi
jl 0x16b60
incl %edx
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r11
movl %edx, 0x4(%rcx)
incl %eax
cmpl (%r11), %eax
jne 0x16b10
xorl %eax, %eax
jmp 0x16bdd
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
orl %eax, 0x2c(%rsp)
movq 0x40(%rsp), %rsi
incq %rsi
movslq 0x14(%r8), %rax
cmpq %rax, %rsi
jl 0x16737
movl $0x1, 0x60(%r8)
movl 0x2c(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq