#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 */
int /*<<< orphan*/ Z_NO_FLUSH;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
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 = inflateInit(&stream);
  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   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x58(%rbp),%rdi
call   1060 <inflateInit@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
je     11b2 <my_inflate+0x62>
movl   $0x1,-0x4(%rbp)
jmp    1270 <my_inflate+0x120>
jmp    11b7 <my_inflate+0x67>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%eax
jne    11f3 <my_inflate+0xa3>
jmp    1225 <my_inflate+0xd5>
mov    -0x2c(%rbp),%eax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%eax
je     1220 <my_inflate+0xd0>
mov    -0x2c(%rbp),%esi
lea    0xdf1(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1270 <my_inflate+0x120>
jmp    11b7 <my_inflate+0x67>
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2db5(%rip),%rcx
cmp    (%rcx),%eax
je     124f <my_inflate+0xff>
movl   $0x3,-0x4(%rbp)
jmp    1270 <my_inflate+0x120>
mov    -0x58(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1269 <my_inflate+0x119>
movl   $0x4,-0x4(%rbp)
jmp    1270 <my_inflate+0x120>
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   1050 <memset@plt>
mov    %r12,0x20(%rsp)
mov    %r15,0x18(%rsp)
mov    %r13,%rdi
call   1060 <inflateInit@plt>
mov    %eax,%ecx
mov    0x2e59(%rip),%r12
mov    $0x1,%eax
cmp    (%r12),%ecx
jne    1217 <my_inflate+0xc7>
mov    0x2e27(%rip),%r13
mov    %rsp,%r15
mov    0x2e2d(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,0x10(%rsp)
mov    %r14,0x8(%rsp)
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1030 <inflate@plt>
cmp    0x0(%rbp),%eax
je     11f6 <my_inflate+0xa6>
cmp    (%r12),%eax
je     11c0 <my_inflate+0x70>
lea    0xe18(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x2,%eax
jmp    1217 <my_inflate+0xc7>
mov    %rsp,%rdi
call   1070 <inflateEnd@plt>
mov    %eax,%ecx
mov    $0x3,%eax
cmp    (%r12),%ecx
jne    1217 <my_inflate+0xc7>
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* }
@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 = call i32 @inflateInit(%struct.TYPE_6__* %11)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = load i32, i32* @Z_OK
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %4
store i32 1, i32* %5
br label %57
23: ; preds = %4
br label %24
24: ; preds = %43, %23
%25 = load i32*, i32** %8
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 2
store i32* %25, i32** %26
%27 = load i64, i64* %9
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 1
store i8* %28, i8** %29
%30 = load i32, i32* @Z_NO_FLUSH
%31 = call i32 @inflate(%struct.TYPE_6__* %11, i32 %30)
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = load i32, i32* @Z_STREAM_END
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %24
br label %44
36: ; preds = %24
%37 = load i32, i32* %10
%38 = load i32, i32* @Z_OK
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %10
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %41)
store i32 2, i32* %5
br label %57
43: ; preds = %36
br label %24
44: ; preds = %35
%45 = call i32 @inflateEnd(%struct.TYPE_6__* %11)
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = load i32, i32* @Z_OK
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %44
store i32 3, i32* %5
br label %57
50: ; preds = %44
%51 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* %9
%54 = icmp ne i64 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %50
store i32 4, i32* %5
br label %57
56: ; preds = %50
store i32 0, i32* %5
br label %57
57: ; preds = %56, %55, %49, %40, %22
%58 = load i32, i32* %5
ret i32 %58
}

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