// File: karel-brinda[P]ococo/ext/htslib/cram/cram_encode.c
// Function: cram_compress_slice
static int cram_compress_slice(cram_fd *fd, cram_slice *s) {
    int level = fd->level, i;
    int method = 1<<GZIP | 1<<GZIP_RLE, methodF = method;

    /* Compress the CORE Block too, with minimal zlib level */
    if (level > 5 && s->block[0]->uncomp_size > 500)
	cram_compress_block(fd, s->block[0], NULL, GZIP, 1);
 
    if (fd->use_bz2)
	method |= 1<<BZIP2;

    if (fd->use_rans)
	method |= (1<<RANS0) | (1<<RANS1);

    if (fd->use_lzma)
	method |= (1<<LZMA);

    /* Faster method for data series we only need entropy encoding on */
    methodF = method & ~(1<<GZIP | 1<<BZIP2 | 1<<LZMA);
    if (level >= 6)
	methodF = method;
    

    /* Specific compression methods for certain block types */
    if (cram_compress_block(fd, s->block[DS_IN], fd->m[DS_IN], //IN (seq)
			    method, level))
	return -1;

    if (fd->level == 0) {
	/* Do nothing */
    } else if (fd->level == 1) {
	if (cram_compress_block(fd, s->block[DS_QS], fd->m[DS_QS],
				methodF, 1))
	    return -1;
	for (i = DS_aux; i <= DS_aux_oz; i++) {
	    if (s->block[i])
		if (cram_compress_block(fd, s->block[i], fd->m[i],
					method, 1))
		    return -1;
	}
    } else if (fd->level < 3) {
	if (cram_compress_block(fd, s->block[DS_QS], fd->m[DS_QS],
				method, 1))
	    return -1;
	if (cram_compress_block(fd, s->block[DS_BA], fd->m[DS_BA],
				method, 1))
	    return -1;
	if (s->block[DS_BB])
	    if (cram_compress_block(fd, s->block[DS_BB], fd->m[DS_BB],
				    method, 1))
	    return -1;
	for (i = DS_aux; i <= DS_aux_oz; i++) {
	    if (s->block[i])
		if (cram_compress_block(fd, s->block[i], fd->m[i],
					method, level))
		    return -1;
	}
    } else {
	if (cram_compress_block(fd, s->block[DS_QS], fd->m[DS_QS],
				method, level))
	    return -1;
	if (cram_compress_block(fd, s->block[DS_BA], fd->m[DS_BA],
				method, level))
	    return -1;
	if (s->block[DS_BB])
	    if (cram_compress_block(fd, s->block[DS_BB], fd->m[DS_BB],
				    method, level))
	    return -1;
	for (i = DS_aux; i <= DS_aux_oz; i++) {
	    if (s->block[i])
		if (cram_compress_block(fd, s->block[i], fd->m[i],
					method, level))
		    return -1;
	}
    }

    // NAME: best is generally xz, bzip2, zlib then rans1
    // It benefits well from a little bit extra compression level.
    if (cram_compress_block(fd, s->block[DS_RN], fd->m[DS_RN],
			    method & ~(1<<RANS0 | 1<<GZIP_RLE),
			    MIN(9,level)))
	return -1;

    // NS shows strong local correlation as rearrangements are localised
    if (s->block[DS_NS] != s->block[0])
	if (cram_compress_block(fd, s->block[DS_NS], fd->m[DS_NS],
				method, level))
	    return -1;


    /*
     * Minimal compression of any block still uncompressed, bar CORE
     */
    {
	int i;
	for (i = 1; i < DS_END; i++) {
	    if (!s->block[i] || s->block[i] == s->block[0])
		continue;

	    // fast methods only
	    if (s->block[i]->method == RAW) {
		cram_compress_block(fd, s->block[i], fd->m[i],
				    methodF, level);
	    }
	}
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x802, -0x24(%rbp)     # imm = 0x802
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x5, -0x1c(%rbp)
jle 0x3bc02
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
cmpl $0x1f4, 0x14(%rax)      # imm = 0x1F4
jle 0x3bc02
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %r8d
movl %r8d, %ecx
callq 0x472d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x214(%rax)
je 0x3bc18
movl -0x24(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x218(%rax)
je 0x3bc30
movl -0x24(%rbp), %eax
orl $0x410, %eax            # imm = 0x410
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x21c(%rax)
je 0x3bc46
movl -0x24(%rbp), %eax
orl $0x8, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
andl $-0xf, %eax
movl %eax, -0x28(%rbp)
cmpl $0x6, -0x1c(%rbp)
jl 0x3bc5b
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x68(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdx
movl -0x24(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bc93
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
movq -0x10(%rbp), %rax
cmpl $0x0, 0x78(%rax)
jne 0x3bca2
jmp 0x3bfe4
movq -0x10(%rbp), %rax
cmpl $0x1, 0x78(%rax)
jne 0x3bd61
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x60(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rdx
movl -0x28(%rbp), %ecx
movl $0x1, %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bcea
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
movl $0x1, -0x20(%rbp)
cmpl $0x9, -0x20(%rbp)
jg 0x3bd5c
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x3bd4f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x80(%rax,%rcx,8), %rdx
movl -0x24(%rbp), %ecx
movl $0x1, %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bd4d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
jmp 0x3bd4f
jmp 0x3bd51
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3bcf1
jmp 0x3bfe2
movq -0x10(%rbp), %rax
cmpl $0x3, 0x78(%rax)
jge 0x3beac
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x60(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rdx
movl -0x24(%rbp), %ecx
movl $0x1, %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bda9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0xf0(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x170(%rax), %rdx
movl -0x24(%rbp), %ecx
movl $0x1, %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bde6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
cmpq $0x0, 0x128(%rax)
je 0x3be37
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x128(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x1a8(%rax), %rdx
movl -0x24(%rbp), %ecx
movl $0x1, %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3be35
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
jmp 0x3be37
movl $0x1, -0x20(%rbp)
cmpl $0x9, -0x20(%rbp)
jg 0x3bea7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x3be9a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x80(%rax,%rcx,8), %rdx
movl -0x24(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3be98
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
jmp 0x3be9a
jmp 0x3be9c
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3be3e
jmp 0x3bfe0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x60(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rdx
movl -0x24(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bee4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0xf0(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x170(%rax), %rdx
movl -0x24(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bf1f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
cmpq $0x0, 0x128(%rax)
je 0x3bf6e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x128(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x1a8(%rax), %rdx
movl -0x24(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bf6c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
jmp 0x3bf6e
movl $0x1, -0x20(%rbp)
cmpl $0x9, -0x20(%rbp)
jg 0x3bfde
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x3bfd1
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x80(%rax,%rcx,8), %rdx
movl -0x24(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3bfcf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
jmp 0x3bfd1
jmp 0x3bfd3
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3bf75
jmp 0x3bfe0
jmp 0x3bfe2
jmp 0x3bfe4
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %eax
andl $0xfffff7ef, %eax       # imm = 0xFFFFF7EF
movl %eax, -0x30(%rbp)
movl $0x9, %eax
cmpl -0x1c(%rbp), %eax
jge 0x3c02a
movl $0x9, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3c030
movl -0x1c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x30(%rbp), %ecx
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3c059
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0xa0(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpq (%rcx), %rax
je 0x3c0b2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0xa0(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x120(%rax), %rdx
movl -0x24(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x472d0
cmpl $0x0, %eax
je 0x3c0b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c151
jmp 0x3c0b2
movl $0x1, -0x2c(%rbp)
cmpl $0x2f, -0x2c(%rbp)
jge 0x3c14a
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x3c0f3
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpq (%rcx), %rax
jne 0x3c0f5
jmp 0x3c13c
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, (%rax)
jne 0x3c13a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq 0x80(%rax,%rcx,8), %rdx
movl -0x28(%rbp), %ecx
movl -0x1c(%rbp), %r8d
callq 0x472d0
jmp 0x3c13c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3c0b9
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)