// File: /workspace/github_c_makefile_star2_O3/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 0x49d40(%rip), %xmm1    # 0x9ad88
ucomisd %xmm0, %xmm1
jbe 0x51083
xorps %xmm0, %xmm0
cvtsi2sdl 0x88a8(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x64(%r14), %xmm1
mulsd 0x49d26(%rip), %xmm1    # 0x9ad90
ucomisd %xmm1, %xmm0
jbe 0x51083
movq %rbx, %rdi
callq 0x50f58
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), %r12
testq %r12, %r12
je 0x5117d
movl $0x10, %edi
callq 0x4680
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x51199
movq %rax, %r15
movq %rbx, (%rax)
movq %r14, 0x8(%rax)
callq 0x4050
movq %rax, %r14
movl $0x0, (%rax)
movq 0x88c0(%rbx), %rsi
leaq -0x1cc(%rip), %rdx      # 0x50f23
movq %r12, %rdi
movq %r15, %rcx
movl $0x1, %r8d
callq 0x36ca6
movl (%r14), %ebp
movq %rbx, %rdi
callq 0x511ab
testl %eax, %eax
jne 0x51199
leaq 0x8(%rsp), %r12
leaq -0x1fc(%rip), %r13      # 0x50f23
cmpl $0xb, %ebp
jne 0x51196
movq $0x0, 0x8(%rsp)
movq $0xf4240, 0x10(%rsp)    # imm = 0xF4240
movq %r12, %rdi
xorl %esi, %esi
callq 0x4100
movl $0x0, (%r14)
movq 0x88b8(%rbx), %rdi
movq 0x88c0(%rbx), %rsi
movq %r13, %rdx
movq %r15, %rcx
movl $0x1, %r8d
callq 0x36ca6
movl (%r14), %ebp
movq %rbx, %rdi
callq 0x511ab
testl %eax, %eax
je 0x5111f
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x51199
movq %rbx, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x50da0
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq