// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_io.c
// Function: cram_free_container
void cram_free_container(cram_container *c) {
    enum cram_DS_ID id;
    int i;

    if (!c)
        return;

    if (c->refs_used)
        free(c->refs_used);

    if (c->landmark)
        free(c->landmark);

    if (c->comp_hdr)
        cram_free_compression_header(c->comp_hdr);

    if (c->comp_hdr_block)
        cram_free_block(c->comp_hdr_block);

    // Free the slices; filled out by encoder only
    if (c->slices) {
        for (i = 0; i < c->max_slice; i++) {
            if (c->slices[i])
                cram_free_slice(c->slices[i]);
            if (c->slices[i] == c->slice)
                c->slice = NULL;
        }
        free(c->slices);
    }

    // Free the current slice; set by both encoder & decoder
    if (c->slice) {
        cram_free_slice(c->slice);
        c->slice = NULL;
    }

    for (id = DS_RN; id < DS_TN; id++)
        if (c->stats[id]) cram_stats_free(c->stats[id]);

    //if (c->aux_B_stats) cram_stats_free(c->aux_B_stats);

    if (c->tags_used) {
        khint_t k;

        for (k = kh_begin(c->tags_used); k != kh_end(c->tags_used); k++) {
            if (!kh_exist(c->tags_used, k))
                continue;

            cram_tag_map *tm = (cram_tag_map *)kh_val(c->tags_used, k);
            if (tm) {
                cram_codec *c = tm->codec;

                if (c) c->free(c);

                // If tm->blk or tm->blk2 is set, then we haven't yet got to
                // cram_encode_container which copies the blocks to s->aux_block
                // and NULLifies tm->blk*.  In this case we failed to complete
                // the container construction, so we have to free up our partially
                // converted CRAM.
                cram_free_block(tm->blk);
                cram_free_block(tm->blk2);
                free(tm);
            }
        }

        kh_destroy(m_tagmap, c->tags_used);
    }

    if (c->ref_free)
        free(c->ref);

    if (c->bams)
        free_bam_list(c->bams, c->max_c_rec);

    free(c);
}

// Assembly:
testq %rdi, %rdi
je 0x4ffeb
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x278(%rdi), %rdi
testq %rdi, %rdi
je 0x4fe53
callq 0x45c0
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x4fe61
callq 0x45c0
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x4fe6f
callq 0x4ffec
movq 0x50(%rbx), %rdi
testq %rdi, %rdi
je 0x4fe7d
callq 0x4ceb6
movq 0x88(%rbx), %rdi
testq %rdi, %rdi
je 0x4fed7
cmpl $0x0, 0x58(%rbx)
jle 0x4fed2
xorl %r14d, %r14d
movq (%rdi,%r14,8), %rax
testq %rax, %rax
je 0x4feb0
movq %rax, %rdi
callq 0x50127
movq 0x88(%rbx), %rdi
movq (%rdi,%r14,8), %rax
jmp 0x4feb2
xorl %eax, %eax
cmpq 0x90(%rbx), %rax
jne 0x4fec6
movq $0x0, 0x90(%rbx)
incq %r14
movslq 0x58(%rbx), %rax
cmpq %rax, %r14
jl 0x4fe92
callq 0x45c0
movq 0x90(%rbx), %rdi
testq %rdi, %rdi
je 0x4fef3
callq 0x50127
movq $0x0, 0x90(%rbx)
movl $0x2a, %r14d
movq (%rbx,%r14,8), %rdi
testq %rdi, %rdi
je 0x4ff07
callq 0x5661d
incq %r14
cmpq $0x46, %r14
jne 0x4fef9
movq 0x270(%rbx), %r14
testq %r14, %r14
je 0x4ffb2
movl (%r14), %eax
testl %eax, %eax
je 0x4ff8f
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x10(%r14), %rcx
movl %r12d, %edx
shrl $0x4, %edx
movl (%rcx,%rdx,4), %edx
movl %ebp, %ecx
andb $0x1e, %cl
shrl %cl, %edx
testb $0x3, %dl
jne 0x4ff84
movq 0x20(%r14), %rcx
movl %r12d, %edx
movq (%rcx,%rdx,8), %r15
testq %r15, %r15
je 0x4ff84
movq (%r15), %rdi
testq %rdi, %rdi
je 0x4ff60
callq *0x20(%rdi)
movq 0x8(%r15), %rdi
callq 0x4ceb6
movq 0x10(%r15), %rdi
callq 0x4ceb6
movq %r15, %rdi
callq 0x45c0
movq 0x270(%rbx), %r14
movl (%r14), %eax
incl %r12d
addl $0x2, %ebp
cmpl %eax, %r12d
jne 0x4ff2c
movq 0x18(%r14), %rdi
callq 0x45c0
movq 0x10(%r14), %rdi
callq 0x45c0
movq 0x20(%r14), %rdi
callq 0x45c0
movq %r14, %rdi
callq 0x45c0
cmpl $0x0, 0x29c(%rbx)
je 0x4ffc7
movq 0xe0(%rbx), %rdi
callq 0x45c0
movq 0xf0(%rbx), %rdi
testq %rdi, %rdi
je 0x4ffdb
movl 0x6c(%rbx), %esi
callq 0x502fe
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x45c0
retq