// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/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 (55 + c->num_landmarks * 5 >= 1024)
	buf = malloc(55 + c->num_landmarks * 5);
    cp = buf;

    if (CRAM_MAJOR_VERS(fd->version) == 1) {
	cp += itf8_put(cp, c->length);
    } else {
	*(int32_t *)cp = le_int4(c->length);
	cp += 4;
    }
    if (c->multi_seq) {
	cp += itf8_put(cp, -2);
	cp += itf8_put(cp, 0);
	cp += itf8_put(cp, 0);
    } else {
	cp += itf8_put(cp, c->ref_seq_id);
	cp += itf8_put(cp, c->ref_seq_start);
	cp += itf8_put(cp, c->ref_seq_span);
    }
    cp += itf8_put(cp, c->num_records);
    if (CRAM_MAJOR_VERS(fd->version) == 2) {
	cp += itf8_put(cp, c->record_counter);
	cp += ltf8_put(cp, c->num_bases);
    } else if (CRAM_MAJOR_VERS(fd->version) >= 3) {
	cp += ltf8_put(cp, c->record_counter);
	cp += ltf8_put(cp, c->num_bases);
    }

    cp += itf8_put(cp, c->num_blocks);
    cp += itf8_put(cp, c->num_landmarks);
    for (i = 0; i < c->num_landmarks; i++)
	cp += itf8_put(cp, 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 %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rsi, %r15
movq %rdi, %r14
movl 0x28(%rsi), %eax
cmpl $0xc2, %eax
jl 0x2b8e5
leaq (%rax,%rax,4), %rdi
addq $0x37, %rdi
callq 0x46f0
movq %rax, %rbx
jmp 0x2b8e8
movq %rsp, %rbx
movl $0xffffff00, %ecx       # imm = 0xFFFFFF00
andl 0xc(%r14), %ecx
movl (%r15), %eax
pushq $0x4
popq %rbp
cmpl $0x100, %ecx            # imm = 0x100
jne 0x2b90a
cmpl $0x7f, %eax
ja 0x2b90e
movb %al, (%rbx)
pushq $0x1
jmp 0x2b985
movl %eax, (%rbx)
jmp 0x2b986
movl %eax, %ecx
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x2b926
shrl $0x8, %ecx
orb $-0x80, %cl
movb %cl, (%rbx)
movb %al, 0x1(%rbx)
pushq $0x2
jmp 0x2b985
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x2b93f
shrl $0x10, %ecx
orb $-0x40, %cl
movb %cl, (%rbx)
movb %ah, 0x1(%rbx)
movb %al, 0x2(%rbx)
pushq $0x3
jmp 0x2b985
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x2b95e
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 0x2b986
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)
pushq $0x5
popq %rbp
addq %rbx, %rbp
cmpl $0x0, 0x94(%r15)
je 0x2b9aa
orl $-0x1, (%rbp)
movw $0xe, 0x4(%rbp)
movb $0x0, 0x6(%rbp)
addq $0x7, %rbp
jmp 0x2bb95
movl 0x4(%r15), %eax
cmpl $0x7f, %eax
ja 0x2b9bd
movb %al, (%rbp)
pushq $0x1
jmp 0x2ba47
movl %eax, %ecx
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x2b9d6
shrl $0x8, %ecx
orb $-0x80, %cl
movb %cl, (%rbp)
movb %al, 0x1(%rbp)
pushq $0x2
jmp 0x2ba47
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x2b9f4
shrl $0x10, %ecx
orb $-0x40, %cl
movb %cl, (%rbp)
movb %ah, 0x1(%rbp)
movb 0x4(%r15), %al
movb %al, 0x2(%rbp)
pushq $0x3
jmp 0x2ba47
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x2ba1b
shrl $0x18, %ecx
orb $-0x20, %cl
movb %cl, (%rbp)
shrl $0x10, %eax
movb %al, 0x1(%rbp)
movzwl 0x4(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rbp)
pushq $0x4
jmp 0x2ba47
shrl $0x1c, %ecx
orb $-0x10, %cl
movb %cl, (%rbp)
shrl $0x14, %eax
movb %al, 0x1(%rbp)
movl 0x4(%r15), %eax
movl %eax, %ecx
shrl $0xc, %ecx
movb %cl, 0x2(%rbp)
shrl $0x4, %eax
movb %al, 0x3(%rbp)
movb 0x4(%r15), %al
andb $0xf, %al
movb %al, 0x4(%rbp)
pushq $0x5
popq %rax
addq %rax, %rbp
movl 0x8(%r15), %eax
cmpl $0x7f, %eax
ja 0x2ba5e
movb %al, (%rbp)
pushq $0x1
jmp 0x2baec
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x2ba78
shrl $0x8, %eax
orb $-0x80, %al
movb %al, (%rbp)
movb 0x8(%r15), %al
movb %al, 0x1(%rbp)
pushq $0x2
jmp 0x2baec
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x2ba98
shrl $0x10, %eax
orb $-0x40, %al
movb %al, (%rbp)
movzwl 0x8(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x1(%rbp)
pushq $0x3
jmp 0x2baec
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x2babf
shrl $0x18, %eax
orb $-0x20, %al
movb %al, (%rbp)
movzwl 0x9(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x1(%rbp)
movb 0x8(%r15), %al
movb %al, 0x3(%rbp)
pushq $0x4
jmp 0x2baec
shrl $0x1c, %eax
orb $-0x10, %al
movb %al, (%rbp)
movl 0x8(%r15), %eax
movl %eax, %ecx
shrl $0x14, %ecx
movb %cl, 0x1(%rbp)
shrl $0xc, %eax
movb %al, 0x2(%rbp)
movl 0x8(%r15), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movb %cl, 0x3(%rbp)
andb $0xf, %al
movb %al, 0x4(%rbp)
pushq $0x5
popq %rax
addq %rax, %rbp
movl 0xc(%r15), %eax
cmpl $0x7f, %eax
ja 0x2bb03
movb %al, (%rbp)
pushq $0x1
jmp 0x2bb91
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x2bb1d
shrl $0x8, %eax
orb $-0x80, %al
movb %al, (%rbp)
movb 0xc(%r15), %al
movb %al, 0x1(%rbp)
pushq $0x2
jmp 0x2bb91
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x2bb3d
shrl $0x10, %eax
orb $-0x40, %al
movb %al, (%rbp)
movzwl 0xc(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x1(%rbp)
pushq $0x3
jmp 0x2bb91
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x2bb64
shrl $0x18, %eax
orb $-0x20, %al
movb %al, (%rbp)
movzwl 0xd(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x1(%rbp)
movb 0xc(%r15), %al
movb %al, 0x3(%rbp)
pushq $0x4
jmp 0x2bb91
shrl $0x1c, %eax
orb $-0x10, %al
movb %al, (%rbp)
movl 0xc(%r15), %eax
movl %eax, %ecx
shrl $0x14, %ecx
movb %cl, 0x1(%rbp)
shrl $0xc, %eax
movb %al, 0x2(%rbp)
movl 0xc(%r15), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movb %cl, 0x3(%rbp)
andb $0xf, %al
movb %al, 0x4(%rbp)
pushq $0x5
popq %rax
addq %rax, %rbp
movl 0x20(%r15), %ecx
cmpl $0x7f, %ecx
ja 0x2bba9
movb %cl, (%rbp)
pushq $0x1
popq %rax
jmp 0x2bc4b
cmpl $0x3fff, %ecx           # imm = 0x3FFF
ja 0x2bbc9
pushq $0x2
popq %rax
shrl $0x8, %ecx
orb $-0x80, %cl
movb %cl, (%rbp)
movb 0x20(%r15), %cl
movb %cl, 0x1(%rbp)
jmp 0x2bc4b
cmpl $0x1fffff, %ecx         # imm = 0x1FFFFF
ja 0x2bbed
pushq $0x3
popq %rax
shrl $0x10, %ecx
orb $-0x40, %cl
movb %cl, (%rbp)
movb 0x21(%r15), %cl
movb %cl, 0x1(%rbp)
movb 0x20(%r15), %cl
movb %cl, 0x2(%rbp)
jmp 0x2bc4b
cmpl $0xfffffff, %ecx        # imm = 0xFFFFFFF
ja 0x2bc17
shrl $0x18, %ecx
orb $-0x20, %cl
movb %cl, (%rbp)
movb 0x22(%r15), %al
movb %al, 0x1(%rbp)
movb 0x21(%r15), %al
movb %al, 0x2(%rbp)
movb 0x20(%r15), %al
movb %al, 0x3(%rbp)
pushq $0x4
jmp 0x2bba3
pushq $0x5
popq %rax
shrl $0x1c, %ecx
orb $-0x10, %cl
movb %cl, (%rbp)
movl 0x20(%r15), %ecx
shrl $0x14, %ecx
movb %cl, 0x1(%rbp)
movl 0x20(%r15), %ecx
shrl $0xc, %ecx
movb %cl, 0x2(%rbp)
movl 0x20(%r15), %ecx
shrl $0x4, %ecx
movb %cl, 0x3(%rbp)
movb 0x20(%r15), %cl
andb $0xf, %cl
movb %cl, 0x4(%rbp)
addq %rax, %rbp
movl 0xc(%r14), %eax
sarl $0x8, %eax
cmpl $0x2, %eax
jne 0x2bc6e
movq 0x10(%r15), %rax
cmpq $0x7f, %rax
ja 0x2bc87
movb %al, (%rbp)
pushq $0x1
jmp 0x2bd1e
jle 0x2bd33
movq 0x10(%r15), %rsi
movq %rbp, %rdi
callq 0x2697e
movl %eax, %eax
jmp 0x2bd1f
cmpq $0x3fff, %rax           # imm = 0x3FFF
ja 0x2bca2
shrl $0x8, %eax
orb $-0x80, %al
movb %al, (%rbp)
movb 0x10(%r15), %al
movb %al, 0x1(%rbp)
pushq $0x2
jmp 0x2bd1e
cmpq $0x1fffff, %rax         # imm = 0x1FFFFF
ja 0x2bcc4
shrl $0x10, %eax
orb $-0x40, %al
movb %al, (%rbp)
movb 0x11(%r15), %al
movb %al, 0x1(%rbp)
movb 0x10(%r15), %al
movb %al, 0x2(%rbp)
pushq $0x3
jmp 0x2bd1e
cmpq $0xfffffff, %rax        # imm = 0xFFFFFFF
ja 0x2bced
shrl $0x18, %eax
orb $-0x20, %al
movb %al, (%rbp)
movb 0x12(%r15), %al
movb %al, 0x1(%rbp)
movb 0x11(%r15), %al
movb %al, 0x2(%rbp)
movb 0x10(%r15), %al
movb %al, 0x3(%rbp)
pushq $0x4
jmp 0x2bd1e
shrl $0x1c, %eax
orb $-0x10, %al
movb %al, (%rbp)
movl 0x10(%r15), %eax
shrl $0x14, %eax
movb %al, 0x1(%rbp)
movl 0x10(%r15), %eax
shrl $0xc, %eax
movb %al, 0x2(%rbp)
movl 0x10(%r15), %eax
shrl $0x4, %eax
movb %al, 0x3(%rbp)
movb 0x10(%r15), %al
andb $0xf, %al
movb %al, 0x4(%rbp)
pushq $0x5
popq %rax
addq %rax, %rbp
movq 0x18(%r15), %rsi
movq %rbp, %rdi
callq 0x2697e
movl %eax, %eax
addq %rax, %rbp
movl 0x24(%r15), %eax
cmpl $0x7f, %eax
ja 0x2bd46
movb %al, (%rbp)
pushq $0x1
jmp 0x2bdda
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x2bd60
shrl $0x8, %eax
orb $-0x80, %al
movb %al, (%rbp)
movb 0x24(%r15), %al
movb %al, 0x1(%rbp)
pushq $0x2
jmp 0x2bdda
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x2bd81
shrl $0x10, %eax
orb $-0x40, %al
movb %al, (%rbp)
movb 0x25(%r15), %al
movb %al, 0x1(%rbp)
movb 0x24(%r15), %al
movb %al, 0x2(%rbp)
pushq $0x3
jmp 0x2bdda
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x2bda9
shrl $0x18, %eax
orb $-0x20, %al
movb %al, (%rbp)
movb 0x26(%r15), %al
movb %al, 0x1(%rbp)
movb 0x25(%r15), %al
movb %al, 0x2(%rbp)
movb 0x24(%r15), %al
movb %al, 0x3(%rbp)
pushq $0x4
jmp 0x2bdda
shrl $0x1c, %eax
orb $-0x10, %al
movb %al, (%rbp)
movl 0x24(%r15), %eax
shrl $0x14, %eax
movb %al, 0x1(%rbp)
movl 0x24(%r15), %eax
shrl $0xc, %eax
movb %al, 0x2(%rbp)
movl 0x24(%r15), %eax
shrl $0x4, %eax
movb %al, 0x3(%rbp)
movb 0x24(%r15), %al
andb $0xf, %al
movb %al, 0x4(%rbp)
pushq $0x5
popq %rax
addq %rax, %rbp
movl 0x28(%r15), %eax
cmpl $0x7f, %eax
ja 0x2bdf1
movb %al, (%rbp)
pushq $0x1
jmp 0x2be85
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x2be0b
shrl $0x8, %eax
orb $-0x80, %al
movb %al, (%rbp)
movb 0x28(%r15), %al
movb %al, 0x1(%rbp)
pushq $0x2
jmp 0x2be85
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x2be2c
shrl $0x10, %eax
orb $-0x40, %al
movb %al, (%rbp)
movb 0x29(%r15), %al
movb %al, 0x1(%rbp)
movb 0x28(%r15), %al
movb %al, 0x2(%rbp)
pushq $0x3
jmp 0x2be85
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x2be54
shrl $0x18, %eax
orb $-0x20, %al
movb %al, (%rbp)
movb 0x2a(%r15), %al
movb %al, 0x1(%rbp)
movb 0x29(%r15), %al
movb %al, 0x2(%rbp)
movb 0x28(%r15), %al
movb %al, 0x3(%rbp)
pushq $0x4
jmp 0x2be85
shrl $0x1c, %eax
orb $-0x10, %al
movb %al, (%rbp)
movl 0x28(%r15), %eax
shrl $0x14, %eax
movb %al, 0x1(%rbp)
movl 0x28(%r15), %eax
shrl $0xc, %eax
movb %al, 0x2(%rbp)
movl 0x28(%r15), %eax
shrl $0x4, %eax
movb %al, 0x3(%rbp)
movb 0x28(%r15), %al
andb $0xf, %al
movb %al, 0x4(%rbp)
pushq $0x5
popq %rcx
pushq $0x1
popq %rax
addq %rcx, %rbp
xorl %ecx, %ecx
pushq $0x2
popq %rdx
pushq $0x3
popq %rsi
pushq $0x4
popq %rdi
pushq $0x5
popq %r8
movslq 0x28(%r15), %r9
cmpq %r9, %rcx
jge 0x2bfbb
movq 0x30(%r15), %r9
movl (%r9,%rcx,4), %r9d
cmpl $0x7f, %r9d
ja 0x2bec2
movb %r9b, (%rbp)
movq %rax, %r9
jmp 0x2bfb0
cmpl $0x3fff, %r9d           # imm = 0x3FFF
ja 0x2beeb
shrl $0x8, %r9d
orb $-0x80, %r9b
movb %r9b, (%rbp)
movq 0x30(%r15), %r9
movb (%r9,%rcx,4), %r9b
movb %r9b, 0x1(%rbp)
movq %rdx, %r9
jmp 0x2bfb0
cmpl $0x1fffff, %r9d         # imm = 0x1FFFFF
ja 0x2bf21
shrl $0x10, %r9d
orb $-0x40, %r9b
movb %r9b, (%rbp)
movq 0x30(%r15), %r9
movb 0x1(%r9,%rcx,4), %r9b
movb %r9b, 0x1(%rbp)
movq 0x30(%r15), %r9
movb (%r9,%rcx,4), %r9b
movb %r9b, 0x2(%rbp)
movq %rsi, %r9
jmp 0x2bfb0
cmpl $0xfffffff, %r9d        # imm = 0xFFFFFFF
ja 0x2bf61
shrl $0x18, %r9d
orb $-0x20, %r9b
movb %r9b, (%rbp)
movq 0x30(%r15), %r9
movb 0x2(%r9,%rcx,4), %r9b
movb %r9b, 0x1(%rbp)
movq 0x30(%r15), %r9
movb 0x1(%r9,%rcx,4), %r9b
movb %r9b, 0x2(%rbp)
movq 0x30(%r15), %r9
movb (%r9,%rcx,4), %r9b
movb %r9b, 0x3(%rbp)
movq %rdi, %r9
jmp 0x2bfb0
shrl $0x1c, %r9d
orb $-0x10, %r9b
movb %r9b, (%rbp)
movq 0x30(%r15), %r9
movl (%r9,%rcx,4), %r9d
shrl $0x14, %r9d
movb %r9b, 0x1(%rbp)
movq 0x30(%r15), %r9
movl (%r9,%rcx,4), %r9d
shrl $0xc, %r9d
movb %r9b, 0x2(%rbp)
movq 0x30(%r15), %r9
movl (%r9,%rcx,4), %r9d
shrl $0x4, %r9d
movb %r9b, 0x3(%rbp)
movq 0x30(%r15), %r9
movb (%r9,%rcx,4), %r9b
andb $0xf, %r9b
movb %r9b, 0x4(%rbp)
movq %r8, %r9
addq %r9, %rbp
incq %rcx
jmp 0x2be9b
cmpl $0x2ff, 0xc(%r14)       # imm = 0x2FF
jle 0x2bfff
movl %ebp, %edx
subl %ebx, %edx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x43b0
movl %eax, 0x248(%r15)
movb %al, (%rbp)
movb 0x249(%r15), %al
movb %al, 0x1(%rbp)
movb 0x24a(%r15), %al
movb %al, 0x2(%rbp)
movb 0x24b(%r15), %al
movb %al, 0x3(%rbp)
addq $0x4, %rbp
subq %rbx, %rbp
movq (%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2691f
movq %rax, %r14
movq %rsp, %rax
cmpq %rax, %rbx
je 0x2c023
movq %rbx, %rdi
callq 0x4600
xorl %eax, %eax
cmpq %r14, %rbp
setne %al
negl %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r14
popq %r15
popq %rbp
retq