// File: karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: cram_write_block
int cram_write_block(cram_fd *fd, cram_block *b) {
    assert(b->method != RAW || (b->comp_size == b->uncomp_size));

    if (hputc(b->method,       fd->fp)  == EOF) return -1;
    if (hputc(b->content_type, fd->fp)  == EOF) return -1;
    if (itf8_encode(fd, b->content_id)  ==  -1) return -1;
    if (itf8_encode(fd, b->comp_size)   ==  -1) return -1;
    if (itf8_encode(fd, b->uncomp_size) ==  -1) return -1;

    if (b->method == RAW) {
	if (b->uncomp_size != hwrite(fd->fp, b->data, b->uncomp_size))
	    return -1;
    } else {
	if (b->comp_size != hwrite(fd->fp, b->data, b->comp_size))
	    return -1;
    }

    if (CRAM_MAJOR_VERS(fd->version) >= 3) {
	unsigned char dat[100], *cp = dat;;
	uint32_t crc;

	*cp++ = b->method;
	*cp++ = b->content_type;
	cp += itf8_put(cp, b->content_id);
	cp += itf8_put(cp, b->comp_size);
	cp += itf8_put(cp, b->uncomp_size);
	crc = crc32(0L, dat, cp-dat);

	if (b->method == RAW) {
	    b->crc32 = crc32(crc, b->data ? b->data : (uc*)"", b->uncomp_size);
	} else {
	    b->crc32 = crc32(crc, b->data ? b->data : (uc*)"", b->comp_size);
	}

	if (-1 == int32_encode(fd, b->crc32))
	    return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x4669c
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x4669e
jmp 0x466bd
leaq 0x3668c(%rip), %rdi     # 0x7cd31
leaq 0x366ba(%rip), %rsi     # 0x7cd66
movl $0x401, %edx            # imm = 0x401
leaq 0x366bd(%rip), %rcx     # 0x7cd75
callq 0x4360
movq -0x18(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x47060
cmpl $-0x1, %eax
jne 0x466e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4704e
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x47060
cmpl $-0x1, %eax
jne 0x46704
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4704e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x43490
cmpl $-0x1, %eax
jne 0x46725
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4704e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x43490
cmpl $-0x1, %eax
jne 0x46746
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4704e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %esi
callq 0x43490
cmpl $-0x1, %eax
jne 0x46767
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4704e
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x467b8
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rdx
callq 0x43620
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
je 0x467b6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4704e
jmp 0x46800
movq -0x18(%rbp), %rax
movslq 0x10(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x18(%rbp), %rax
movslq 0x10(%rax), %rdx
callq 0x43620
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
je 0x467fe
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4704e
jmp 0x46800
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x3, %eax
jl 0x47047
leaq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x88(%rbp)
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x88(%rbp)
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x4688e
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x46a8d
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x468e1
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movl $0x2, %eax
movl %eax, -0xa8(%rbp)
jmp 0x46a81
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x4694f
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x10, %eax
orl $0xc0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movl $0x3, %eax
movl %eax, -0xac(%rbp)
jmp 0x46a75
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
jne 0x469d8
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x18, %eax
orl $0xe0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x3(%rax)
movl $0x4, %eax
movl %eax, -0xb0(%rbp)
jmp 0x46a69
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x1c, %eax
andl $0xff, %eax
orl $0xf0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x14, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0xc, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x4, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xf, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x4(%rax)
movl $0x5, %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %ecx
movq -0x88(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x46ad8
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x46cd7
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x46b2b
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x8, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movl $0x2, %eax
movl %eax, -0xb8(%rbp)
jmp 0x46ccb
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x46b99
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x10, %eax
orl $0xc0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movl $0x3, %eax
movl %eax, -0xbc(%rbp)
jmp 0x46cbf
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
jne 0x46c22
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x18, %eax
orl $0xe0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x3(%rax)
movl $0x4, %eax
movl %eax, -0xc0(%rbp)
jmp 0x46cb3
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x1c, %eax
andl $0xff, %eax
orl $0xf0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x14, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0xc, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
sarl $0x4, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xf, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x4(%rax)
movl $0x5, %eax
movl %eax, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %ecx
movq -0x88(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x46d22
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x46f21
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x46d75
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x8, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movl $0x2, %eax
movl %eax, -0xc8(%rbp)
jmp 0x46f15
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x46de3
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x10, %eax
orl $0xc0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movl $0x3, %eax
movl %eax, -0xcc(%rbp)
jmp 0x46f09
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
jne 0x46e6c
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x18, %eax
orl $0xe0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x3(%rax)
movl $0x4, %eax
movl %eax, -0xd0(%rbp)
jmp 0x46efd
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x1c, %eax
andl $0xff, %eax
orl $0xf0, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x14, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0xc, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
sarl $0x4, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xf, %eax
movb %al, %cl
movq -0x88(%rbp), %rax
movb %cl, 0x4(%rax)
movl $0x5, %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %ecx
movq -0x88(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rsi
movq -0x88(%rbp), %rax
leaq -0x80(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
xorl %eax, %eax
movl %eax, %edi
callq 0x43d0
movl %eax, -0x8c(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x46fc5
movl -0x8c(%rbp), %eax
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x46f90
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xe0(%rbp)
jmp 0x46fa0
leaq 0x35535(%rip), %rax     # 0x7c4cc
movq %rax, -0xe0(%rbp)
jmp 0x46fa0
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %edx
callq 0x43d0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0x47021
movl -0x8c(%rbp), %eax
movq %rax, -0xe8(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x46fee
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xf0(%rbp)
jmp 0x46ffe
leaq 0x354d7(%rip), %rax     # 0x7c4cc
movq %rax, -0xf0(%rbp)
jmp 0x46ffe
movq -0xe8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x43d0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x455e0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x47045
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4704e
jmp 0x47047
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopw (%rax,%rax)