// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorl %r15d, %r15d
movq %rdi, 0x8(%rsp)
testq %rdi, %rdi
je 0x166a1
movq 0x8(%rsp), %rax
cmpl $0x0, 0x60(%rax)
jne 0x166a1
movq 0x8(%rsp), %rax
movslq 0x5c(%rax), %rax
testq %rax, %rax
js 0x16178
movq %rsi, %r14
movq 0x8(%rsp), %rdx
movq 0x28(%rdx), %rcx
movq (%rcx,%rax,8), %rdi
movl 0x4c(%rdx), %esi
movq 0x70(%rdx), %rdx
movq %r14, %rcx
callq 0x166b3
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 0x166b3
movl %eax, %r14d
orl %ebp, %r14d
movq 0x8(%rsp), %r8
movq 0x28(%r8), %rax
movslq 0x5c(%r8), %rcx
movq (%rax,%rcx,8), %rdi
movl 0xc(%r8), %esi
incl %esi
movq 0x88(%r8), %rdx
movq 0x90(%r8), %rcx
callq 0x166b3
movl %eax, %r15d
orl %r14d, %r15d
jmp 0x1617b
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
cmpl $0x0, 0x14(%rax)
jle 0x16695
xorl %r12d, %r12d
xorl %edx, %edx
movq 0x8(%rsp), %rbx
cmpl $0x0, (%rbx)
sete %dl
movq %rbx, %rdi
movl %r12d, %esi
callq 0x167b9
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %r8
movl $0x0, %eax
testq %r8, %r8
je 0x1666a
movq %r12, 0x30(%rsp)
movl %r15d, 0x24(%rsp)
movq 0x8(%rsp), %rax
movl 0x8(%rax), %r11d
movl (%r8), %edx
testl %r11d, %r11d
movq %r8, 0x18(%rsp)
movl %edx, 0x14(%rsp)
jle 0x164e7
movl %edx, %eax
movq %rax, 0x28(%rsp)
movl %edx, %edi
movl %edx, %r9d
leal (%r11,%r11,2), %ecx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
xorl %eax, %eax
testl %edx, %edx
jne 0x16214
leal -0x1(%r11), %ecx
movl %eax, %edx
cmpl $0x1, %r11d
movl %ecx, %r11d
jg 0x161ef
jmp 0x164e9
notl %esi
movl $0x92492493, %eax       # imm = 0x92492493
imulq %rax, %rsi
shrq $0x22, %rsi
movq %rsi, 0x50(%rsp)
xorl %r14d, %r14d
movq %r11, 0x38(%rsp)
movq 0x10(%r8), %rax
leal (%r14,%r14), %r15d
andl $0x1e, %r15d
movl $0x3, %r12d
movl %r15d, %ecx
shll %cl, %r12d
movl %r14d, %ebx
shrl $0x4, %ebx
testl %r12d, (%rax,%rbx,4)
je 0x16261
incl %r14d
movl %r9d, %eax
cmpl %r9d, %r14d
jne 0x16230
jmp 0x16200
movq 0x18(%r8), %rax
movl %r14d, %r13d
movl (%rax,%r13,4), %eax
movq 0x8(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x16254
cmpl 0x50(%rsp), %eax
jb 0x16254
leaq (,%r13,2), %rbp
addq %r13, %rbp
shlq $0x3, %rbp
addq 0x20(%r8), %rbp
movq 0x8(%rsp), %rax
cmpl 0x8(%rax), %r11d
jge 0x162c3
movslq 0x4(%rbp), %rdi
cmpq $0x2, %rdi
jl 0x162c3
movq 0x10(%rbp), %rsi
callq 0x1c402
movq 0x38(%rsp), %r11
movq 0x18(%rsp), %r8
movl (%r8), %eax
movl %eax, 0x14(%rsp)
movq %rax, 0x28(%rsp)
movq 0x10(%rbp), %rsi
movslq 0x4(%rbp), %rdi
movq %rdi, %rax
shlq $0x4, %rax
movq -0x8(%rsi,%rax), %rax
shrq $0x10, %rax
movq (%rsi), %rcx
shrq $0x10, %rcx
subq %rcx, %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x1637e
movq %rdi, 0x48(%rsp)
movq 0x28(%rsp), %rax
testl %eax, %eax
movq %rbp, 0x40(%rsp)
je 0x163a8
movq 0x18(%r8), %rdx
movl (%rdx,%r13,4), %r9d
decl %r9d
shrl $0x3, %r9d
leal -0x1(%rax), %r11d
movl %r9d, %r13d
andl %r11d, %r13d
movq 0x10(%r8), %rax
movl $0x1, %r8d
movl %r13d, %r10d
movl %r10d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %edi
leal (%r10,%r10), %ecx
andl $0x1e, %ecx
movl %edi, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x1638d
testb $0x1, %bpl
jne 0x16357
movl %r10d, %ebp
cmpl %r9d, (%rdx,%rbp,4)
je 0x1638d
addl %r8d, %r10d
andl %r11d, %r10d
incl %r8d
cmpl %r13d, %r10d
jne 0x1632e
movq 0x28(%rsp), %rax
movl %eax, %edi
movl %eax, %r9d
movq 0x18(%rsp), %r8
movq 0x38(%rsp), %r11
jmp 0x16254
movq 0x28(%rsp), %rax
movl %eax, %edi
movl %eax, %r9d
jmp 0x16254
shrl %cl, %edi
testb $0x3, %dil
movq 0x28(%rsp), %rax
cmovnel %eax, %r10d
movq 0x18(%rsp), %r8
movq 0x38(%rsp), %r11
jmp 0x163ab
xorl %r10d, %r10d
movl %eax, %edi
movl %eax, %r9d
cmpl %eax, %r10d
je 0x16254
movq 0x20(%r8), %rax
movl %r10d, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r13
movl 0x4(%r13), %ecx
movq 0x48(%rsp), %rdx
leal (%rcx,%rdx), %eax
cmpl (%r13), %eax
jle 0x16414
testl %eax, %eax
je 0x16422
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 0x16424
jmp 0x16684
movq 0x10(%r13), %rax
movq %r13, %rbp
movq 0x40(%rsp), %r13
jmp 0x16458
xorl %ebp, %ebp
movq 0x10(%r13), %rdi
movl %ebp, %esi
shlq $0x4, %rsi
callq 0x4840
testq %rax, %rax
je 0x16684
movl %ebp, (%r13)
movq %rax, 0x10(%r13)
movl 0x4(%r13), %ecx
movq %r13, %rbp
movq 0x40(%rsp), %r13
movq 0x10(%r13), %rsi
movslq 0x4(%r13), %rdx
movslq %ecx, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
shlq $0x4, %rdx
callq 0x43c0
movl 0x4(%r13), %eax
addl %eax, 0x4(%rbp)
movq 0x10(%r13), %rdi
callq 0x45c0
movq 0x18(%rsp), %r8
movl (%r8), %eax
movl %r14d, %ecx
movl %r14d, 0x14(%rsp)
movq %rcx, 0x28(%rsp)
movl %r14d, %edi
movl %r14d, %r9d
cmpl %r14d, %eax
movq 0x38(%rsp), %r11
je 0x16254
movq 0x10(%r8), %rcx
movl (%rcx,%rbx,4), %edx
movl %eax, 0x14(%rsp)
movl %eax, %esi
movq %rsi, 0x28(%rsp)
movl %eax, %edi
movl %eax, %r9d
testl %r12d, %edx
jne 0x16254
btsl %r15d, %edx
movl %edx, (%rcx,%rbx,4)
decl 0x4(%r8)
movl (%r8), %r9d
movl %r9d, %eax
movq %rax, 0x28(%rsp)
movl %r9d, %edi
movl %r9d, 0x14(%rsp)
jmp 0x16254
movl %edx, %edi
testl %edi, %edi
je 0x1655d
leal -0x1(%rdi), %esi
movq 0x10(%r8), %r8
xorl %edx, %edx
movl $0x1, %eax
movl 0x24(%rsp), %r15d
movq 0x30(%rsp), %r12
movl 0x14(%rsp), %ebx
movl %edx, %ecx
shrl $0x4, %ecx
movl (%r8,%rcx,4), %r9d
leal (%rdx,%rdx), %ecx
andl $0x1e, %ecx
movl %r9d, %r10d
shrl %cl, %r10d
testb $0x2, %r10b
jne 0x1654c
testb $0x1, %r10b
jne 0x1653d
movq 0x18(%rsp), %r10
movq 0x18(%r10), %r10
movl %edx, %r11d
cmpl $0x0, (%r10,%r11,4)
je 0x1654c
addl %eax, %edx
incl %eax
andl %esi, %edx
jne 0x16509
movq 0x18(%rsp), %r8
jmp 0x16594
shrl %cl, %r9d
testb $0x3, %r9b
cmovnel %edi, %edx
movq 0x18(%rsp), %r8
jmp 0x1656d
xorl %edx, %edx
movl 0x24(%rsp), %r15d
movq 0x30(%rsp), %r12
movl 0x14(%rsp), %ebx
cmpl %edi, %edx
je 0x16594
movq 0x20(%r8), %rax
movl %edx, %ecx
leaq (%rcx,%rcx,2), %rcx
movslq 0x4(%rax,%rcx,8), %rdi
movq 0x10(%rax,%rcx,8), %rsi
callq 0x1c402
movq 0x18(%rsp), %r8
movl (%r8), %ebx
movl %ebx, %edi
testl %edi, %edi
je 0x16668
xorl %edx, %edx
movq 0x10(%r8), %rax
movl %edx, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
leal (%rdx,%rdx), %ecx
shrl %cl, %eax
testb $0x3, %al
jne 0x1665e
movq 0x18(%r8), %rcx
movl %edx, %eax
movl (%rcx,%rax,4), %ecx
movq 0x8(%rsp), %rsi
cmpl 0xc(%rsi), %ecx
jae 0x1665e
movq 0x20(%r8), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rcx
movl 0x4(%rcx), %edi
movl $0x1, %esi
cmpl $0x2, %edi
jl 0x16659
xorl %esi, %esi
movl $0x1, %eax
movl $0x10, %r8d
movq 0x10(%rcx), %r9
movslq %esi, %r10
shlq $0x4, %r10
movq 0x8(%r9,%r10), %r11
movq %r11, %rbx
shrq $0x10, %rbx
movq (%r9,%r8), %r14
shrq $0x10, %r14
cmpq %r14, %rbx
jae 0x1662c
leaq (%r9,%r8), %rdi
incl %esi
movups (%rdi), %xmm0
movups %xmm0, 0x10(%r10,%r9)
movl 0x4(%rcx), %edi
jmp 0x16640
movq 0x8(%r9,%r8), %rbx
cmpq %rbx, %r11
jae 0x16640
addq %r10, %r9
addq $0x8, %r9
movq %rbx, (%r9)
incq %rax
movslq %edi, %r9
addq $0x10, %r8
cmpq %r9, %rax
jl 0x165f4
movq 0x18(%rsp), %r8
movl (%r8), %ebx
incl %esi
movl %esi, 0x4(%rcx)
movl %ebx, %edi
incl %edx
cmpl %edi, %edx
jne 0x1659e
xorl %eax, %eax
orl %eax, %r15d
incq %r12
movq 0x8(%rsp), %rax
movslq 0x14(%rax), %rax
cmpq %rax, %r12
jl 0x1618d
jmp 0x16695
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl 0x24(%rsp), %r15d
movq 0x30(%rsp), %r12
jmp 0x1666a
movq 0x8(%rsp), %rax
movl $0x1, 0x60(%rax)
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq