// File: /workspace/github_c_makefile_star2_O2/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 0x13275
movq %rdi, %r8
cmpl $0x0, 0x60(%rdi)
je 0x13276
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movslq 0x5c(%r8), %rax
testq %rax, %rax
movq %r8, (%rsp)
js 0x13326
movq %rsi, %r14
movq 0x28(%r8), %rcx
movq (%rcx,%rax,8), %rdi
movl 0x4c(%r8), %esi
movq 0x70(%r8), %rdx
movq %r14, %rcx
callq 0x1364a
movl %eax, %ebp
movq (%rsp), %rax
movq 0x28(%rax), %rax
movq (%rsp), %rcx
movslq 0x5c(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq (%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
movq (%rsp), %rax
movq 0x78(%rax), %rdx
movq %r14, %rcx
callq 0x1364a
movl %eax, %r14d
orl %ebp, %r14d
movq (%rsp), %rax
movq 0x28(%rax), %rax
movq (%rsp), %rcx
movslq 0x5c(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq (%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
movq (%rsp), %rax
movq 0x88(%rax), %rdx
movq (%rsp), %rax
movq 0x90(%rax), %rcx
callq 0x1364a
movq (%rsp), %r8
orl %r14d, %eax
jmp 0x13328
xorl %eax, %eax
xorl %ebx, %ebx
movslq 0x14(%r8), %rcx
cmpq %rcx, %rbx
jge 0x13633
movl %eax, 0xc(%rsp)
xorl %edx, %edx
cmpl $0x0, (%r8)
sete %dl
movq %r8, %rdi
movl %ebx, %esi
callq 0x13723
movq (%rsp), %r8
movq 0x28(%r8), %rax
movq %rbx, 0x20(%rsp)
movq (%rax,%rbx,8), %r15
testq %r15, %r15
je 0x1352b
movl 0x8(%r8), %esi
testl %esi, %esi
jle 0x13532
leal (%rsi,%rsi,2), %ecx
pushq $-0x1
popq %rax
shll %cl, %eax
notl %eax
xorl %ebx, %ebx
xorl %edx, %edx
pushq $0x7
popq %rcx
divl %ecx
movl %eax, 0x1c(%rsp)
xorl %r13d, %r13d
movq %rsi, 0x10(%rsp)
cmpl (%r15), %r13d
je 0x13524
movq 0x10(%r15), %rax
movl %r13d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
movl %ebx, %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
je 0x133bc
incl %r13d
addl $0x2, %ebx
jmp 0x13393
movq 0x18(%r15), %rax
movl %r13d, %r14d
movl (%rax,%r14,4), %eax
cmpl 0xc(%r8), %eax
jae 0x133b4
cmpl 0x1c(%rsp), %eax
jb 0x133b4
imulq $0x18, %r14, %r12
addq 0x20(%r15), %r12
cmpl 0x8(%r8), %esi
jge 0x133ff
movslq 0x4(%r12), %rdi
cmpq $0x2, %rdi
jl 0x133ff
movq 0x10(%r12), %rsi
callq 0x184ed
movq 0x10(%rsp), %rsi
movq (%rsp), %r8
movq 0x10(%r12), %rbp
movslq 0x4(%r12), %rdx
movq %rdx, %rax
shlq $0x4, %rax
movq -0x8(%rbp,%rax), %rax
shrq $0x10, %rax
movq (%rbp), %rcx
shrq $0x10, %rcx
subq %rcx, %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x133b4
movq 0x18(%r15), %rax
movl (%rax,%r14,4), %esi
decl %esi
shrl $0x3, %esi
movq %r15, %rdi
movq %rdx, %r14
callq 0x14465
movq 0x10(%rsp), %rsi
movq (%rsp), %r8
cmpl (%r15), %eax
je 0x133b4
movq %r14, %rdx
movq 0x20(%r15), %rdi
movl %eax, %eax
imulq $0x18, %rax, %rsi
leaq (%rdi,%rsi), %r14
movl 0x4(%rdi,%rsi), %ecx
leal (%rcx,%rdx), %eax
cmpl (%rdi,%rsi), %eax
jle 0x134ad
testl %eax, %eax
je 0x134b3
leal -0x1(%rax), %ecx
movl %ecx, %edx
shrl %edx
orl %ecx, %edx
movl %edx, %ecx
shrl $0x2, %ecx
orl %edx, %ecx
movl %ecx, %edx
shrl $0x4, %edx
orl %ecx, %edx
movl %edx, %ecx
shrl $0x8, %ecx
orl %edx, %ecx
movl %ecx, %edx
shrl $0x10, %edx
orl %ecx, %edx
xorl %ebp, %ebp
testl %eax, %eax
setg %bpl
addl %edx, %ebp
jns 0x134b5
jmp 0x1361d
movq 0x10(%r14), %rax
jmp 0x134e2
xorl %ebp, %ebp
movq 0x10(%r14), %rdi
movl %ebp, %esi
shlq $0x4, %rsi
callq 0x4840
testq %rax, %rax
je 0x13614
movl %ebp, (%r14)
movq %rax, 0x10(%r14)
movl 0x4(%r14), %ecx
movq 0x10(%r12), %rbp
movslq 0x4(%r12), %rdx
movslq %ecx, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
shlq $0x4, %rdx
movq %rbp, %rsi
callq 0x43c0
movl 0x4(%r12), %eax
addl %eax, 0x4(%r14)
movq 0x10(%r12), %rdi
callq 0x45c0
movq %r15, %rdi
movl %r13d, %esi
callq 0x181f9
movq (%rsp), %r8
movq 0x10(%rsp), %rsi
jmp 0x133b4
decl %esi
jmp 0x1336c
xorl %ebp, %ebp
jmp 0x13620
movq %r15, %rdi
xorl %esi, %esi
callq 0x14465
cmpl (%r15), %eax
je 0x1355a
movq 0x20(%r15), %rcx
movl %eax, %eax
imulq $0x18, %rax, %rax
movslq 0x4(%rcx,%rax), %rdi
movq 0x10(%rcx,%rax), %rsi
callq 0x184ed
xorl %ebp, %ebp
xorl %edx, %edx
movq (%rsp), %r8
pushq $0x1
popq %rax
cmpl (%r15), %edx
je 0x13620
movq 0x10(%r15), %rcx
movl %edx, %esi
shrl $0x4, %esi
movl (%rcx,%rsi,4), %esi
leal (%rdx,%rdx), %ecx
shrl %cl, %esi
testb $0x3, %sil
jne 0x1360d
movq 0x18(%r15), %rsi
movl %edx, %ecx
movl (%rsi,%rcx,4), %esi
cmpl 0xc(%r8), %esi
jae 0x1360d
imulq $0x18, %rcx, %rcx
addq 0x20(%r15), %rcx
xorl %esi, %esi
pushq $0x10
popq %rdi
movq %rax, %r8
movslq 0x4(%rcx), %r9
cmpq %r9, %r8
jge 0x13604
movq 0x10(%rcx), %r9
movslq %esi, %r10
shlq $0x4, %r10
movq 0x8(%r9,%r10), %r11
movq %r11, %rbx
shrq $0x10, %rbx
movq (%r9,%rdi), %r14
shrq $0x10, %r14
cmpq %r14, %rbx
jae 0x135e7
leaq (%r9,%rdi), %r11
incl %esi
movups (%r11), %xmm0
movups %xmm0, 0x10(%r10,%r9)
jmp 0x135fb
movq 0x8(%r9,%rdi), %rbx
cmpq %rbx, %r11
jae 0x135fb
addq %r10, %r9
addq $0x8, %r9
movq %rbx, (%r9)
incq %r8
addq $0x10, %rdi
jmp 0x135a8
incl %esi
movl %esi, 0x4(%rcx)
movq (%rsp), %r8
incl %edx
jmp 0x13565
pushq $-0x1
popq %rbp
movq (%rsp), %r8
jmp 0x13620
pushq $-0x1
popq %rbp
movl 0xc(%rsp), %eax
orl %ebp, %eax
movq 0x20(%rsp), %rbx
incq %rbx
jmp 0x1332a
movl $0x1, 0x60(%r8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq