// File: /workspace/github_c_makefile_star2_O2/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), %ecx
cvtsi2sd %rcx, %xmm0
movl 0x68(%r14), %esi
cvtsi2sd %esi, %xmm1
mulsd 0x3985e(%rip), %xmm1    # 0x7cb88
ucomisd %xmm0, %xmm1
jbe 0x4335f
cvtsi2sdl 0x88a8(%rbx), %xmm0
cvtsi2sdl 0x64(%r14), %xmm1
mulsd 0x3984a(%rip), %xmm1    # 0x7cb90
ucomisd %xmm1, %xmm0
jbe 0x4335f
movq %rbx, %rdi
callq 0x43236
movl 0x298(%r14), %ecx
movl 0x68(%r14), %esi
movl 0x64(%r14), %eax
incl %eax
imull %ecx, %eax
incl %esi
xorl %edx, %edx
divl %esi
movl %eax, 0x88a8(%rbx)
movq %r15, %rdi
callq 0x4340
movq 0x88b8(%rbx), %rbp
testq %rbp, %rbp
je 0x43411
pushq $0x10
popq %rdi
callq 0x4680
movq %rax, %r15
pushq $-0x1
popq %rax
testq %r15, %r15
je 0x43431
movq %rbx, (%r15)
movq %r14, 0x8(%r15)
callq 0x4050
movq %rax, %r14
pushq $0x1
popq %r13
leaq 0x8(%rsp), %r12
andl $0x0, (%r14)
movq 0x88c0(%rbx), %rsi
movq %rbp, %rdi
leaq -0x1cd(%rip), %rdx      # 0x43203
movq %r15, %rcx
movl %r13d, %r8d
callq 0x2ca41
movl (%r14), %ebp
movq %rbx, %rdi
callq 0x43440
testl %eax, %eax
jne 0x4342a
cmpl $0xb, %ebp
jne 0x4342f
andq $0x0, 0x8(%rsp)
movq $0xf4240, 0x10(%rsp)    # imm = 0xF4240
movq %r12, %rdi
xorl %esi, %esi
callq 0x4100
movq 0x88b8(%rbx), %rbp
jmp 0x433bb
movq %rbx, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4307f
pushq $-0x1
popq %rax
jmp 0x43431
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq