// File: /workspace/github_cpp_makefile_star2_O1/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 0x10f17
movq %rdi, %r8
cmpl $0x0, 0x54(%rdi)
je 0x10f18
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 0x11106
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 0x138fc
movl %eax, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x20(%r15), %r13
cmpl $0x0, (%r12)
je 0x10f8a
movq $0x1, (%r13)
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%r13)
movl (%r13), %eax
cmpl %eax, 0x4(%r13)
jne 0x10fae
addl %eax, %eax
movl %eax, (%r13)
movq 0x10(%r13), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x48d0
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 0x138fc
movl %eax, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x20(%r15), %r13
cmpl $0x0, (%r12)
je 0x11023
movq $0x1, (%r13)
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%r13)
movl (%r13), %eax
cmpl %eax, 0x4(%r13)
jne 0x11047
addl %eax, %eax
movl %eax, (%r13)
movq 0x10(%r13), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x48d0
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 0x138fc
movl %eax, %eax
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x20(%r14), %r13
cmpl $0x0, (%r15)
je 0x110c2
movq $0x1, (%r13)
movl $0x1, %edi
movl $0x10, %esi
callq 0x4360
movq %rax, 0x10(%r13)
movl (%r13), %eax
cmpl %eax, 0x4(%r13)
jne 0x110e6
addl %eax, %eax
movl %eax, (%r13)
movq 0x10(%r13), %rdi
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x48d0
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 0x1152f
xorl %r14d, %r14d
xorl %edx, %edx
cmpl $0x0, (%r8)
sete %dl
movq %r8, %rdi
movl %r14d, %esi
callq 0x11546
movq (%rsp), %r8
movq 0x28(%r8), %rax
movq (%rax,%r14,8), %rdx
testq %rdx, %rdx
je 0x1151f
movq %r14, 0x20(%rsp)
movl 0x8(%r8), %r9d
testl %r9d, %r9d
movq %rdx, 0x8(%rsp)
jle 0x113b4
leal (%r9,%r9,2), %ecx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shll %cl, %r10d
cmpl $0x0, (%rdx)
je 0x113a3
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 0x111b6
incl %r14d
cmpl (%rdx), %r14d
jne 0x11187
jmp 0x113a3
movq 0x18(%rdx), %rax
movl %r14d, %r12d
movl (%rax,%r12,4), %eax
cmpl 0xc(%r8), %eax
jae 0x111a9
cmpl %r10d, %eax
jb 0x111a9
leaq (%r12,%r12,2), %r15
shlq $0x3, %r15
addq 0x20(%rdx), %r15
cmpl 0x8(%r8), %r9d
jge 0x11204
movslq 0x4(%r15), %rdi
cmpq $0x2, %rdi
jl 0x11204
movq 0x10(%r15), %rsi
callq 0x10a0f
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 0x111a9
movl (%rdx), %eax
testl %eax, %eax
je 0x112cf
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 0x112a9
testb $0x1, %dl
jne 0x11292
movl %esi, %edx
cmpl %r8d, (%rdi,%rdx,4)
je 0x112a9
addl %r12d, %esi
andl %r9d, %esi
incl %r12d
cmpl %r10d, %esi
jne 0x1126d
movq 0x28(%rsp), %rax
movl %eax, %esi
jmp 0x112b5
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 0x112d1
xorl %esi, %esi
cmpl %eax, %esi
je 0x111a9
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 0x11338
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 0x48d0
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 0x4420
movl 0x4(%r15), %eax
addl %eax, 0x4(%r12)
movq 0x10(%r15), %rdi
callq 0x4610
movq 0x8(%rsp), %rdx
cmpl %r14d, (%rdx)
movq (%rsp), %r8
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %r10
je 0x111a9
movq 0x10(%rdx), %rax
movl (%rax,%rbx,4), %ecx
testl %r13d, %ecx
jne 0x111a9
btsl %ebp, %ecx
movl %ecx, (%rax,%rbx,4)
decl 0x4(%rdx)
jmp 0x111a9
leal -0x1(%r9), %eax
cmpl $0x1, %r9d
movl %eax, %r9d
jg 0x11154
movl (%rdx), %eax
testl %eax, %eax
je 0x11420
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 0x11410
testb $0x1, %r10b
jne 0x11402
movq 0x8(%rsp), %r10
movq 0x18(%r10), %r10
movl %edx, %r11d
cmpl $0x0, (%r10,%r11,4)
je 0x11410
addl %r8d, %edx
incl %r8d
andl %esi, %edx
jne 0x113ce
movl %eax, %edx
jmp 0x1141a
shrl %cl, %r9d
testb $0x3, %r9b
cmovnel %eax, %edx
movq (%rsp), %r8
jmp 0x11427
xorl %edx, %edx
movq 0x20(%rsp), %r14
cmpl %eax, %edx
je 0x1144d
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 0x10a0f
movq (%rsp), %r8
movq 0x8(%rsp), %rsi
cmpl $0x0, (%rsi)
je 0x1151f
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 0x11515
movq 0x18(%rsi), %rdx
movl %eax, %ecx
movl (%rdx,%rcx,4), %edx
cmpl 0xc(%r8), %edx
jae 0x11515
movq 0x20(%rsi), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rcx
movl $0x1, %edx
cmpl $0x2, 0x4(%rcx)
jl 0x1150d
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 0x114e3
leaq (%r8,%rdi), %r10
incl %edx
movups (%r10), %xmm0
movups %xmm0, 0x10(%r9,%r8)
jmp 0x114f7
movq 0x8(%r8,%rdi), %r11
cmpq %r11, %r10
jae 0x114f7
addq %r9, %r8
addq $0x8, %r8
movq %r11, (%r8)
incq %rsi
movslq 0x4(%rcx), %r8
addq $0x10, %rdi
cmpq %r8, %rsi
jl 0x114ad
incl %edx
movq (%rsp), %r8
movl %edx, 0x4(%rcx)
movq 0x8(%rsp), %rsi
incl %eax
cmpl (%rsi), %eax
jne 0x1145d
incq %r14
movslq 0x14(%r8), %rax
cmpq %rax, %r14
jl 0x11114
movl $0x1, 0x54(%r8)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq