#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 char const *next_in;
  unsigned int avail_out;
  unsigned char *next_out;
  int /*<<< orphan*/ opaque;
  int /*<<< orphan*/ zfree;
  int /*<<< orphan*/ zalloc;
};
typedef TYPE_1__ z_stream;

/* Variables and functions */
size_t UINT_MAX;
int /*<<< orphan*/ Z_FINISH;
int /*<<< orphan*/ Z_NULL;
int Z_OK;
int Z_STREAM_END;
int /*<<< orphan*/ bgen_error(char *, ...);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int /*<<< orphan*/ zError(int);
int bgen_unzlib(char const *src, size_t src_size, char **dst,
                size_t *dst_size) {
  z_stream strm = {
      .zalloc = Z_NULL,
      .zfree = Z_NULL,
      .opaque = Z_NULL,
      .avail_in = 0,
      .next_in = (unsigned char const *)src,
  };
  int e = inflateInit(&strm);
  if (e != Z_OK) {
    bgen_error("zlib failed to init (%s)", zError(e));
    goto err;
  }
  if (src_size > UINT_MAX) {
    bgen_error("zlib src_size overflow");
    goto err;
  }
  strm.avail_in = (unsigned)src_size;
  if (*dst_size > UINT_MAX) {
    bgen_error("zlib *dst_size overflow");
    goto err;
  }
  strm.avail_out = (unsigned)*dst_size;
  strm.next_out = (unsigned char *)*dst;
  e = inflate(&strm, Z_FINISH);
  if (e != Z_STREAM_END) {
    bgen_error("zlib failed to inflate (%s)", zError(e));
    goto err;
  }
  if (inflateEnd(&strm) != Z_OK) {
    bgen_error("zlib failed to inflateEnd (%s)", zError(e));
    return 1;
  }
  return 0;
err:
  inflateEnd(&strm);
  return 1;
}


x86 assembly (clang, -O0):
<bgen_unzlib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
lea    -0x58(%rbp),%rdi
call   1060 <inflateInit@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
je     11e5 <bgen_unzlib+0x95>
mov    -0x5c(%rbp),%edi
call   1050 <zError@plt>
mov    %eax,%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <bgen_error@plt>
jmp    12de <bgen_unzlib+0x18e>
mov    -0x18(%rbp),%rax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%rax
jbe    120c <bgen_unzlib+0xbc>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <bgen_error@plt>
jmp    12de <bgen_unzlib+0x18e>
mov    -0x18(%rbp),%rax
mov    %eax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%rax
jbe    123d <bgen_unzlib+0xed>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <bgen_error@plt>
jmp    12de <bgen_unzlib+0x18e>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1040 <inflate@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x2d6f(%rip),%rcx
cmp    (%rcx),%eax
je     1296 <bgen_unzlib+0x146>
mov    -0x5c(%rbp),%edi
call   1050 <zError@plt>
mov    %eax,%esi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1030 <bgen_error@plt>
jmp    12de <bgen_unzlib+0x18e>
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    0x2d4a(%rip),%rcx
cmp    (%rcx),%eax
je     12d2 <bgen_unzlib+0x182>
mov    -0x5c(%rbp),%edi
call   1050 <zError@plt>
mov    %eax,%esi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1030 <bgen_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ee <bgen_unzlib+0x19e>
movl   $0x0,-0x4(%rbp)
jmp    12ee <bgen_unzlib+0x19e>
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bgen_unzlib>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
movl   $0x0,0x8(%rsp)
mov    %rdi,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    %eax,0x2c(%rsp)
mov    %eax,0x30(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <inflateInit@plt>
mov    0x2e48(%rip),%r12
cmp    (%r12),%eax
jne    11c6 <bgen_unzlib+0x76>
mov    0x2e23(%rip),%rax
mov    (%rax),%rax
cmp    %rbx,%rax
jae    11df <bgen_unzlib+0x8f>
lea    0xe55(%rip),%rdi
jmp    11f2 <bgen_unzlib+0xa2>
mov    %eax,%edi
call   1050 <zError@plt>
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <bgen_error@plt>
jmp    11f9 <bgen_unzlib+0xa9>
mov    %ebx,0x8(%rsp)
mov    (%r15),%rcx
cmp    %rax,%rcx
jbe    1214 <bgen_unzlib+0xc4>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1030 <bgen_error@plt>
lea    0x8(%rsp),%rdi
call   1070 <inflateEnd@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %ecx,0x18(%rsp)
mov    (%r14),%rax
mov    %rax,0x20(%rsp)
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1040 <inflate@plt>
mov    %eax,%ebx
mov    0x2da4(%rip),%rax
cmp    (%rax),%ebx
jne    126d <bgen_unzlib+0x11d>
lea    0x8(%rsp),%rdi
call   1070 <inflateEnd@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    (%r12),%ecx
je     1208 <bgen_unzlib+0xb8>
mov    %ebx,%edi
call   1050 <zError@plt>
lea    0xe02(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <bgen_error@plt>
jmp    1203 <bgen_unzlib+0xb3>
mov    %ebx,%edi
call   1050 <zError@plt>
lea    0xdcd(%rip),%rdi
jmp    11d4 <bgen_unzlib+0x84>

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i8*, i32, i8*, i32, i32, i32 }
@Z_NULL = global i32 0
@Z_OK = global i32 0
@.str = [25 x i8] c"zlib failed to init (%s)\00"
@UINT_MAX = global i64 0
@.str.1 = [23 x i8] c"zlib src_size overflow\00"
@.str.2 = [24 x i8] c"zlib *dst_size overflow\00"
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.3 = [28 x i8] c"zlib failed to inflate (%s)\00"
@.str.4 = [31 x i8] c"zlib failed to inflateEnd (%s)\00"
define i32 @bgen_unzlib(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 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 0
store i32 0, i32* %12
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 1
%14 = load i8*, i8** %6
store i8* %14, i8** %13
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 2
store i32 0, i32* %15
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 3
store i8* null, i8** %16
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 4
%18 = load i32, i32* @Z_NULL
store i32 %18, i32* %17
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 5
%20 = load i32, i32* @Z_NULL
store i32 %20, i32* %19
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 6
%22 = load i32, i32* @Z_NULL
store i32 %22, i32* %21
%23 = call i32 @inflateInit(%struct.TYPE_5__* %10)
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = load i32, i32* @Z_OK
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %4
%28 = load i32, i32* %11
%29 = call i32 @zError(i32 %28)
%30 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %73
31: ; preds = %4
%32 = load i64, i64* %7
%33 = load i64, i64* @UINT_MAX
%34 = icmp ugt i64 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %73
37: ; preds = %31
%38 = load i64, i64* %7
%39 = trunc i64 %38 to i32
%40 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i64*, i64** %9
%42 = load i64, i64* %41
%43 = load i64, i64* @UINT_MAX
%44 = icmp ugt i64 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %73
47: ; preds = %37
%48 = load i64*, i64** %9
%49 = load i64, i64* %48
%50 = trunc i64 %49 to i32
%51 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i8**, i8*** %8
%53 = load i8*, i8** %52
%54 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 3
store i8* %53, i8** %54
%55 = load i32, i32* @Z_FINISH
%56 = call i32 @inflate(%struct.TYPE_5__* %10, i32 %55)
store i32 %56, i32* %11
%57 = load i32, i32* %11
%58 = load i32, i32* @Z_STREAM_END
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %64
60: ; preds = %47
%61 = load i32, i32* %11
%62 = call i32 @zError(i32 %61)
%63 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %62)
br label %73
64: ; preds = %47
%65 = call i32 @inflateEnd(%struct.TYPE_5__* %10)
%66 = load i32, i32* @Z_OK
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i32, i32* %11
%70 = call i32 @zError(i32 %69)
%71 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %70)
store i32 1, i32* %5
br label %75
72: ; preds = %64
store i32 0, i32* %5
br label %75
73: ; preds = %60, %45, %35, %27
%74 = call i32 @inflateEnd(%struct.TYPE_5__* %10)
store i32 1, i32* %5
br label %75
75: ; preds = %73, %72, %68
%76 = load i32, i32* %5
ret i32 %76
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i8*, i32, i8*, i32, i32, i32 }
@Z_NULL = global i32 0
@Z_OK = global i32 0
@.str = [25 x i8] c"zlib failed to init (%s)\00"
@UINT_MAX = global i64 0
@.str.1 = [23 x i8] c"zlib src_size overflow\00"
@.str.2 = [24 x i8] c"zlib *dst_size overflow\00"
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.3 = [28 x i8] c"zlib failed to inflate (%s)\00"
@.str.4 = [31 x i8] c"zlib failed to inflateEnd (%s)\00"
define i32 @bgen_unzlib(i8* %0, i64 %1, i8** nocapture %2, i64* nocapture %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 0
store i32 0, i32* %7
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
store i8* %0, i8** %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 2
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 3
store i8* null, i8** %10
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 4
%12 = load i32, i32* @Z_NULL
store i32 %12, i32* %11
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 5
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 6
store i32 %12, i32* %14
%15 = call i32 @inflateInit(%struct.TYPE_5__* %5)
%16 = load i32, i32* @Z_OK
%17 = icmp eq i32 %15, %16
br i1 %17, label %21, label %18
18: ; preds = %4
%19 = call i32 @zError(i32 %15)
%20 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %49
21: ; preds = %4
%22 = load i64, i64* @UINT_MAX
%23 = icmp ult i64 %22, %1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %49
26: ; preds = %21
%27 = trunc i64 %1 to i32
store i32 %27, i32* %7
%28 = load i64, i64* %3
%29 = icmp ugt i64 %28, %22
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %49
32: ; preds = %26
%33 = trunc i64 %28 to i32
store i32 %33, i32* %9
%34 = load i8*, i8** %2
store i8* %34, i8** %10
%35 = load i32, i32* @Z_FINISH
%36 = call i32 @inflate(%struct.TYPE_5__* %5, i32 %35)
%37 = load i32, i32* @Z_STREAM_END
%38 = icmp eq i32 %36, %37
br i1 %38, label %42, label %39
39: ; preds = %32
%40 = call i32 @zError(i32 %36)
%41 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %49
42: ; preds = %32
%43 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
%44 = load i32, i32* @Z_OK
%45 = icmp eq i32 %43, %44
br i1 %45, label %51, label %46
46: ; preds = %42
%47 = call i32 @zError(i32 %36)
%48 = call i32 (i8*, ...) @bgen_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %51
49: ; preds = %39, %30, %24, %18
%50 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
br label %51
51: ; preds = %42, %49, %46
%52 = phi i32 [ 1, %49 ], [ 1, %46 ], [ 0, %42 ]
ret i32 %52
}