// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jle 0x766c4
movq -0x18(%rbp), %rax
cmpq $0x0, 0x88(%rax)
jne 0x766c4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76876
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b490
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x76030
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x766f5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76876
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b490
subq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x6f400
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x7672e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76876
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b490
movq %rax, -0x38(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x5c(%rcx), %eax
jge 0x7686f
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
subq -0x28(%rbp), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x6f400
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x767a1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76876
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x40(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x28(%rcx), %eax
jge 0x767f1
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x6f400
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x767e4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76876
jmp 0x767e6
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x767a8
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b490
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
subq -0x28(%rbp), %rax
subq -0x30(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8988(%rax)
je 0x7685f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x8988(%rax), %rcx
movq -0x28(%rbp), %r8
movq -0x48(%rbp), %r9
movq -0x50(%rbp), %rax
movq %rax, (%rsp)
callq 0x6b850
cmpl $0x0, %eax
jge 0x7685d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76876
jmp 0x7685f
jmp 0x76861
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x76745
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop