// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_encode.c
// Function: cram_next_container
static cram_container *cram_next_container(cram_fd *fd, bam_seq_t *b) {
    cram_container *c = fd->ctr;
    int i;

    /* First occurrence */
    if (c->curr_ref == -2)
        c->curr_ref = bam_ref(b);

    if (c->slice)
        cram_update_curr_slice(c, fd->version);

    /* Flush container */
    if (c->curr_slice == c->max_slice ||
        (bam_ref(b) != c->curr_ref && !c->multi_seq)) {
        c->ref_seq_span = fd->last_base - c->ref_seq_start + 1;
        hts_log_info("Flush container %d/%"PRId64"..%"PRId64,
                     c->ref_seq_id, c->ref_seq_start,
                     c->ref_seq_start + c->ref_seq_span -1);

        /* Encode slices */
        if (-1 == cram_flush_container_mt(fd, c))
            return NULL;
        if (!fd->pool) {
            // Move to sep func, as we need cram_flush_container for
            // the closing phase to flush the partial container.
            for (i = 0; i < c->max_slice; i++) {
                cram_free_slice(c->slices[i]);
                c->slices[i] = NULL;
            }

            c->slice = NULL;
            c->curr_slice = 0;

            /* Easy approach for purposes of freeing stats */
            cram_free_container(c);
        }

        c = fd->ctr = cram_new_container(fd->seqs_per_slice,
                                         fd->slices_per_container);
        if (!c)
            return NULL;

        pthread_mutex_lock(&fd->ref_lock);
        c->no_ref = fd->no_ref;
        c->embed_ref = fd->embed_ref;
        c->record_counter = fd->record_counter;
        pthread_mutex_unlock(&fd->ref_lock);
        c->curr_ref = bam_ref(b);
    }

    c->last_pos = c->first_base = c->last_base = bam_pos(b)+1;

    /* New slice */
    c->slice = c->slices[c->curr_slice] =
        cram_new_slice(MAPPED_SLICE, c->max_rec);
    if (!c->slice)
        return NULL;

    if (c->multi_seq) {
        c->slice->hdr->ref_seq_id = -2;
        c->slice->hdr->ref_seq_start = 0;
        c->slice->last_apos = 1;
    } else {
        c->slice->hdr->ref_seq_id = bam_ref(b);
        // wrong for unsorted data, will fix during encoding.
        c->slice->hdr->ref_seq_start = bam_pos(b)+1;
        c->slice->last_apos = bam_pos(b)+1;
    }

    c->curr_rec = 0;
    c->s_num_bases = 0;
    c->n_mapped = 0;

    // QO field: 0 implies original orientation, 1 implies sequence orientation
    // 1 is often preferable for NovaSeq, but impact is slight. ~0.5% diff.
    // Conversely other data sets it's often better than 1% saving for 0.
    // Short of trying both and learning, for now we use use 0 for V4, 1 for V3.
    c->qs_seq_orient = CRAM_MAJOR_VERS(fd->version) >= 4 ? 0 : 1;

    return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $-0x2, 0x78(%rax)
jne 0x62c04
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x62c22
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x62160
movq -0x20(%rbp), %rax
movl 0x5c(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x58(%rcx), %eax
je 0x62c57
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x78(%rcx), %eax
je 0x62df2
movq -0x20(%rbp), %rax
cmpl $0x0, 0xac(%rax)
jne 0x62df2
movq -0x10(%rbp), %rax
movslq 0x4c(%rax), %rcx
movq -0x20(%rbp), %rax
subq 0x8(%rax), %rcx
addq $0x1, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x20(%rbp), %rax
movq 0x8(%rax), %r9
movq -0x20(%rbp), %rax
addq 0x10(%rax), %r9
subq $0x1, %r9
movl $0x4, %edi
leaq 0x91c19(%rip), %rsi     # 0xf48bb
leaq 0x91c26(%rip), %rdx     # 0xf48cf
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x76a00
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x62cd5
movq $0x0, -0x8(%rbp)
jmp 0x62f5c
movq -0x10(%rbp), %rax
cmpq $0x0, 0x88b8(%rax)
jne 0x62d53
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jge 0x62d30
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x74f20
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x24(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x62cea
movq -0x20(%rbp), %rax
movq $0x0, 0x90(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x20(%rbp), %rdi
callq 0x74a70
movq -0x10(%rbp), %rax
movl 0x214(%rax), %edi
movq -0x10(%rbp), %rax
movl 0x21c(%rax), %esi
callq 0x74730
movq -0x10(%rbp), %rcx
movq %rax, 0x38(%rcx)
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x62d8c
movq $0x0, -0x8(%rbp)
jmp 0x62f5c
movq -0x10(%rbp), %rdi
addq $0x88f0, %rdi           # imm = 0x88F0
callq 0x4730
movq -0x10(%rbp), %rax
movl 0x224(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xec(%rax)
movq -0x10(%rbp), %rax
movl 0x220(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xe8(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
addq $0x88f0, %rdi           # imm = 0x88F0
callq 0x4330
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x20(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x20(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x20(%rbp), %rax
movl 0x64(%rax), %esi
movl $0x2, %edi
callq 0x76f40
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rdx
movslq 0x5c(%rdx), %rdx
movq %rcx, (%rax,%rdx,8)
movq -0x20(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x90(%rax)
jne 0x62e6f
movq $0x0, -0x8(%rbp)
jmp 0x62f5c
movq -0x20(%rbp), %rax
cmpl $0x0, 0xac(%rax)
je 0x62ebc
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rax
movq (%rax), %rax
movl $0xfffffffe, 0x4(%rax)  # imm = 0xFFFFFFFE
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rax
movq (%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rax
movq $0x1, 0x20(%rax)
jmp 0x62f0b
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rax
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x68(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x288(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x298(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
sarl $0x8, %edx
movl $0x1, %ecx
xorl %eax, %eax
cmpl $0x4, %edx
cmovgel %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xb4(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)