// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_io.c
// Function: cram_flush_container_mt
int cram_flush_container_mt(cram_fd *fd, cram_container *c) {
    cram_job *j;

    // At the junction of mapped to unmapped data the compression
    // methods may need to change due to very different statistical
    // properties; particularly BA if minhash sorted.
    //
    // However with threading we'll have several in-flight blocks
    // arriving out of order.
    //
    // So we do one trial reset of NThreads to last for NThreads
    // duration to get us over this transition period, followed
    // by another retrial of the usual ntrials & trial span.
    pthread_mutex_lock(&fd->metrics_lock);
    if (c->n_mapped < 0.3*c->curr_rec &&
        fd->last_mapped > 0.7*c->max_rec) {
        reset_metrics(fd);
    }
    fd->last_mapped = c->n_mapped * (c->max_rec+1)/(c->curr_rec+1) ;
    pthread_mutex_unlock(&fd->metrics_lock);

    if (!fd->pool)
        return cram_flush_container(fd, c);

    if (!(j = malloc(sizeof(*j))))
        return -1;
    j->fd = fd;
    j->c = c;

    // Flush the job.  Note our encoder queue may be full, so we
    // either have to keep trying in non-blocking mode (what we do) or
    // use a dedicated separate thread for draining the queue.
    for (;;) {
        errno = 0;
        hts_tpool_dispatch2(fd->pool, fd->rqueue, cram_flush_thread, j, 1);
        int pending = (errno == EAGAIN);
        if (cram_flush_result(fd) != 0)
            return -1;
        if (!pending)
            break;

        hts_usleep(1000);
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
addq $0x88c8, %rdi           # imm = 0x88C8
callq 0x4730
movq -0x18(%rbp), %rax
movl 0x298(%rax), %eax
cvtsi2sd %rax, %xmm1
movq -0x18(%rbp), %rax
cvtsi2sdl 0x68(%rax), %xmm2
movsd 0x7eb20(%rip), %xmm0    # 0xf5560
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x76a7a
movq -0x10(%rbp), %rax
cvtsi2sdl 0x88a8(%rax), %xmm0
movq -0x18(%rbp), %rax
cvtsi2sdl 0x64(%rax), %xmm2
movsd 0x7eb01(%rip), %xmm1    # 0xf5568
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x76a7a
movq -0x10(%rbp), %rdi
callq 0x768f0
movq -0x18(%rbp), %rax
movl 0x298(%rax), %eax
movq -0x18(%rbp), %rcx
movl 0x64(%rcx), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movq -0x18(%rbp), %rcx
movl 0x68(%rcx), %ecx
addl $0x1, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x88a8(%rax)
movq -0x10(%rbp), %rdi
addq $0x88c8, %rdi           # imm = 0x88C8
callq 0x4330
movq -0x10(%rbp), %rax
cmpq $0x0, 0x88b8(%rax)
jne 0x76ade
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x76640
movl %eax, -0x4(%rbp)
jmp 0x76b91
movl $0x10, %edi
callq 0x4650
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x76afe
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76b91
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
callq 0x4050
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x88b8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x88c0(%rax), %rsi
movq -0x20(%rbp), %rcx
leaq -0x2c1(%rip), %rdx      # 0x76880
movl $0x1, %r8d
callq 0x4e540
callq 0x4050
cmpl $0xb, (%rax)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
callq 0x76ba0
cmpl $0x0, %eax
je 0x76b76
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76b91
cmpl $0x0, -0x24(%rbp)
jne 0x76b7e
jmp 0x76b8a
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x76df0
jmp 0x76b15
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)