#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  unsigned int avail_in;
  unsigned int avail_out;
  scalar_t__ opaque;
  void *zfree;
  void *zalloc;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
int Z_BUF_ERROR;
int Z_DATA_ERROR;
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int zlib_uncompress(void *dest, unsigned int destLen, const void *src,
                    unsigned int srcLen) {
  z_stream zs;
  int ret;
  zs.next_in = (Bytef *)src;
  zs.avail_in = srcLen;
  zs.next_out = (Bytef *)dest;
  zs.avail_out = destLen;
  zs.zalloc = Z_NULL;
  zs.zfree = Z_NULL;
  zs.opaque = 0;
  ret = inflateInit(&zs);
  if (ret == Z_OK) {
    ret = inflate(&zs, Z_FINISH);
    if (ret == Z_STREAM_END)
      ret = Z_OK;
    if (inflateEnd(&zs) == Z_DATA_ERROR)
      ret = Z_DATA_ERROR;
  }
  if (ret == Z_BUF_ERROR)
    ret = Z_DATA_ERROR;
  return ret;
}


x86 assembly (clang, -O0):
<zlib_uncompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <inflateInit@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%eax
jne    1200 <zlib_uncompress+0xd0>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
jne    11d7 <zlib_uncompress+0xa7>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
call   1050 <inflateEnd@plt>
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%eax
jne    11fb <zlib_uncompress+0xcb>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
jmp    1200 <zlib_uncompress+0xd0>
mov    -0x54(%rbp),%eax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%eax
jne    121e <zlib_uncompress+0xee>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zlib_uncompress>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdx,0x28(%rsp)
mov    %ecx,(%rsp)
mov    %rdi,0x20(%rsp)
mov    %esi,0x4(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
mov    %rax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
call   1040 <inflateInit@plt>
mov    0x2e72(%rip),%r15
cmp    (%r15),%eax
jne    11b9 <zlib_uncompress+0x89>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <inflate@plt>
mov    %eax,%ebx
mov    0x2e40(%rip),%rax
cmp    (%rax),%ebx
jne    119f <zlib_uncompress+0x6f>
mov    (%r15),%ebx
mov    %r14,%rdi
call   1050 <inflateEnd@plt>
mov    %eax,%ecx
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ecx
cmove  %eax,%ebx
jmp    11c4 <zlib_uncompress+0x94>
mov    %eax,%ebx
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%ebx
cmovne %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32, i64, i8*, i8*, i32*, i32* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@Z_DATA_ERROR = global i32 0
@Z_BUF_ERROR = global i32 0
define i32 @zlib_uncompress(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.TYPE_5__
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %7
%12 = bitcast i8* %11 to i32*
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 6
store i32* %12, i32** %13
%14 = load i32, i32* %8
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
store i32 %14, i32* %15
%16 = load i8*, i8** %5
%17 = bitcast i8* %16 to i32*
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 5
store i32* %17, i32** %18
%19 = load i32, i32* %6
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i8*, i8** @Z_NULL
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 4
store i8* %21, i8** %22
%23 = load i8*, i8** @Z_NULL
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 3
store i8* %23, i8** %24
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 2
store i64 0, i64* %25
%26 = call i32 @inflateInit(%struct.TYPE_5__* %9)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = load i32, i32* @Z_OK
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %45
30: ; preds = %4
%31 = load i32, i32* @Z_FINISH
%32 = call i32 @inflate(%struct.TYPE_5__* %9, i32 %31)
store i32 %32, i32* %10
%33 = load i32, i32* %10
%34 = load i32, i32* @Z_STREAM_END
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = load i32, i32* @Z_OK
store i32 %37, i32* %10
br label %38
38: ; preds = %36, %30
%39 = call i32 @inflateEnd(%struct.TYPE_5__* %9)
%40 = load i32, i32* @Z_DATA_ERROR
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = load i32, i32* @Z_DATA_ERROR
store i32 %43, i32* %10
br label %44
44: ; preds = %42, %38
br label %45
45: ; preds = %44, %4
%46 = load i32, i32* %10
%47 = load i32, i32* @Z_BUF_ERROR
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load i32, i32* @Z_DATA_ERROR
store i32 %50, i32* %10
br label %51
51: ; preds = %49, %45
%52 = load i32, i32* %10
ret i32 %52
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, i64, i8*, i8*, i32*, i32* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@Z_DATA_ERROR = global i32 0
@Z_BUF_ERROR = global i32 0
define i32 @zlib_uncompress(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.TYPE_5__
%6 = bitcast %struct.TYPE_5__* %5 to i8*
%7 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 6
%8 = bitcast i32** %7 to i8**
store i8* %2, i8** %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
store i32 %3, i32* %9
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 5
%11 = bitcast i32** %10 to i8**
store i8* %0, i8** %11
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
store i32 %1, i32* %12
%13 = load i8*, i8** @Z_NULL
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 4
store i8* %13, i8** %14
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 3
store i8* %13, i8** %15
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 2
store i64 0, i64* %16
%17 = call i32 @inflateInit(%struct.TYPE_5__* %5)
%18 = load i32, i32* @Z_OK
%19 = icmp eq i32 %17, %18
br i1 %19, label %22, label %20
20: ; preds = %4
%21 = load i32, i32* @Z_DATA_ERROR
br label %33
22: ; preds = %4
%23 = load i32, i32* @Z_FINISH
%24 = call i32 @inflate(%struct.TYPE_5__* %5, i32 %23)
%25 = load i32, i32* @Z_STREAM_END
%26 = icmp eq i32 %24, %25
%27 = load i32, i32* @Z_OK
%28 = select i1 %26, i32 %27, i32 %24
%29 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
%30 = load i32, i32* @Z_DATA_ERROR
%31 = icmp eq i32 %29, %30
%32 = select i1 %31, i32 %30, i32 %28
br label %33
33: ; preds = %20, %22
%34 = phi i32 [ %21, %20 ], [ %30, %22 ]
%35 = phi i32 [ %17, %20 ], [ %32, %22 ]
%36 = load i32, i32* @Z_BUF_ERROR
%37 = icmp eq i32 %35, %36
%38 = select i1 %37, i32 %34, i32 %35
ret i32 %38
}