// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x88c8(%rdi), %r15
movq %r15, %rdi
callq 0x4750
movl 0x298(%r14), %eax
cvtsi2sd %rax, %xmm0
cvtsi2sdl 0x68(%r14), %xmm1
mulsd 0x49ffb(%rip), %xmm1    # 0x9db90
ucomisd %xmm0, %xmm1
jbe 0x53bc5
xorps %xmm0, %xmm0
cvtsi2sdl 0x88a8(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x64(%r14), %xmm1
mulsd 0x49fe1(%rip), %xmm1    # 0x9db98
ucomisd %xmm1, %xmm0
jbe 0x53bc5
movq %rbx, %rdi
callq 0x53aa7
movl 0x64(%r14), %eax
movl 0x68(%r14), %ecx
incl %eax
imull 0x298(%r14), %eax
incl %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x88a8(%rbx)
movq %r15, %rdi
callq 0x4340
cmpq $0x0, 0x88b8(%rbx)
je 0x53ca0
movl $0x10, %edi
callq 0x4680
movq %rax, %r15
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x53cbe
movq %rbx, (%r15)
movq %r14, 0x8(%r15)
callq 0x4050
movq %rax, %r14
leaq -0x1b8(%rip), %r12      # 0x53a72
movl $0x0, (%r14)
movq 0x88b8(%rbx), %rdi
movq 0x88c0(%rbx), %rsi
movl $0x1, %r13d
movq %r12, %rdx
movq %r15, %rcx
movl $0x1, %r8d
callq 0x380d0
movl (%r14), %ebp
movq %rbx, %rdi
callq 0x53ccd
testl %eax, %eax
jne 0x53c91
movl $0x2, %r13d
cmpl $0xb, %ebp
jne 0x53c91
movq $0x0, 0x8(%rsp)
movq $0xf4240, 0x10(%rsp)    # imm = 0xF4240
xorl %r13d, %r13d
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x4100
testl %r13d, %r13d
je 0x53c2a
cmpl $0x2, %r13d
jne 0x53cb9
xorl %eax, %eax
jmp 0x53cbe
movq %rbx, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x538d7
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq