#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_6__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  scalar_t__ total_out;
  void *avail_out;
  int /*<<< orphan*/ *next_out;
  void *avail_in;
  int /*<<< orphan*/ *next_in;
};
typedef TYPE_1__ z_stream;
typedef scalar_t__ uLong;
typedef void *uInt;
typedef int /*<<< orphan*/ Byte;

/* Variables and functions */
scalar_t__ MAX_WBITS;
int /*<<< orphan*/ Z_NO_FLUSH;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit2(TYPE_1__ *, scalar_t__);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int my_inflate(const Byte *compr, uLong compr_len, Byte *uncompr,
               uLong uncompr_len) {
  int err;
  z_stream stream;
  memset(&stream, 0, sizeof(z_stream));
  stream.next_in = (Byte *)compr;
  stream.avail_in = (uInt)compr_len;
  err = inflateInit2(&stream, 16 + MAX_WBITS);
  if (err != Z_OK)
    return 1;
  for (;;) {
    stream.next_out = uncompr;
    stream.avail_out = (uInt)uncompr_len;
    err = inflate(&stream, Z_NO_FLUSH);
    if (err == Z_STREAM_END)
      break;
    if (err != Z_OK) {
      printf("%d\n", err);
      return 2;
    }
  }
  err = inflateEnd(&stream);
  if (err != Z_OK)
    return 3;
  if (stream.total_out != uncompr_len)
    return 4;
  return 0;
}


x86 assembly (clang, -O0):
<my_inflate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rsi
add    $0x10,%rsi
lea    -0x58(%rbp),%rdi
call   1040 <inflateInit2@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%eax
je     11c0 <my_inflate+0x70>
movl   $0x1,-0x4(%rbp)
jmp    127e <my_inflate+0x12e>
jmp    11c5 <my_inflate+0x75>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <my_inflate+0xb1>
jmp    1233 <my_inflate+0xe3>
mov    -0x2c(%rbp),%eax
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%eax
je     122e <my_inflate+0xde>
mov    -0x2c(%rbp),%esi
lea    0xde3(%rip),%rdi
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    127e <my_inflate+0x12e>
jmp    11c5 <my_inflate+0x75>
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2da7(%rip),%rcx
cmp    (%rcx),%eax
je     125d <my_inflate+0x10d>
movl   $0x3,-0x4(%rbp)
jmp    127e <my_inflate+0x12e>
mov    -0x58(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1277 <my_inflate+0x127>
movl   $0x4,-0x4(%rbp)
jmp    127e <my_inflate+0x12e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_inflate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsp,%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    %r12,0x20(%rsp)
mov    %r15,0x18(%rsp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%rsi
add    $0x10,%rsi
mov    %r13,%rdi
call   1040 <inflateInit2@plt>
mov    %eax,%ecx
mov    0x2e4b(%rip),%r12
mov    $0x1,%eax
cmp    (%r12),%ecx
jne    1227 <my_inflate+0xd7>
mov    0x2e11(%rip),%r13
mov    %rsp,%r15
mov    0x2e1f(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,0x10(%rsp)
mov    %r14,0x8(%rsp)
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1030 <inflate@plt>
cmp    0x0(%rbp),%eax
je     1206 <my_inflate+0xb6>
cmp    (%r12),%eax
je     11d0 <my_inflate+0x80>
lea    0xe08(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    $0x2,%eax
jmp    1227 <my_inflate+0xd7>
mov    %rsp,%rdi
call   1070 <inflateEnd@plt>
mov    %eax,%ecx
mov    $0x3,%eax
cmp    (%r12),%ecx
jne    1227 <my_inflate+0xd7>
xor    %eax,%eax
cmp    %r14,(%rsp)
setne  %al
shl    $0x2,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i64, i8*, i32*, i8*, i32* }
@MAX_WBITS = global i64 0
@Z_OK = global i32 0
@Z_NO_FLUSH = global i32 0
@Z_STREAM_END = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @my_inflate(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 i32
%11 = alloca %struct.TYPE_6__
store i32* %0, i32** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i64 %3, i64* %9
%12 = call i32 @memset(%struct.TYPE_6__* %11, i32 0, i32 40)
%13 = load i32*, i32** %6
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 4
store i32* %13, i32** %14
%15 = load i64, i64* %7
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 3
store i8* %16, i8** %17
%18 = load i64, i64* @MAX_WBITS
%19 = add nsw i64 16, %18
%20 = call i32 @inflateInit2(%struct.TYPE_6__* %11, i64 %19)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = load i32, i32* @Z_OK
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 1, i32* %5
br label %59
25: ; preds = %4
br label %26
26: ; preds = %45, %25
%27 = load i32*, i32** %8
%28 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 2
store i32* %27, i32** %28
%29 = load i64, i64* %9
%30 = inttoptr i64 %29 to i8*
%31 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 1
store i8* %30, i8** %31
%32 = load i32, i32* @Z_NO_FLUSH
%33 = call i32 @inflate(%struct.TYPE_6__* %11, i32 %32)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = load i32, i32* @Z_STREAM_END
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %26
br label %46
38: ; preds = %26
%39 = load i32, i32* %10
%40 = load i32, i32* @Z_OK
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i32, i32* %10
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %43)
store i32 2, i32* %5
br label %59
45: ; preds = %38
br label %26
46: ; preds = %37
%47 = call i32 @inflateEnd(%struct.TYPE_6__* %11)
store i32 %47, i32* %10
%48 = load i32, i32* %10
%49 = load i32, i32* @Z_OK
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %46
store i32 3, i32* %5
br label %59
52: ; preds = %46
%53 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 0
%54 = load i64, i64* %53
%55 = load i64, i64* %9
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %58
57: ; preds = %52
store i32 4, i32* %5
br label %59
58: ; preds = %52
store i32 0, i32* %5
br label %59
59: ; preds = %58, %57, %51, %42, %24
%60 = load i32, i32* %5
ret i32 %60
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i64, i8*, i32*, i8*, i32* }
@MAX_WBITS = global i64 0
@Z_OK = global i32 0
@Z_NO_FLUSH = global i32 0
@Z_STREAM_END = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @my_inflate(i32* %0, i64 %1, i32* %2, i64 %3) {
%5 = alloca %struct.TYPE_6__
%6 = bitcast %struct.TYPE_6__* %5 to i8*
%7 = call i32 @memset(%struct.TYPE_6__* %5, i32 0, i32 40)
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 4
store i32* %0, i32** %8
%9 = inttoptr i64 %1 to i8*
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 3
store i8* %9, i8** %10
%11 = load i64, i64* @MAX_WBITS
%12 = add nsw i64 %11, 16
%13 = call i32 @inflateInit2(%struct.TYPE_6__* %5, i64 %12)
%14 = load i32, i32* @Z_OK
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %39
16: ; preds = %4
%17 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 2
%18 = inttoptr i64 %3 to i8*
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 1
br label %20
20: ; preds = %16, %25
store i32* %2, i32** %17
store i8* %18, i8** %19
%21 = load i32, i32* @Z_NO_FLUSH
%22 = call i32 @inflate(%struct.TYPE_6__* %5, i32 %21)
%23 = load i32, i32* @Z_STREAM_END
%24 = icmp eq i32 %22, %23
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i32, i32* @Z_OK
%27 = icmp eq i32 %22, %26
br i1 %27, label %20, label %28
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %39
30: ; preds = %20
%31 = call i32 @inflateEnd(%struct.TYPE_6__* %5)
%32 = load i32, i32* @Z_OK
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i64 0, i32 0
%36 = load i64, i64* %35
%37 = icmp eq i64 %36, %3
%38 = select i1 %37, i32 0, i32 4
br label %39
39: ; preds = %34, %30, %4, %28
%40 = phi i32 [ 2, %28 ], [ 1, %4 ], [ 3, %30 ], [ %38, %34 ]
ret i32 %40
}