// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/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 0x10ead
movq %rdi, %r8
cmpl $0x0, 0x54(%rdi)
je 0x10eae
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movslq 0x50(%r8), %rax
testq %rax, %rax
movq %r8, 0x8(%rsp)
js 0x110db
movq %rsi, %r14
movq 0x28(%r8), %rcx
movq (%rcx,%rax,8), %r15
movl 0x44(%r8), %esi
movq 0x60(%r8), %rbx
leaq 0x5c(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x139ac
movl %eax, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x20(%r15), %r13
cmpl $0x0, (%r12)
je 0x10f29
movq $0x1, (%r13)
leaq 0x4(%r13), %r15
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%r13)
xorl %ecx, %ecx
jmp 0x10f5b
leaq 0x4(%r13), %r15
movl 0x4(%r13), %ecx
cmpl (%r13), %ecx
jne 0x10f57
addl %ecx, %ecx
movl %ecx, (%r13)
movq 0x10(%r13), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%r13)
movl 0x4(%r13), %ecx
jmp 0x10f5b
movq 0x10(%r13), %rax
movq 0x8(%rsp), %rdi
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
movq %rbx, (%rax,%rdx)
incl %ecx
movl %ecx, (%r15)
movq %r14, 0x8(%rax,%rdx)
movq 0x28(%rdi), %rax
movslq 0x50(%rdi), %rcx
movq (%rax,%rcx,8), %r15
movl 0xc(%rdi), %esi
incl %esi
movq 0x68(%rdi), %rbx
leaq 0x60(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x139ac
movl %eax, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x20(%r15), %r13
cmpl $0x0, (%r12)
je 0x10fd5
movq $0x1, (%r13)
leaq 0x4(%r13), %r15
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%r13)
xorl %ecx, %ecx
jmp 0x11007
leaq 0x4(%r13), %r15
movl 0x4(%r13), %ecx
cmpl (%r13), %ecx
jne 0x11003
addl %ecx, %ecx
movl %ecx, (%r13)
movq 0x10(%r13), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%r13)
movl 0x4(%r13), %ecx
jmp 0x11007
movq 0x10(%r13), %rax
movq 0x8(%rsp), %rdi
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
movq %rbx, (%rax,%rdx)
incl %ecx
movl %ecx, (%r15)
movq %r14, 0x8(%rax,%rdx)
movq 0x28(%rdi), %rax
movslq 0x50(%rdi), %rcx
movq (%rax,%rcx,8), %r14
movl 0xc(%rdi), %esi
incl %esi
movups 0x78(%rdi), %xmm0
movaps %xmm0, 0x20(%rsp)
leaq 0x64(%rsp), %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x139ac
movl %eax, %eax
leaq (%rax,%rax,2), %r12
shlq $0x3, %r12
addq 0x20(%r14), %r12
cmpl $0x0, (%r15)
je 0x11087
movq $0x1, (%r12)
leaq 0x4(%r12), %rbx
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%r12)
xorl %ecx, %ecx
jmp 0x110bf
leaq 0x4(%r12), %rbx
movl 0x4(%r12), %ecx
cmpl (%r12), %ecx
jne 0x110ba
addl %ecx, %ecx
movl %ecx, (%r12)
movq 0x10(%r12), %rdi
movslq %ecx, %rsi
shlq $0x4, %rsi
callq 0x48d0
movq %rax, 0x10(%r12)
movl 0x4(%r12), %ecx
jmp 0x110bf
movq 0x10(%r12), %rax
movq 0x8(%rsp), %r8
movaps 0x20(%rsp), %xmm0
movslq %ecx, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
incl %ecx
movl %ecx, (%rbx)
movups %xmm0, (%rax,%rdx)
cmpl $0x0, 0x14(%r8)
jle 0x115bb
xorl %r15d, %r15d
xorl %edx, %edx
cmpl $0x0, (%r8)
sete %dl
movq %r8, %rdi
movl %r15d, %esi
callq 0x115d2
movq 0x8(%rsp), %r8
movq 0x28(%r8), %rax
movq (%rax,%r15,8), %rsi
testq %rsi, %rsi
je 0x115ab
movq %r15, 0x38(%rsp)
movl 0x8(%r8), %r11d
movl (%rsi), %edx
testl %r11d, %r11d
movq %rsi, 0x18(%rsp)
movl %edx, 0x14(%rsp)
jle 0x1141e
movl %edx, %eax
movq %rax, 0x20(%rsp)
movl %edx, %edi
movl %edx, %r9d
leal (%r11,%r11,2), %ecx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shll %cl, %r10d
xorl %eax, %eax
testl %edx, %edx
jne 0x11163
leal -0x1(%r11), %ecx
movl %eax, %edx
cmpl $0x1, %r11d
movl %ecx, %r11d
jg 0x1113c
jmp 0x11420
notl %r10d
movl $0x92492493, %eax       # imm = 0x92492493
imulq %rax, %r10
shrq $0x22, %r10
movq %r10, 0x50(%rsp)
xorl %r14d, %r14d
movq %r11, 0x30(%rsp)
movq 0x10(%rsi), %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 0x111af
incl %r14d
movl %r9d, %eax
cmpl %r9d, %r14d
jne 0x11180
jmp 0x1114f
movq 0x18(%rsi), %rax
movl %r14d, %r12d
movl (%rax,%r12,4), %eax
cmpl 0xc(%r8), %eax
jae 0x111a2
cmpl 0x50(%rsp), %eax
jb 0x111a2
leaq (%r12,%r12,2), %r15
shlq $0x3, %r15
addq 0x20(%rsi), %r15
cmpl 0x8(%r8), %r11d
jge 0x11209
movslq 0x4(%r15), %rdi
cmpq $0x2, %rdi
movq 0x20(%rsp), %rdx
jl 0x1120e
movq 0x10(%r15), %rsi
callq 0x109a4
movq 0x30(%rsp), %r11
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %r8
movl (%rsi), %eax
movl %eax, 0x14(%rsp)
movl %eax, %edx
jmp 0x1120e
movq 0x20(%rsp), %rdx
movq 0x10(%r15), %rdi
movslq 0x4(%r15), %r9
movq %r9, %rax
shlq $0x4, %rax
movq -0x8(%rdi,%rax), %rax
shrq $0x10, %rax
movq (%rdi), %rcx
shrq $0x10, %rcx
subq %rcx, %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
movq %rdx, 0x20(%rsp)
ja 0x112d1
movq %r9, 0x48(%rsp)
testl %edx, %edx
movq %rdi, 0x40(%rsp)
je 0x112fa
movq %rsi, %rax
movq 0x18(%rsi), %rsi
movl (%rsi,%r12,4), %r9d
decl %r9d
shrl $0x3, %r9d
leal -0x1(%rdx), %r11d
movl %r9d, %r12d
andl %r11d, %r12d
movq 0x10(%rax), %rax
movl $0x1, %r8d
movl %r12d, %r10d
movl %r10d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %edx
leal (%r10,%r10), %ecx
andl $0x1e, %ecx
movl %edx, %edi
shrl %cl, %edi
testb $0x2, %dil
jne 0x112db
testb $0x1, %dil
jne 0x112a5
movl %r10d, %edi
cmpl %r9d, (%rsi,%rdi,4)
je 0x112db
addl %r8d, %r10d
andl %r11d, %r10d
incl %r8d
cmpl %r12d, %r10d
jne 0x1127c
movq 0x20(%rsp), %rax
movl %eax, %edi
movl %eax, %r9d
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %r11
jmp 0x111a2
movl %edx, %edi
movl %edx, %r9d
jmp 0x111a2
shrl %cl, %edx
testb $0x3, %dl
movq 0x20(%rsp), %rdx
cmovnel %edx, %r10d
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %r11
jmp 0x112fd
xorl %r10d, %r10d
movl %edx, %edi
movl %edx, %r9d
cmpl %edx, %r10d
je 0x111a2
movq 0x20(%rsi), %rax
movl %r10d, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r12
movl 0x4(%r12), %ecx
movq 0x48(%rsp), %rdx
leal (%rcx,%rdx), %eax
cmpl (%r12), %eax
jle 0x11383
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, (%r12)
movq 0x10(%r12), %rdi
addq $0x10, %rsi
callq 0x48d0
movq %rax, 0x10(%r12)
movl 0x4(%r12), %ecx
movq 0x10(%r15), %rsi
movslq 0x4(%r15), %rdx
jmp 0x1138d
movq 0x10(%r12), %rax
movq 0x40(%rsp), %rsi
movslq %ecx, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
shlq $0x4, %rdx
callq 0x4420
movl 0x4(%r15), %eax
addl %eax, 0x4(%r12)
movq 0x10(%r15), %rdi
callq 0x4610
movq 0x18(%rsp), %rsi
movl (%rsi), %eax
movl %r14d, %ecx
movl %r14d, 0x14(%rsp)
movq %rcx, 0x20(%rsp)
movl %r14d, %edi
movl %r14d, %r9d
cmpl %r14d, %eax
movq 0x8(%rsp), %r8
movq 0x30(%rsp), %r11
je 0x111a2
movq 0x10(%rsi), %rcx
movl (%rcx,%rbx,4), %edx
movl %eax, 0x14(%rsp)
movl %eax, %edi
movq %rdi, 0x20(%rsp)
movl %eax, %r9d
testl %r13d, %edx
jne 0x111a2
btsl %ebp, %edx
movl %edx, (%rcx,%rbx,4)
decl 0x4(%rsi)
movl (%rsi), %r9d
movl %r9d, %eax
movq %rax, 0x20(%rsp)
movl %r9d, %edi
movl %r9d, 0x14(%rsp)
jmp 0x111a2
movl %edx, %edi
testl %edi, %edi
je 0x1149c
movq %rsi, %rax
leal -0x1(%rdi), %esi
movq 0x10(%rax), %r8
xorl %edx, %edx
movl $0x1, %eax
movq 0x38(%rsp), %r15
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 0x11486
testb $0x1, %r10b
jne 0x11472
movq 0x18(%rsp), %r10
movq 0x18(%r10), %r10
movl %edx, %r11d
cmpl $0x0, (%r10,%r11,4)
je 0x11486
addl %eax, %edx
incl %eax
andl %esi, %edx
jne 0x1143e
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rsi
jmp 0x114d2
shrl %cl, %r9d
testb $0x3, %r9b
cmovnel %edi, %edx
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rsi
jmp 0x114a7
xorl %edx, %edx
movq 0x38(%rsp), %r15
movl 0x14(%rsp), %ebx
cmpl %edi, %edx
je 0x114d2
movq 0x20(%rsi), %rax
movl %edx, %ecx
leaq (%rcx,%rcx,2), %rcx
movslq 0x4(%rax,%rcx,8), %rdi
movq 0x10(%rax,%rcx,8), %rsi
callq 0x109a4
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %r8
movl (%rsi), %ebx
movl %ebx, %edi
testl %edi, %edi
je 0x115ab
xorl %edx, %edx
movq 0x10(%rsi), %rax
movl %edx, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
leal (%rdx,%rdx), %ecx
shrl %cl, %eax
testb $0x3, %al
jne 0x115a1
movq 0x18(%rsi), %rcx
movl %edx, %eax
movl (%rcx,%rax,4), %ecx
cmpl 0xc(%r8), %ecx
jae 0x115a1
movq 0x20(%rsi), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rcx
movl 0x4(%rcx), %edi
movl $0x1, %esi
cmpl $0x2, %edi
jl 0x11597
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 0x11566
leaq (%r9,%r8), %rdi
incl %esi
movups (%rdi), %xmm0
movups %xmm0, 0x10(%r10,%r9)
movl 0x4(%rcx), %edi
jmp 0x1157a
movq 0x8(%r9,%r8), %rbx
cmpq %rbx, %r11
jae 0x1157a
addq %r10, %r9
addq $0x8, %r9
movq %rbx, (%r9)
incq %rax
movslq %edi, %r9
addq $0x10, %r8
cmpq %r9, %rax
jl 0x1152e
movq 0x18(%rsp), %rax
movl (%rax), %ebx
incl %esi
movq 0x8(%rsp), %r8
movl %esi, 0x4(%rcx)
movl %ebx, %edi
movq 0x18(%rsp), %rsi
incl %edx
cmpl %edi, %edx
jne 0x114dc
incq %r15
movslq 0x14(%r8), %rax
cmpq %rax, %r15
jl 0x110e9
movl $0x1, 0x54(%r8)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq