// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_io.c
// Function: cram_flush_container2
static int cram_flush_container2(cram_fd *fd, cram_container *c) {
    int i, j;

    if (c->curr_slice > 0 && !c->slices)
        return -1;

    //fprintf(stderr, "Writing container %d, sum %u\n", c->record_counter, sum);

    off_t c_offset = htell(fd->fp); // File offset of container

    /* Write the container struct itself */
    if (0 != cram_write_container(fd, c))
        return -1;

    off_t hdr_size = htell(fd->fp) - c_offset;

    /* And the compression header */
    if (0 != cram_write_block(fd, c->comp_hdr_block))
        return -1;

    /* Followed by the slice blocks */
    off_t file_offset = htell(fd->fp);
    for (i = 0; i < c->curr_slice; i++) {
        cram_slice *s = c->slices[i];
        off_t spos = file_offset - c_offset - hdr_size;

        if (0 != cram_write_block(fd, s->hdr_block))
            return -1;

        for (j = 0; j < s->hdr->num_blocks; j++) {
            if (0 != cram_write_block(fd, s->block[j]))
                return -1;
        }

        file_offset = htell(fd->fp);
        off_t sz = file_offset - c_offset - hdr_size - spos;

        if (fd->idxfp) {
            if (cram_index_slice(fd, c, s, fd->idxfp, c_offset, spos, sz) < 0)
                return -1;
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, 0x5c(%rsi)
jle 0x5392e
cmpq $0x0, 0x88(%rbx)
je 0x53a5c
movq (%r14), %rax
movq 0x28(%rax), %r15
addq 0x8(%rax), %r15
subq (%rax), %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x53556
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x53a61
movq (%r14), %rax
movq (%rax), %r13
movq 0x28(%rax), %r12
addq 0x8(%rax), %r12
movq 0x50(%rbx), %rsi
movq %r14, %rdi
callq 0x4f35f
testl %eax, %eax
jne 0x53a61
cmpl $0x0, 0x5c(%rbx)
jle 0x53a58
movq (%r14), %rax
movq 0x28(%rax), %rcx
addq 0x8(%rax), %rcx
subq %r12, %r13
movq %r13, 0x10(%rsp)
subq (%rax), %rcx
movq %rcx, 0x8(%rsp)
xorl %r13d, %r13d
movq 0x88(%rbx), %rax
movq (%rax,%r13,8), %r12
movq 0x8(%r12), %rsi
movq %r14, %rdi
callq 0x4f35f
testl %eax, %eax
je 0x539c1
xorl %eax, %eax
jmp 0x53a44
movq (%r12), %rax
cmpl $0x0, 0x28(%rax)
jle 0x539f2
xorl %ebp, %ebp
movq 0x10(%r12), %rax
movq (%rax,%rbp,8), %rsi
movq %r14, %rdi
callq 0x4f35f
testl %eax, %eax
jne 0x539ba
incq %rbp
movq (%r12), %rax
movslq 0x28(%rax), %rax
cmpq %rax, %rbp
jl 0x539cd
movq (%r14), %rax
movq 0x28(%rax), %rbp
addq 0x8(%rax), %rbp
subq (%rax), %rbp
movq 0x8988(%r14), %rcx
testq %rcx, %rcx
je 0x53a39
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rdx
leaq (%rax,%rdx), %r9
movq %rbp, %rax
subq %rdx, %rax
movq %rax, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %r8
callq 0x4c9c6
testl %eax, %eax
js 0x53a3d
movb $0x1, %al
jmp 0x53a3f
xorl %eax, %eax
movq %rbp, 0x8(%rsp)
testb %al, %al
je 0x53a5c
incq %r13
movslq 0x5c(%rbx), %rax
cmpq %rax, %r13
jl 0x5399e
xorl %ebp, %ebp
jmp 0x53a61
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq