// File: /workspace/github_c_makefile_star2_O3/samtools[P]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) {
        hts_log_error("Call to zlib inflateInit failed: %s", 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) {
            hts_log_error("Call to zlib inflate failed: %s", s.msg);
            free(data);
            inflateEnd(&s);
            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);
            inflateEnd(&s);
            return NULL;
        }
        s.avail_out += alloc_inc;
    }
    inflateEnd(&s);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r15
movq %rsi, %xmm0
punpckldq 0x49335(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4933d(%rip), %xmm0    # 0x957c0
movq %rdx, %rbx
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x4e8c6(%rip), %xmm1    # 0x9ad60
addsd 0x4843e(%rip), %xmm1    # 0x948e0
movq %rdi, %r12
cvttsd2si %xmm1, %ebp
movslq %ebp, %rdi
callq 0x4680
testq %rax, %rax
je 0x4c660
movq %rax, %r14
xorpd %xmm0, %xmm0
leaq 0x8(%rsp), %rdi
movupd %xmm0, 0x40(%rdi)
xorl %eax, %eax
movq %rax, 0x50(%rdi)
movq %r12, (%rdi)
movl %r15d, 0x8(%rdi)
movq %rax, 0x10(%rdi)
movq %r14, 0x18(%rdi)
movl %ebp, 0x20(%rdi)
movq %rax, 0x28(%rdi)
leaq 0x484d2(%rip), %rdx     # 0x949c0
movl $0x2f, %esi
movl $0x70, %ecx
callq 0x43e0
testl %eax, %eax
je 0x4c530
movq 0x38(%rsp), %rcx
leaq 0x4e8a3(%rip), %rsi     # 0x9adb0
leaq 0x4e8ad(%rip), %rdx     # 0x9adc1
xorl %r12d, %r12d
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movq %r14, %rdi
callq 0x45c0
jmp 0x4c663
movq %rbx, (%rsp)
cmpl $0x0, 0x10(%rsp)
je 0x4c5f9
leaq 0x8(%rsp), %rax
movq 0x28(%rax), %r13
addq %r14, %r13
movq %r13, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x4380
testl %eax, %eax
jne 0x4c5f4
movl 0x10(%rsp), %ebx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x49232(%rip), %xmm3    # 0x957b0
unpcklps %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x49237(%rip), %xmm4    # 0x957c0
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movq 0x30(%rsp), %r13
movq %r13, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
addsd 0x48319(%rip), %xmm2    # 0x948e0
cvttsd2si %xmm2, %r15d
addl %r15d, %ebp
movslq %ebp, %rsi
movq %r14, %rdi
callq 0x4840
testq %rax, %rax
je 0x4c64e
movq %rax, %r12
addl %r15d, 0x28(%rsp)
movq %rax, %r14
testl %ebx, %ebx
jne 0x4c548
jmp 0x4c5fc
cmpl $0x1, %eax
jne 0x4c616
movq %r14, %r12
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x44e0
movq 0x28(%r14), %rax
movq (%rsp), %rcx
movq %rax, (%rcx)
jmp 0x4c663
leaq 0x8(%rsp), %rbx
movq 0x30(%rbx), %rcx
leaq 0x4e78a(%rip), %rsi     # 0x9adb0
leaq 0x4e7b8(%rip), %rdx     # 0x9ade5
xorl %r12d, %r12d
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movq %r14, %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x44e0
jmp 0x4c663
movq %r14, %rdi
callq 0x45c0
leaq 0x8(%rsp), %rdi
callq 0x44e0
xorl %r12d, %r12d
movq %r12, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq