// File: karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: zlib_mem_deflate
static char *zlib_mem_deflate(char *data, size_t size, size_t *cdata_size,
			      int level, int strat) {
    z_stream s;
    unsigned char *cdata = NULL; /* Compressed output */
    int cdata_alloc = 0;
    int cdata_pos = 0;
    int err;

    cdata = malloc(cdata_alloc = size*1.05+100);
    if (!cdata)
	return NULL;
    cdata_pos = 0;

    /* Initialise zlib stream */
    s.zalloc = Z_NULL; /* use default allocation functions */
    s.zfree  = Z_NULL;
    s.opaque = Z_NULL;
    s.next_in  = (unsigned char *)data;
    s.avail_in = size;
    s.total_in = 0;
    s.next_out  = cdata;
    s.avail_out = cdata_alloc;
    s.total_out = 0;
    s.data_type = Z_BINARY;

    err = deflateInit2(&s, level, Z_DEFLATED, 15|16, 9, strat);
    if (err != Z_OK) {
	fprintf(stderr, "zlib deflateInit2 error: %s\n", s.msg);
	return NULL;
    }

    /* Encode to 'cdata' array */
    for (;s.avail_in;) {
	s.next_out = &cdata[cdata_pos];
	s.avail_out = cdata_alloc - cdata_pos;
	if (cdata_alloc - cdata_pos <= 0) {
	    fprintf(stderr, "Deflate produced larger output than expected. Abort\n"); 
	    return NULL;
	}
	err = deflate(&s, Z_NO_FLUSH);
	cdata_pos = cdata_alloc - s.avail_out;
	if (err != Z_OK) {
	    fprintf(stderr, "zlib deflate error: %s\n", s.msg);
	    break;
	}
    }
    if (deflate(&s, Z_FINISH) != Z_STREAM_END) {
	fprintf(stderr, "zlib deflate error: %s\n", s.msg);
    }
    *cdata_size = s.total_out;

    if (deflateEnd(&s) != Z_OK) {
	fprintf(stderr, "zlib deflate error: %s\n", s.msg);
    }
    return (char *)cdata;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq $0x0, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
movaps 0x2720c(%rip), %xmm1    # 0x7aae0
movq -0x18(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2720b(%rip), %xmm1    # 0x7aaf0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x293a4(%rip), %xmm1    # 0x7cca0
mulsd %xmm1, %xmm0
movsd 0x24778(%rip), %xmm1    # 0x78080
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0xa4(%rbp)
movslq %eax, %rdi
callq 0x47a0
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0x5393c
movq $0x0, -0x8(%rbp)
jmp 0x53b3c
movl $0x0, -0xa8(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movl %eax, -0x90(%rbp)
movq $0x0, -0x88(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x80(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %r9d
leaq -0x98(%rbp), %rdi
movl $0x8, %edx
movl $0x1f, %ecx
movl $0x9, %r8d
leaq 0x277e4(%rip), %rax     # 0x7b1aa
movq %rax, (%rsp)
movl $0x70, 0x8(%rsp)
callq 0x4090
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
je 0x53a0f
movq 0x365e3(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x68(%rbp), %rdx
leaq 0x29706(%rip), %rsi     # 0x7d101
movb $0x0, %al
callq 0x4830
movq $0x0, -0x8(%rbp)
jmp 0x53b3c
jmp 0x53a11
cmpl $0x0, -0x90(%rbp)
je 0x53ac7
movq -0xa0(%rbp), %rax
movslq -0xa8(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl -0xa4(%rbp), %eax
subl -0xa8(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0xa4(%rbp), %eax
subl -0xa8(%rbp), %eax
cmpl $0x0, %eax
jg 0x53a78
movq 0x36576(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
leaq 0x296ba(%rip), %rsi     # 0x7d11e
movb $0x0, %al
callq 0x4830
movq $0x0, -0x8(%rbp)
jmp 0x53b3c
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
callq 0x4270
movl %eax, -0xac(%rbp)
movl -0xa4(%rbp), %eax
subl -0x78(%rbp), %eax
movl %eax, -0xa8(%rbp)
cmpl $0x0, -0xac(%rbp)
je 0x53ac2
movq 0x36525(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x68(%rbp), %rdx
leaq 0x2969a(%rip), %rsi     # 0x7d153
movb $0x0, %al
callq 0x4830
jmp 0x53ac7
jmp 0x53a11
leaq -0x98(%rbp), %rdi
movl $0x4, %esi
callq 0x4270
cmpl $0x1, %eax
je 0x53af9
movq 0x364ec(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x68(%rbp), %rdx
leaq 0x29661(%rip), %rsi     # 0x7d153
movb $0x0, %al
callq 0x4830
movq -0x70(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
leaq -0x98(%rbp), %rdi
callq 0x4310
cmpl $0x0, %eax
je 0x53b31
movq 0x364b4(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x68(%rbp), %rdx
leaq 0x29629(%rip), %rsi     # 0x7d153
movb $0x0, %al
callq 0x4830
movq -0xa0(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)