// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_io.c
// Function: cram_write_container
int cram_write_container(cram_fd *fd, cram_container *c) {
    char buf_a[1024], *buf = buf_a, *cp;
    int i;

    if (61 + c->num_landmarks * 10 >= 1024) {
        buf = malloc(61 + c->num_landmarks * 10);
        if (!buf)
            return -1;
    }
    cp = buf;

    if (CRAM_MAJOR_VERS(fd->version) == 1) {
        cp += itf8_put(cp, c->length);
    } else if (CRAM_MAJOR_VERS(fd->version) <= 3) {
        *(int32_t *)cp = le_int4(c->length);
        cp += 4;
    } else {
        cp += fd->vv.varint_put32(cp, NULL, c->length);
    }
    if (c->multi_seq) {
        cp += fd->vv.varint_put32(cp, NULL, (uint32_t)-2);
        cp += fd->vv.varint_put32(cp, NULL, 0);
        cp += fd->vv.varint_put32(cp, NULL, 0);
    } else {
        cp += fd->vv.varint_put32s(cp, NULL, c->ref_seq_id);
        if (CRAM_MAJOR_VERS(fd->version) >= 4) {
            cp += fd->vv.varint_put64(cp, NULL, c->ref_seq_start);
            cp += fd->vv.varint_put64(cp, NULL, c->ref_seq_span);
        } else {
            cp += fd->vv.varint_put32(cp, NULL, c->ref_seq_start);
            cp += fd->vv.varint_put32(cp, NULL, c->ref_seq_span);
        }
    }
    cp += fd->vv.varint_put32(cp, NULL, c->num_records);
    if (CRAM_MAJOR_VERS(fd->version) >= 3)
        cp += fd->vv.varint_put64(cp, NULL, c->record_counter);
    else
        cp += fd->vv.varint_put32(cp, NULL, c->record_counter);
    cp += fd->vv.varint_put64(cp, NULL, c->num_bases);
    cp += fd->vv.varint_put32(cp, NULL, c->num_blocks);
    cp += fd->vv.varint_put32(cp, NULL, c->num_landmarks);
    for (i = 0; i < c->num_landmarks; i++)
        cp += fd->vv.varint_put32(cp, NULL, c->landmark[i]);

    if (CRAM_MAJOR_VERS(fd->version) >= 3) {
        c->crc32 = crc32(0L, (uc *)buf, cp-buf);
        cp[0] =  c->crc32        & 0xff;
        cp[1] = (c->crc32 >>  8) & 0xff;
        cp[2] = (c->crc32 >> 16) & 0xff;
        cp[3] = (c->crc32 >> 24) & 0xff;
        cp += 4;
    }

    if (cp-buf != hwrite(fd->fp, buf, cp-buf)) {
        if (buf != buf_a)
            free(buf);
        return -1;
    }

    if (buf != buf_a)
        free(buf);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rsi, %r15
movq %rdi, %r14
movl 0x30(%rsi), %eax
cmpl $0x61, %eax
jl 0x53598
leaq (%rax,%rax,4), %rax
leaq 0x3d(,%rax,2), %rdi
callq 0x4680
movq %rax, %rbx
testq %rax, %rax
jne 0x5359b
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x53851
movq %rsp, %rbx
movl 0xc(%r14), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x535b9
movl (%r15), %eax
cmpl $0x7f, %eax
ja 0x535cb
movb %al, (%rbx)
movl $0x1, %r12d
jmp 0x535fd
cmpl $0x3, %eax
jg 0x535eb
movl (%r15), %eax
movl %eax, (%rbx)
movl $0x4, %r12d
jmp 0x535fd
movl %eax, %ecx
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x53865
shrl $0x8, %ecx
orb $-0x80, %cl
movb %cl, (%rbx)
movb %al, 0x1(%rbx)
movl $0x2, %r12d
jmp 0x535fd
movl (%r15), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq *0x89c8(%r14)
movslq %eax, %r12
addq %rbx, %r12
cmpl $0x0, 0xac(%r15)
je 0x5363e
movq %r12, %rdi
xorl %esi, %esi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq *0x89c8(%r14)
movslq %eax, %r13
addq %r12, %r13
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq *0x89c8(%r14)
movslq %eax, %r12
addq %r13, %r12
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
jmp 0x5369e
movl 0x4(%r15), %edx
movq %r12, %rdi
xorl %esi, %esi
callq *0x89d0(%r14)
movslq %eax, %r13
addq %r12, %r13
cmpl $0x400, 0xc(%r14)       # imm = 0x400
movq 0x8(%r15), %rdx
movq %r13, %rdi
jl 0x53686
xorl %esi, %esi
callq *0x89d8(%r14)
movslq %eax, %r12
addq %r13, %r12
movq 0x10(%r15), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq *0x89d8(%r14)
jmp 0x536a5
xorl %esi, %esi
callq *0x89c8(%r14)
movslq %eax, %r12
addq %r13, %r12
movl 0x10(%r15), %edx
movq %r12, %rdi
xorl %esi, %esi
callq *0x89c8(%r14)
movslq %eax, %r13
addq %r12, %r13
movl 0x28(%r15), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r14)
movslq %eax, %r12
addq %r13, %r12
cmpl $0x300, 0xc(%r14)       # imm = 0x300
jl 0x536dd
movq 0x18(%r15), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq *0x89d8(%r14)
jmp 0x536ed
movl 0x18(%r15), %edx
movq %r12, %rdi
xorl %esi, %esi
callq *0x89c8(%r14)
cltq
addq %rax, %r12
movq 0x20(%r15), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq *0x89d8(%r14)
movslq %eax, %r13
addq %r12, %r13
movl 0x2c(%r15), %edx
movq %r13, %rdi
xorl %esi, %esi
callq *0x89c8(%r14)
movslq %eax, %rbp
addq %r13, %rbp
movl 0x30(%r15), %edx
movq %rbp, %rdi
xorl %esi, %esi
callq *0x89c8(%r14)
movslq %eax, %r12
addq %rbp, %r12
cmpl $0x0, 0x30(%r15)
jle 0x53763
xorl %r13d, %r13d
movq 0x38(%r15), %rax
movl (%rax,%r13,4), %edx
movq %r12, %rdi
xorl %esi, %esi
callq *0x89c8(%r14)
cltq
addq %rax, %r12
incq %r13
movslq 0x30(%r15), %rax
cmpq %rax, %r13
jl 0x5373e
cmpl $0x300, 0xc(%r14)       # imm = 0x300
jl 0x537af
movl %r12d, %edx
subl %ebx, %edx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x4320
movl %eax, 0x280(%r15)
movb %al, (%r12)
movb 0x281(%r15), %al
movb %al, 0x1(%r12)
movb 0x282(%r15), %al
movb %al, 0x2(%r12)
movb 0x283(%r15), %al
movb %al, 0x3(%r12)
addq $0x4, %r12
subq %rbx, %r12
movq (%r14), %r14
testb $0x2, 0x30(%r14)
jne 0x537e2
movq 0x18(%r14), %rsi
movq %rsi, %rax
subq 0x8(%r14), %rax
cmpq %r12, %rax
jae 0x537e2
addq %r12, %rsi
subq (%r14), %rsi
movq %r14, %rdi
callq 0xefdd
movq 0x18(%r14), %rax
movq %rax, 0x10(%r14)
movq 0x8(%r14), %rdi
movq 0x18(%r14), %r13
subq %rdi, %r13
cmpq %r12, %r13
ja 0x537f7
cmpq (%r14), %rdi
je 0x53823
cmpq %r12, %r13
movq %r12, %r15
cmovbq %r13, %r15
movq %rbx, %rsi
movq %r15, %rdx
callq 0x43c0
addq %r15, 0x8(%r14)
cmpq %r12, %r13
jae 0x53836
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
jmp 0x5382e
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xf4c6
movq %rax, %r15
xorl %ebp, %ebp
cmpq %r15, %r12
setne %bpl
negl %ebp
movq %rsp, %rax
cmpq %rax, %rbx
je 0x53851
movq %rbx, %rdi
callq 0x45c0
movl %ebp, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x53885
shrl $0x10, %ecx
orb $-0x40, %cl
movb %cl, (%rbx)
movb %ah, 0x1(%rbx)
movb %al, 0x2(%rbx)
movl $0x3, %r12d
jmp 0x535fd
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x538a7
shrl $0x18, %ecx
orb $-0x20, %cl
movb %cl, (%rbx)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x1(%rbx)
movb %ah, 0x2(%rbx)
movb %al, 0x3(%rbx)
jmp 0x535c3
shrl $0x1c, %ecx
orb $-0x10, %cl
movb %cl, (%rbx)
movl %eax, %ecx
shrl $0x14, %ecx
movb %cl, 0x1(%rbx)
movl %eax, %ecx
shrl $0xc, %ecx
movb %cl, 0x2(%rbx)
movl %eax, %ecx
shrl $0x4, %ecx
movb %cl, 0x3(%rbx)
andb $0xf, %al
movb %al, 0x4(%rbx)
movl $0x5, %r12d
jmp 0x535fd