#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 long total_out;
  scalar_t__ zfree;
  scalar_t__ zalloc;
  void *avail_out;
  int /*<<< orphan*/ *next_out;
  void *avail_in;
  int /*<<< orphan*/ *next_in;
};
typedef TYPE_1__ z_stream;
typedef unsigned long uLong;
typedef void *uInt;
typedef scalar_t__ free_func;
typedef scalar_t__ alloc_func;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
int Z_BUF_ERROR;
int /*<<< orphan*/ Z_FINISH;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int decode_zip(unsigned char *dest, unsigned long *destLen,
               const unsigned char *source, unsigned long sourceLen) {
  z_stream stream;
  int err;
  stream.next_in = (Bytef *)source;
  stream.avail_in = (uInt)sourceLen;
  if ((uLong)stream.avail_in != sourceLen)
    return Z_BUF_ERROR;
  stream.next_out = (Bytef *)dest;
  stream.avail_out = (uInt)*destLen;
  if ((uLong)stream.avail_out != *destLen)
    return Z_BUF_ERROR;
  stream.zalloc = (alloc_func)0;
  stream.zfree = (free_func)0;
  err = inflateInit(&stream);
  if (err != Z_OK)
    return err;
  err = inflate(&stream, Z_FINISH);
  if (err != Z_STREAM_END) {
    inflateEnd(&stream);
    return err == Z_OK ? Z_BUF_ERROR : err;
  }
  *destLen = stream.total_out;
  err = inflateEnd(&stream);
  return err;
}


x86 assembly (clang, -O0):
<decode_zip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1177 <decode_zip+0x47>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1266 <decode_zip+0x136>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
je     11ac <decode_zip+0x7c>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1266 <decode_zip+0x136>
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <inflateInit@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%eax
je     11e5 <decode_zip+0xb5>
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1266 <decode_zip+0x136>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%eax
je     1249 <decode_zip+0x119>
lea    -0x60(%rbp),%rdi
call   1050 <inflateEnd@plt>
mov    -0x64(%rbp),%eax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%eax
jne    1238 <decode_zip+0x108>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
jmp    123e <decode_zip+0x10e>
mov    -0x64(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1266 <decode_zip+0x136>
mov    -0x60(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x60(%rbp),%rdi
call   1050 <inflateEnd@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_zip>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
mov    %rdx,0x38(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rdi,0x28(%rsp)
mov    (%rsi),%rax
mov    %rax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <inflateInit@plt>
mov    %eax,%ebp
mov    0x2e83(%rip),%r14
cmp    (%r14),%eax
jne    11c0 <decode_zip+0x90>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1030 <inflate@plt>
mov    %eax,%ebp
mov    0x2e52(%rip),%rax
cmp    (%rax),%ebp
jne    11a8 <decode_zip+0x78>
mov    0x8(%rsp),%rax
mov    %rax,(%rbx)
lea    0x8(%rsp),%rdi
call   1050 <inflateEnd@plt>
mov    %eax,%ebp
jmp    11c0 <decode_zip+0x90>
lea    0x8(%rsp),%rdi
call   1050 <inflateEnd@plt>
cmp    (%r14),%ebp
jne    11c0 <decode_zip+0x90>
mov    0x2e1a(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64, i64, i64, i8*, i32*, i8*, i32* }
@Z_BUF_ERROR = global i32 0
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @decode_zip(i8* %0, i64* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.TYPE_5__
%11 = alloca i32
store i8* %0, i8** %6
store i64* %1, i64** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i8*, i8** %8
%13 = bitcast i8* %12 to i32*
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 6
store i32* %13, i32** %14
%15 = load i64, i64* %9
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 5
store i8* %16, i8** %17
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 5
%19 = load i8*, i8** %18
%20 = ptrtoint i8* %19 to i64
%21 = load i64, i64* %9
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %4
%24 = load i32, i32* @Z_BUF_ERROR
store i32 %24, i32* %5
br label %73
25: ; preds = %4
%26 = load i8*, i8** %6
%27 = bitcast i8* %26 to i32*
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 4
store i32* %27, i32** %28
%29 = load i64*, i64** %7
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to i8*
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 3
store i8* %31, i8** %32
%33 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 3
%34 = load i8*, i8** %33
%35 = ptrtoint i8* %34 to i64
%36 = load i64*, i64** %7
%37 = load i64, i64* %36
%38 = icmp ne i64 %35, %37
br i1 %38, label %39, label %41
39: ; preds = %25
%40 = load i32, i32* @Z_BUF_ERROR
store i32 %40, i32* %5
br label %73
41: ; preds = %25
%42 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 2
store i64 0, i64* %42
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 1
store i64 0, i64* %43
%44 = call i32 @inflateInit(%struct.TYPE_5__* %10)
store i32 %44, i32* %11
%45 = load i32, i32* %11
%46 = load i32, i32* @Z_OK
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = load i32, i32* %11
store i32 %49, i32* %5
br label %73
50: ; preds = %41
%51 = load i32, i32* @Z_FINISH
%52 = call i32 @inflate(%struct.TYPE_5__* %10, i32 %51)
store i32 %52, i32* %11
%53 = load i32, i32* %11
%54 = load i32, i32* @Z_STREAM_END
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %67
56: ; preds = %50
%57 = call i32 @inflateEnd(%struct.TYPE_5__* %10)
%58 = load i32, i32* %11
%59 = load i32, i32* @Z_OK
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = load i32, i32* @Z_BUF_ERROR
br label %65
63: ; preds = %56
%64 = load i32, i32* %11
br label %65
65: ; preds = %63, %61
%66 = phi i32 [ %62, %61 ], [ %64, %63 ]
store i32 %66, i32* %5
br label %73
67: ; preds = %50
%68 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 0
%69 = load i64, i64* %68
%70 = load i64*, i64** %7
store i64 %69, i64* %70
%71 = call i32 @inflateEnd(%struct.TYPE_5__* %10)
store i32 %71, i32* %11
%72 = load i32, i32* %11
store i32 %72, i32* %5
br label %73
73: ; preds = %67, %65, %48, %39, %23
%74 = load i32, i32* %5
ret i32 %74
}

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