#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 char *next_in;
  unsigned int avail_in;
  int total_out;
  unsigned char *next_out;
  unsigned int avail_out;
  void *zfree;
  void *zalloc;
};
typedef TYPE_1__ z_stream;

/* Variables and functions */
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int /*<<< orphan*/ Z_SYNC_FLUSH;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit2(TYPE_1__ *, int);
int bundle_inflate(char *dest, unsigned char *src, unsigned int src_len,
                   unsigned int len) {
  if (src_len == 0) {
    return 0;
  }
  bool done = false;
  int status;
  z_stream strm;
  strm.next_in = src;
  strm.avail_in = src_len;
  strm.total_out = 0;
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  if (inflateInit2(&strm, (15 + 32)) != Z_OK) {
    return -1;
  }
  while (!done) {
    strm.next_out = (unsigned char *)dest + strm.total_out;
    strm.avail_out = len - (int)strm.total_out;
    status = inflate(&strm, Z_SYNC_FLUSH);
    if (status == Z_STREAM_END) {
      done = true;
    } else if (status != Z_OK) {
      break;
    }
  }
  if (inflateEnd(&strm) != Z_OK) {
    return -1;
  }
  return done ? 0 : -1;
}


x86 assembly (clang, -O0):
<bundle_inflate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    115c <bundle_inflate+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    127b <bundle_inflate+0x14b>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x50(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
lea    -0x58(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <inflateInit2@plt>
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%eax
je     11bd <bundle_inflate+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    127b <bundle_inflate+0x14b>
jmp    11c2 <bundle_inflate+0x92>
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d8 <bundle_inflate+0xa8>
jmp    1244 <bundle_inflate+0x114>
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x4c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%eax
jne    1223 <bundle_inflate+0xf3>
movl   $0x1,-0x24(%rbp)
jmp    123f <bundle_inflate+0x10f>
mov    -0x28(%rbp),%eax
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%eax
je     123a <bundle_inflate+0x10a>
jmp    1244 <bundle_inflate+0x114>
jmp    123f <bundle_inflate+0x10f>
jmp    11c2 <bundle_inflate+0x92>
lea    -0x58(%rbp),%rdi
call   1050 <inflateEnd@plt>
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%eax
je     1268 <bundle_inflate+0x138>
movl   $0xffffffff,-0x4(%rbp)
jmp    127b <bundle_inflate+0x14b>
mov    -0x24(%rbp),%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bundle_inflate>:
test   %edx,%edx
je     124e <bundle_inflate+0x11e>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%r13d
mov    %rdi,%rbp
mov    %rsi,0x8(%rsp)
mov    %edx,0x10(%rsp)
movl   $0x0,0x14(%rsp)
mov    0x2e64(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x2f,%esi
call   1040 <inflateInit2@plt>
mov    %eax,%ecx
mov    0x2e67(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%ecx
jne    123f <bundle_inflate+0x10f>
movslq 0x14(%rsp),%rax
mov    %r13d,%ecx
sub    %eax,%ecx
add    %rbp,%rax
mov    %rax,0x18(%rsp)
mov    %ecx,0x20(%rsp)
mov    0x2e25(%rip),%r12
mov    (%r12),%esi
lea    0x8(%rsp),%rdi
call   1030 <inflate@plt>
mov    0x2e18(%rip),%r15
cmp    (%r15),%eax
sete   %cl
je     121a <bundle_inflate+0xea>
mov    $0x1,%bl
lea    0x8(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    0x2e09(%rip),%rdx
cmp    (%rdx),%eax
jne    121f <bundle_inflate+0xef>
mov    %ecx,%ebx
xor    $0x1,%bl
movslq 0x14(%rsp),%rax
mov    %r13d,%ecx
sub    %eax,%ecx
add    %rbp,%rax
mov    %rax,0x18(%rsp)
mov    %ecx,0x20(%rsp)
mov    (%r12),%esi
mov    %r14,%rdi
call   1030 <inflate@plt>
cmp    (%r15),%eax
sete   %cl
jne    11e0 <bundle_inflate+0xb0>
xor    $0x1,%cl
mov    %ecx,%ebx
lea    0x8(%rsp),%rdi
call   1050 <inflateEnd@plt>
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
or     %bl,%al
movzbl %al,%eax
and    $0x1,%eax
neg    %eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
%struct.TYPE_5__ = type { i8*, i32, i32, i8*, i32, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_SYNC_FLUSH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @bundle_inflate(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.TYPE_5__
%6 = icmp eq i32 %2, 0
br i1 %6, label %57, label %7
7: ; preds = %4
%8 = bitcast %struct.TYPE_5__* %5 to i8*
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
store i8* %1, i8** %9
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
store i32 %2, i32* %10
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 2
store i32 0, i32* %11
%12 = load i8*, i8** @Z_NULL
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 6
store i8* %12, i8** %13
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 5
store i8* %12, i8** %14
%15 = call i32 @inflateInit2(%struct.TYPE_5__* %5, i32 47)
%16 = load i32, i32* @Z_OK
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %55
18: ; preds = %7
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 3
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 4
%21 = load i32, i32* %11
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8* %23, i8** %19
%24 = sub i32 %3, %21
store i32 %24, i32* %20
%25 = load i32, i32* @Z_SYNC_FLUSH
%26 = call i32 @inflate(%struct.TYPE_5__* %5, i32 %25)
%27 = load i32, i32* @Z_STREAM_END
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %38, %18
%30 = phi i1 [ %28, %18 ], [ %47, %38 ]
%31 = xor i1 %30, true
br label %48
32: ; preds = %18, %38
%33 = phi i1 [ %47, %38 ], [ %28, %18 ]
%34 = phi i32 [ %45, %38 ], [ %26, %18 ]
%35 = phi i1 [ %39, %38 ], [ true, %18 ]
%36 = load i32, i32* @Z_OK
%37 = icmp eq i32 %34, %36
br i1 %37, label %38, label %48
38: ; preds = %32
%39 = xor i1 %33, true
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %0, i64 %41
store i8* %42, i8** %19
%43 = sub i32 %3, %40
store i32 %43, i32* %20
%44 = load i32, i32* @Z_SYNC_FLUSH
%45 = call i32 @inflate(%struct.TYPE_5__* %5, i32 %44)
%46 = load i32, i32* @Z_STREAM_END
%47 = icmp eq i32 %45, %46
br i1 %47, label %29, label %32
48: ; preds = %32, %29
%49 = phi i1 [ %31, %29 ], [ %35, %32 ]
%50 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
%51 = load i32, i32* @Z_OK
%52 = icmp ne i32 %50, %51
%53 = or i1 %49, %52
%54 = sext i1 %53 to i32
br label %55
55: ; preds = %48, %7
%56 = phi i32 [ -1, %7 ], [ %54, %48 ]
br label %57
57: ; preds = %4, %55
%58 = phi i32 [ %56, %55 ], [ 0, %4 ]
ret i32 %58
}