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

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