// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/bgzf.c
// Function: mt_flush_queue
static int mt_flush_queue(BGZF *fp)
{
    int i;
    mtaux_t *mt = fp->mt;
    // signal all the workers to compress
    pthread_mutex_lock(&mt->lock);
    for (i = 0; i < mt->n_threads; ++i) mt->w[i].toproc = 1;
    mt->proc_cnt = 0;
    pthread_cond_broadcast(&mt->cv);
    pthread_mutex_unlock(&mt->lock);
    // worker 0 is doing things here
    worker_aux(&mt->w[0]);
    // wait for all the threads to complete
    while (mt->proc_cnt < mt->n_threads);
    // dump data to disk
    for (i = 0; i < mt->n_threads; ++i) fp->errcode |= mt->w[i].errcode;
    if (fp->errcode == 0) {
        /* Only try to write if all the threads worked, as otherwise we
           could get a file with holes in it */
        for (i = 0; i < mt->curr; ++i) {
            if (hwrite(fp->fp, mt->blk[i], mt->len[i]) != mt->len[i]) {
                fp->errcode |= BGZF_ERR_IO;
                break;
            }
        }
    }
    mt->curr = 0;
    return (fp->errcode == 0)? 0 : -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r15
movq 0x40(%rdi), %rbp
leaq 0x38(%rbp), %r14
movq %r14, %rdi
callq 0x47a0
movslq (%rbp), %rdx
testq %rdx, %rdx
jle 0x43e72
movq 0x28(%rbp), %rax
leal 0x3(%rdx), %ecx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %ecx
shlq $0x7, %rcx
movdqa 0xe08c(%rip), %xmm1     # 0x51e20
movdqa 0xe094(%rip), %xmm2     # 0x51e30
xorl %edx, %edx
movdqa 0xe09a(%rip), %xmm3     # 0x51e40
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0xe09a(%rip), %xmm5     # 0x51e50
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0x43df3
movl $0x1, 0x18(%rax,%rdx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x43e0a
movl $0x1, 0x38(%rax,%rdx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %esi
testb $0x1, %sil
je 0x43e4a
movl $0x1, 0x58(%rax,%rdx)
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x43e5d
movl $0x1, 0x78(%rax,%rdx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
subq $-0x80, %rdx
cmpq %rdx, %rcx
jne 0x43db6
movl $0x0, 0x10(%rbp)
leaq 0x60(%rbp), %rdi
callq 0x41e0
movq %r14, %rdi
callq 0x43f0
movq 0x28(%rbp), %rdi
callq 0x4528c
movl (%rbp), %ecx
movl 0x10(%rbp), %eax
cmpl %ecx, %eax
jl 0x43e96
movl (%r15), %eax
testl %ecx, %ecx
jle 0x43ec8
movl $0x14, %ecx
xorl %edx, %edx
movq 0x28(%rbp), %rsi
movzwl (%rsi,%rcx), %esi
orl %esi, %eax
movl %eax, (%r15)
incq %rdx
movslq (%rbp), %rsi
addq $0x20, %rcx
cmpq %rsi, %rdx
jl 0x43eab
testw %ax, %ax
je 0x43eeb
movl $0x0, 0x8(%rbp)
xorl %eax, %eax
cmpw (%r15), %ax
sbbl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x8(%rbp)
jle 0x43ecd
movq 0x20(%rbp), %rax
xorl %ebx, %ebx
movq %r15, 0x8(%rsp)
movq 0x38(%r15), %r15
movq 0x18(%rbp), %rcx
movq (%rcx,%rbx,8), %rsi
movslq (%rax,%rbx,4), %r13
movq 0x8(%r15), %rdi
movq 0x18(%r15), %r12
subq %rdi, %r12
cmpq %r13, %r12
movq %r13, %r14
cmovbq %r12, %r14
movq %rsi, 0x10(%rsp)
movq %r14, %rdx
callq 0x4420
addq %r14, 0x8(%r15)
cmpq %r13, %r12
jae 0x43f4d
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x47309
movq %rax, %r14
movq 0x20(%rbp), %rax
movslq (%rax,%rbx,4), %rcx
cmpq %rcx, %r14
movq 0x8(%rsp), %r15
jne 0x43f70
incq %rbx
movslq 0x8(%rbp), %rcx
cmpq %rcx, %rbx
jl 0x43efc
jmp 0x43ecd
orb $0x4, (%r15)
jmp 0x43ecd