// File: karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: zlib_mem_inflate
char *zlib_mem_inflate(char *cdata, size_t csize, size_t *size) {
    z_stream s;
    unsigned char *data = NULL; /* Uncompressed output */
    int data_alloc = 0;
    int err;

    /* Starting point at uncompressed size, and scale after that */
    data = malloc(data_alloc = csize*1.2+100);
    if (!data)
	return NULL;

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

    //err = inflateInit(&s);
    err = inflateInit2(&s, 15 + 32);
    if (err != Z_OK) {
	fprintf(stderr, "zlib inflateInit error: %s\n", s.msg);
	free(data);
	return NULL;
    }

    /* Decode to 'data' array */
    for (;s.avail_in;) {
	unsigned char *data_tmp;
	int alloc_inc;

	s.next_out = &data[s.total_out];
	err = inflate(&s, Z_NO_FLUSH);
	if (err == Z_STREAM_END)
	    break;

	if (err != Z_OK) {
	    fprintf(stderr, "zlib inflate error: %s\n", s.msg);
	    if (data)
		free(data);
	    return NULL;
	}

	/* More to come, so realloc based on growth so far */
	alloc_inc = (double)s.avail_in/s.total_in * s.total_out + 100;
	data = realloc((data_tmp = data), data_alloc += alloc_inc);
	if (!data) {
	    free(data_tmp);
	    return NULL;
	}
	s.avail_out += alloc_inc;
    }
    inflateEnd(&s);

    *size = s.total_out;
    return (char *)data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movaps 0x3526d(%rip), %xmm1    # 0x7aae0
movq -0x18(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3526c(%rip), %xmm1    # 0x7aaf0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x373fd(%rip), %xmm1    # 0x7cc98
mulsd %xmm1, %xmm0
movsd 0x327d9(%rip), %xmm1    # 0x78080
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x9c(%rbp)
movslq %eax, %rdi
callq 0x47a0
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
jne 0x458db
movq $0x0, -0x8(%rbp)
jmp 0x45aff
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movl %eax, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
leaq -0x90(%rbp), %rdi
movl $0x2f, %esi
leaq 0x3586b(%rip), %rdx     # 0x7b1aa
movl $0x70, %ecx
callq 0x44b0
movl %eax, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
je 0x4598d
movq 0x44671(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x60(%rbp), %rdx
leaq 0x3737b(%rip), %rsi     # 0x7cce8
movb $0x0, %al
callq 0x4830
movq -0x98(%rbp), %rdi
callq 0x46a0
movq $0x0, -0x8(%rbp)
jmp 0x45aff
jmp 0x4598f
cmpl $0x0, -0x88(%rbp)
je 0x45add
movq -0x98(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
callq 0x4450
movl %eax, -0xa0(%rbp)
cmpl $0x1, -0xa0(%rbp)
jne 0x459cd
jmp 0x45add
cmpl $0x0, -0xa0(%rbp)
je 0x45a15
movq 0x445f3(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x60(%rbp), %rdx
leaq 0x37319(%rip), %rsi     # 0x7cd04
movb $0x0, %al
callq 0x4830
cmpq $0x0, -0x98(%rbp)
je 0x45a08
movq -0x98(%rbp), %rdi
callq 0x46a0
movq $0x0, -0x8(%rbp)
jmp 0x45aff
movl -0x88(%rbp), %eax
cvtsi2sd %rax, %xmm0
movq -0x80(%rbp), %xmm1
movaps 0x350b4(%rip), %xmm3    # 0x7aae0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x350b8(%rip), %xmm2    # 0x7aaf0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm4
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm4, %xmm1
divsd %xmm1, %xmm0
movq -0x68(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x32611(%rip), %xmm1    # 0x78080
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0xac(%rbp)
movq -0x98(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
movl -0xac(%rbp), %eax
addl -0x9c(%rbp), %eax
movl %eax, -0x9c(%rbp)
movslq %eax, %rsi
callq 0x4990
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
jne 0x45acc
movq -0xa8(%rbp), %rdi
callq 0x46a0
movq $0x0, -0x8(%rbp)
jmp 0x45aff
movl -0xac(%rbp), %eax
addl -0x70(%rbp), %eax
movl %eax, -0x70(%rbp)
jmp 0x4598f
leaq -0x90(%rbp), %rdi
callq 0x45d0
movq -0x68(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x98(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)