// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/zlib-1.3.0.1/uncompr.c
// Function: uncompress2
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
                        uLong *sourceLen) {
    z_stream stream;
    int err;
    const uInt max = (uInt)-1;
    uLong len, left;
    Byte buf[1];    /* for detection of incomplete stream when *destLen == 0 */

    len = *sourceLen;
    if (*destLen) {
        left = *destLen;
        *destLen = 0;
    }
    else {
        left = 1;
        dest = buf;
    }

    stream.next_in = (z_const Bytef *)source;
    stream.avail_in = 0;
    stream.zalloc = (alloc_func)0;
    stream.zfree = (free_func)0;
    stream.opaque = (voidpf)0;

    err = inflateInit(&stream);
    if (err != Z_OK) return err;

    stream.next_out = dest;
    stream.avail_out = 0;

    do {
        if (stream.avail_out == 0) {
            stream.avail_out = left > (uLong)max ? max : (uInt)left;
            left -= stream.avail_out;
        }
        if (stream.avail_in == 0) {
            stream.avail_in = len > (uLong)max ? max : (uInt)len;
            len -= stream.avail_in;
        }
        err = inflate(&stream, Z_NO_FLUSH);
    } while (err == Z_OK);

    *sourceLen -= len + stream.avail_in;
    if (dest != buf)
        *destLen = stream.total_out;
    else if (stream.total_out && err == Z_BUF_ERROR)
        left = 1;

    inflateEnd(&stream);
    return err == Z_STREAM_END ? Z_OK :
           err == Z_NEED_DICT ? Z_DATA_ERROR  :
           err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
           err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r14
movq %rsi, %rbx
movq (%rcx), %r15
movq (%rsi), %r13
testq %r13, %r13
je 0x2caad7
movq %rdi, %r12
andq $0x0, (%rbx)
jmp 0x2caae0
pushq $0x1
popq %r13
leaq 0x7(%rsp), %r12
leaq 0x18(%rsp), %rdi
movq %rdx, (%rdi)
andl $0x0, 0x8(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rdi)
andq $0x0, 0x50(%rdi)
leaq 0x8fd4c(%rip), %rsi     # 0x35a84b
pushq $0x70
popq %rdx
callq 0x2cf669
movl %eax, %ebp
testl %eax, %eax
je 0x2cab21
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x10(%rsp)
movq %r12, %rax
leaq 0x18(%rsp), %r12
movq %rax, 0x8(%rsp)
movq %rax, 0x18(%r12)
andl $0x0, 0x20(%r12)
xorl %eax, %eax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x2cab5d
cmpq %r14, %r13
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovbq %r13, %rax
movl %eax, 0x38(%rsp)
subq %rax, %r13
cmpl $0x0, 0x20(%rsp)
jne 0x2cab77
cmpq %r14, %r15
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovbq %r15, %rax
movl %eax, 0x20(%rsp)
subq %rax, %r15
movq %r12, %rdi
xorl %esi, %esi
callq 0x2cf6d9
testl %eax, %eax
jne 0x2cab8b
movl 0x38(%rsp), %eax
jmp 0x2cab46
movl %eax, %ebp
movl 0x20(%rsp), %eax
addq %rax, %r15
movq 0x10(%rsp), %rax
subq %r15, (%rax)
leaq 0x7(%rsp), %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, 0x8(%rsp)
je 0x2cabb2
movq %rax, (%rbx)
jmp 0x2cabc3
testq %rax, %rax
pushq $0x1
popq %rax
cmoveq %r13, %rax
cmpl $-0x5, %ebp
cmoveq %rax, %r13
leaq 0x18(%rsp), %rdi
callq 0x2d13c1
cmpl $0x2, %ebp
je 0x2cabed
cmpl $0x1, %ebp
je 0x2cabf5
cmpl $-0x5, %ebp
jne 0x2cab0d
movl 0x38(%rsp), %eax
addq %rax, %r13
je 0x2cab0d
pushq $-0x3
popq %rbp
jmp 0x2cab0d
xorl %ebp, %ebp
jmp 0x2cab0d