#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 */
typedef unsigned int uLongf;

/* Variables and functions */
int Z_BUF_ERROR;
int Z_DATA_ERROR;
int Z_OK;
int uncompress(char *, unsigned int *, char *, unsigned int);
int comp_zlib_uncompress(char *outbuf, unsigned int *outlen, char *source,
                         unsigned int sourcelen) {
  int r;
  uLongf t_outlen = *outlen;
  r = uncompress(outbuf, &t_outlen, source, sourcelen);
  *outlen = t_outlen;
  if (r == Z_OK)
    return 0;
  if (r == Z_BUF_ERROR)
    return 1;
  if (r == Z_DATA_ERROR)
    return 2;
  return 3;
}


x86 assembly (clang, -O0):
<comp_zlib_uncompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    -0x2c(%rbp),%rsi
call   1030 <uncompress@plt>
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
jne    116e <comp_zlib_uncompress+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <comp_zlib_uncompress+0xa1>
mov    -0x28(%rbp),%eax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
jne    118c <comp_zlib_uncompress+0x7c>
movl   $0x1,-0x4(%rbp)
jmp    11b1 <comp_zlib_uncompress+0xa1>
mov    -0x28(%rbp),%eax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%eax
jne    11aa <comp_zlib_uncompress+0x9a>
movl   $0x2,-0x4(%rbp)
jmp    11b1 <comp_zlib_uncompress+0xa1>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comp_zlib_uncompress>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    (%rsi),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
call   1030 <uncompress@plt>
mov    0xc(%rsp),%ecx
mov    %ecx,(%rbx)
mov    0x2eb3(%rip),%rdx
xor    %ecx,%ecx
cmp    (%rdx),%eax
je     115c <comp_zlib_uncompress+0x4c>
mov    0x2e96(%rip),%rdx
mov    $0x1,%ecx
cmp    (%rdx),%eax
je     115c <comp_zlib_uncompress+0x4c>
mov    0x2e9e(%rip),%rdx
xor    %ecx,%ecx
cmp    (%rdx),%eax
sete   %cl
xor    $0x3,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@Z_OK = global i32 0
@Z_BUF_ERROR = global i32 0
@Z_DATA_ERROR = global i32 0
define i32 @comp_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 i32
%11 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i32*, i32** %7
%13 = load i32, i32* %12
store i32 %13, i32* %11
%14 = load i8*, i8** %6
%15 = load i8*, i8** %8
%16 = load i32, i32* %9
%17 = call i32 @uncompress(i8* %14, i32* %11, i8* %15, i32 %16)
store i32 %17, i32* %10
%18 = load i32, i32* %11
%19 = load i32*, i32** %7
store i32 %18, i32* %19
%20 = load i32, i32* %10
%21 = load i32, i32* @Z_OK
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %4
store i32 0, i32* %5
br label %35
24: ; preds = %4
%25 = load i32, i32* %10
%26 = load i32, i32* @Z_BUF_ERROR
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 1, i32* %5
br label %35
29: ; preds = %24
%30 = load i32, i32* %10
%31 = load i32, i32* @Z_DATA_ERROR
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 2, i32* %5
br label %35
34: ; preds = %29
store i32 3, i32* %5
br label %35
35: ; preds = %34, %33, %28, %23
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@Z_OK = global i32 0
@Z_BUF_ERROR = global i32 0
@Z_DATA_ERROR = global i32 0
define i32 @comp_zlib_uncompress(i8* %0, i32* nocapture %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* %1
store i32 %7, i32* %5
%8 = call i32 @uncompress(i8* %0, i32* %5, i8* %2, i32 %3)
%9 = load i32, i32* %5
store i32 %9, i32* %1
%10 = load i32, i32* @Z_OK
%11 = icmp eq i32 %8, %10
br i1 %11, label %19, label %12
12: ; preds = %4
%13 = load i32, i32* @Z_BUF_ERROR
%14 = icmp eq i32 %8, %13
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = load i32, i32* @Z_DATA_ERROR
%17 = icmp eq i32 %8, %16
%18 = select i1 %17, i32 2, i32 3
br label %19
19: ; preds = %15, %12, %4
%20 = phi i32 [ 0, %4 ], [ 1, %12 ], [ %18, %15 ]
ret i32 %20
}