#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int tinf_uncompress(unsigned char *, unsigned int *, unsigned char *,
                    unsigned int);
int tinf_zlib_uncompress(void *dest, unsigned int *destLen, const void *source,
                         unsigned int sourceLen) {
  unsigned char *src = (unsigned char *)source;
  unsigned char *dst = (unsigned char *)dest;
  int res;
  unsigned char cmf, flg;
  cmf = src[0];
  flg = src[1];
  if (((cmf << 8) + flg) % 31)
    return (-3);
  if ((cmf & 0x0f) != 8)
    return (-3);
  if ((cmf >> 4) > 7)
    return (-3);
  if (flg & 0x20)
    return (-3);
  res = tinf_uncompress(dst, destLen, src + 2, sourceLen - 6);
  if (res != 0)
    return (-3);
  return 0;
}


x86 assembly (clang, -O0):
<tinf_zlib_uncompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x3d(%rbp)
mov    -0x30(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x3e(%rbp)
movzbl -0x3d(%rbp),%eax
shl    $0x8,%eax
movzbl -0x3e(%rbp),%ecx
add    %ecx,%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1174 <tinf_zlib_uncompress+0x64>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1203 <tinf_zlib_uncompress+0xf3>
movzbl -0x3d(%rbp),%eax
and    $0xf,%eax
cmp    $0x8,%eax
je     1190 <tinf_zlib_uncompress+0x80>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1203 <tinf_zlib_uncompress+0xf3>
movzbl -0x3d(%rbp),%eax
sar    $0x4,%eax
cmp    $0x7,%eax
jle    11ac <tinf_zlib_uncompress+0x9c>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1203 <tinf_zlib_uncompress+0xf3>
movzbl -0x3e(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     11c8 <tinf_zlib_uncompress+0xb8>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1203 <tinf_zlib_uncompress+0xf3>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
add    $0x2,%rdx
mov    -0x24(%rbp),%ecx
sub    $0x6,%ecx
call   1030 <tinf_uncompress@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11fc <tinf_zlib_uncompress+0xec>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1203 <tinf_zlib_uncompress+0xf3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tinf_zlib_uncompress>:
push   %rax
movzbl (%rdx),%r9d
movzbl 0x1(%rdx),%r8d
mov    %r9d,%eax
shl    $0x8,%eax
or     %r8d,%eax
imul   $0xbdef7bdf,%eax,%r10d
mov    $0xfffffffd,%eax
cmp    $0x8421084,%r10d
ja     1169 <tinf_zlib_uncompress+0x59>
mov    %r9d,%r10d
and    $0xf,%r10d
cmp    $0x8,%r10d
jne    1169 <tinf_zlib_uncompress+0x59>
test   %r9b,%r9b
js     1169 <tinf_zlib_uncompress+0x59>
and    $0x20,%r8d
jne    1169 <tinf_zlib_uncompress+0x59>
add    $0x2,%rdx
add    $0xfffffffa,%ecx
call   1030 <tinf_uncompress@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,2),%eax
add    $0xfffffffd,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @tinf_zlib_uncompress(i8* %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8
%14 = alloca i8
store i8* %0, i8** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%15 = load i8*, i8** %8
store i8* %15, i8** %10
%16 = load i8*, i8** %6
store i8* %16, i8** %11
%17 = load i8*, i8** %10
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
store i8 %19, i8* %13
%20 = load i8*, i8** %10
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
store i8 %22, i8* %14
%23 = load i8, i8* %13
%24 = zext i8 %23 to i32
%25 = shl i32 %24, 8
%26 = load i8, i8* %14
%27 = zext i8 %26 to i32
%28 = add nsw i32 %25, %27
%29 = srem i32 %28, 31
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %4
store i32 -3, i32* %5
br label %62
32: ; preds = %4
%33 = load i8, i8* %13
%34 = zext i8 %33 to i32
%35 = and i32 %34, 15
%36 = icmp ne i32 %35, 8
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 -3, i32* %5
br label %62
38: ; preds = %32
%39 = load i8, i8* %13
%40 = zext i8 %39 to i32
%41 = ashr i32 %40, 4
%42 = icmp sgt i32 %41, 7
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 -3, i32* %5
br label %62
44: ; preds = %38
%45 = load i8, i8* %14
%46 = zext i8 %45 to i32
%47 = and i32 %46, 32
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %44
store i32 -3, i32* %5
br label %62
50: ; preds = %44
%51 = load i8*, i8** %11
%52 = load i32*, i32** %7
%53 = load i8*, i8** %10
%54 = getelementptr inbounds i8, i8* %53, i64 2
%55 = load i32, i32* %9
%56 = sub i32 %55, 6
%57 = call i32 @tinf_uncompress(i8* %51, i32* %52, i8* %54, i32 %56)
store i32 %57, i32* %12
%58 = load i32, i32* %12
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %50
store i32 -3, i32* %5
br label %62
61: ; preds = %50
store i32 0, i32* %5
br label %62
62: ; preds = %61, %60, %49, %43, %37, %31
%63 = load i32, i32* %5
ret i32 %63
}

LLVM IR (-O2):
define i32 @tinf_zlib_uncompress(i8* %0, i32* %1, i8* %2, i32 %3) {
%5 = load i8, i8* %2
%6 = getelementptr inbounds i8, i8* %2, i64 1
%7 = load i8, i8* %6
%8 = zext i8 %5 to i32
%9 = shl nuw nsw i32 %8, 8
%10 = zext i8 %7 to i32
%11 = or i32 %9, %10
%12 = urem i32 %11, 31
%13 = icmp eq i32 %12, 0
%14 = and i32 %8, 15
%15 = icmp eq i32 %14, 8
%16 = select i1 %13, i1 %15, i1 false
%17 = icmp sgt i8 %5, -1
%18 = select i1 %16, i1 %17, i1 false
%19 = and i32 %10, 32
%20 = icmp eq i32 %19, 0
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %22, label %28
22: ; preds = %4
%23 = getelementptr inbounds i8, i8* %2, i64 2
%24 = add i32 %3, -6
%25 = tail call i32 @tinf_uncompress(i8* %0, i32* %1, i8* %23, i32 %24)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i32 0, i32 -3
br label %28
28: ; preds = %22, %4
%29 = phi i32 [ -3, %4 ], [ %27, %22 ]
ret i32 %29
}