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

/* Variables and functions */
#define Z_DATA_ERROR 130
int Z_ERRNO;
#define Z_MEM_ERROR 129
#define Z_NEED_DICT 128
int /*<<< orphan*/ Z_NO_FLUSH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int Z_STREAM_ERROR;
scalar_t__ ferror(int /*<<< orphan*/ *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int zlib_inflate(FILE *fin, FILE *fout) {
  z_stream strm;
  unsigned char bin[0x1000];
  unsigned char bout[0x1000];
  int nleft, result;
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  strm.avail_in = 0;
  strm.next_in = Z_NULL;
  result = inflateInit(&strm);
  if (result != Z_OK)
    return result;
  do {
    strm.avail_in = fread(bin, 1, 0x1000, fin);
    if (ferror(fin)) {
      inflateEnd(&strm);
      return Z_ERRNO;
    }
    if (strm.avail_in == 0)
      break;
    strm.next_in = bin;
    do {
      strm.avail_out = 0x1000;
      strm.next_out = bout;
      result = inflate(&strm, Z_NO_FLUSH);
      if (result == Z_STREAM_ERROR)
        return result;
      switch (result) {
      case Z_NEED_DICT:
        result = Z_DATA_ERROR;
      case Z_DATA_ERROR:
      case Z_MEM_ERROR:
        inflateEnd(&strm);
        return result;
        break;
      }
      nleft = 0x1000 - strm.avail_out;
      if ((fwrite(bout, 1, nleft, fout) != nleft) || ferror(fout)) {
        inflateEnd(&strm);
        return Z_ERRNO;
      }
    } while (strm.avail_out == 0);
  } while (result != Z_STREAM_END);
  inflateEnd(&strm);
  if (result != Z_STREAM_END)
    return Z_DATA_ERROR;
  return Z_OK;
}


x86 assembly (clang, -O0):
<zlib_inflate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x50(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <inflateInit@plt>
mov    %eax,-0x2058(%rbp)
mov    -0x2058(%rbp),%eax
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
je     11e5 <zlib_inflate+0x85>
mov    -0x2058(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13b4 <zlib_inflate+0x254>
jmp    11ea <zlib_inflate+0x8a>
lea    -0x1050(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1050 <fread@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1235 <zlib_inflate+0xd5>
lea    -0x50(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13b4 <zlib_inflate+0x254>
cmpq   $0x0,-0x50(%rbp)
jne    1245 <zlib_inflate+0xe5>
jmp    137e <zlib_inflate+0x21e>
lea    -0x1050(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x1000,-0x40(%rbp)
lea    -0x2050(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x2058(%rbp)
mov    -0x2058(%rbp),%eax
mov    0x2d41(%rip),%rcx
cmp    (%rcx),%eax
jne    129d <zlib_inflate+0x13d>
mov    -0x2058(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13b4 <zlib_inflate+0x254>
mov    -0x2058(%rbp),%eax
mov    %eax,-0x205c(%rbp)
sub    $0x80,%eax
je     12d2 <zlib_inflate+0x172>
jmp    12b9 <zlib_inflate+0x159>
mov    -0x205c(%rbp),%eax
add    $0xffffff7f,%eax
sub    $0x2,%eax
jb     12dc <zlib_inflate+0x17c>
jmp    12f3 <zlib_inflate+0x193>
movl   $0x82,-0x2058(%rbp)
lea    -0x50(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    -0x2058(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13b4 <zlib_inflate+0x254>
mov    $0x1000,%eax
sub    -0x40(%rbp),%eax
mov    %eax,-0x2054(%rbp)
lea    -0x2050(%rbp),%rdi
mov    -0x2054(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
cmp    -0x2054(%rbp),%eax
jne    133b <zlib_inflate+0x1db>
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1355 <zlib_inflate+0x1f5>
lea    -0x50(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13b4 <zlib_inflate+0x254>
jmp    135a <zlib_inflate+0x1fa>
cmpl   $0x0,-0x40(%rbp)
je     1250 <zlib_inflate+0xf0>
jmp    1369 <zlib_inflate+0x209>
mov    -0x2058(%rbp),%eax
mov    0x2c6a(%rip),%rcx
cmp    (%rcx),%eax
jne    11ea <zlib_inflate+0x8a>
lea    -0x50(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    -0x2058(%rbp),%eax
mov    0x2c4c(%rip),%rcx
cmp    (%rcx),%eax
je     13a8 <zlib_inflate+0x248>
movl   $0x82,-0x4(%rbp)
jmp    13b4 <zlib_inflate+0x254>
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zlib_inflate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2048,%rsp
mov    %rsi,%r14
mov    %rdi,0x38(%rsp)
mov    0x2e38(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
movq   $0x0,(%rsp)
mov    %rax,0x8(%rsp)
mov    %rsp,%rdi
call   1060 <inflateInit@plt>
mov    %eax,%ebx
mov    0x2e40(%rip),%rax
cmp    (%rax),%ebx
jne    12dd <zlib_inflate+0x17d>
lea    0x1040(%rsp),%r12
lea    0x40(%rsp),%r13
mov    %r12,%r15
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    0x38(%rsp),%rbp
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rax,%r12
mov    %rax,(%rsp)
mov    %rbp,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12b6 <zlib_inflate+0x156>
test   %r12,%r12
je     1295 <zlib_inflate+0x135>
mov    %r15,%r12
mov    %r15,0x8(%rsp)
mov    0x2dae(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0x1000,0x10(%rsp)
mov    %r13,0x18(%rsp)
mov    (%r15),%esi
mov    %rsp,%rdi
call   1030 <inflate@plt>
mov    %eax,%ebx
mov    0x2d87(%rip),%rax
cmp    (%rax),%ebx
je     12dd <zlib_inflate+0x17d>
mov    %ebx,%eax
add    $0xffffff80,%eax
cmp    $0x2,%eax
jbe    12c9 <zlib_inflate+0x169>
mov    $0x1000,%ebp
sub    0x10(%rsp),%ebp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    %ebp,%eax
jne    12b6 <zlib_inflate+0x156>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12b6 <zlib_inflate+0x156>
cmpl   $0x0,0x10(%rsp)
je     1220 <zlib_inflate+0xc0>
mov    0x2d53(%rip),%rax
cmp    (%rax),%ebx
jne    11c5 <zlib_inflate+0x65>
mov    %rsp,%rdi
call   1070 <inflateEnd@plt>
mov    0x2d3c(%rip),%rax
cmp    (%rax),%ebx
mov    $0x82,%ebx
jne    12dd <zlib_inflate+0x17d>
mov    0x2d3c(%rip),%rax
jmp    12c5 <zlib_inflate+0x165>
mov    %rsp,%rdi
call   1070 <inflateEnd@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%ebx
jmp    12dd <zlib_inflate+0x17d>
cltq
lea    0xd2e(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
mov    %rsp,%rdi
call   1070 <inflateEnd@plt>
mov    %ebx,%eax
add    $0x2048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64, i8*, i32, i8*, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_ERRNO = global i32 0
@Z_NO_FLUSH = global i32 0
@Z_STREAM_ERROR = global i32 0
@Z_STREAM_END = global i32 0
define i32 @zlib_inflate(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.TYPE_5__
%7 = alloca [4096 x i8]
%8 = alloca [4096 x i8]
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%11 = load i8*, i8** @Z_NULL
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 6
store i8* %11, i8** %12
%13 = load i8*, i8** @Z_NULL
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 5
store i8* %13, i8** %14
%15 = load i8*, i8** @Z_NULL
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 4
store i8* %15, i8** %16
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 0
store i64 0, i64* %17
%18 = load i8*, i8** @Z_NULL
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
store i8* %18, i8** %19
%20 = call i32 @inflateInit(%struct.TYPE_5__* %6)
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 %26
24: ; preds = %2
%25 = load i32, i32* %10
store i32 %25, i32* %3
br label %98
26: ; preds = %2
br label %27
27: ; preds = %86, %26
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%29 = load i32*, i32** %4
%30 = call i64 @fread(i8* %28, i32 1, i32 4096, i32* %29)
%31 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 0
store i64 %30, i64* %31
%32 = load i32*, i32** %4
%33 = call i64 @ferror(i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = call i32 @inflateEnd(%struct.TYPE_5__* %6)
%37 = load i32, i32* @Z_ERRNO
store i32 %37, i32* %3
br label %98
38: ; preds = %27
%39 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 0
%40 = load i64, i64* %39
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
br label %90
43: ; preds = %38
%44 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%45 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
store i8* %44, i8** %45
br label %46
46: ; preds = %81, %43
%47 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 2
store i32 4096, i32* %47
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%49 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 3
store i8* %48, i8** %49
%50 = load i32, i32* @Z_NO_FLUSH
%51 = call i32 @inflate(%struct.TYPE_5__* %6, i32 %50)
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = load i32, i32* @Z_STREAM_ERROR
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %46
%56 = load i32, i32* %10
store i32 %56, i32* %3
br label %98
57: ; preds = %46
%58 = load i32, i32* %10
switch i32 %58, label %63 [
i32 128, label %59
i32 130, label %60
i32 129, label %60
]
59: ; preds = %57
store i32 130, i32* %10
br label %60
60: ; preds = %57, %57, %59
%61 = call i32 @inflateEnd(%struct.TYPE_5__* %6)
%62 = load i32, i32* %10
store i32 %62, i32* %3
br label %98
63: ; preds = %57
%64 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 2
%65 = load i32, i32* %64
%66 = sub nsw i32 4096, %65
store i32 %66, i32* %9
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%68 = load i32, i32* %9
%69 = load i32*, i32** %5
%70 = call i32 @fwrite(i8* %67, i32 1, i32 %68, i32* %69)
%71 = load i32, i32* %9
%72 = icmp ne i32 %70, %71
br i1 %72, label %77, label %73
73: ; preds = %63
%74 = load i32*, i32** %5
%75 = call i64 @ferror(i32* %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %73, %63
%78 = call i32 @inflateEnd(%struct.TYPE_5__* %6)
%79 = load i32, i32* @Z_ERRNO
store i32 %79, i32* %3
br label %98
80: ; preds = %73
br label %81
81: ; preds = %80
%82 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 2
%83 = load i32, i32* %82
%84 = icmp eq i32 %83, 0
br i1 %84, label %46, label %85
85: ; preds = %81
br label %86
86: ; preds = %85
%87 = load i32, i32* %10
%88 = load i32, i32* @Z_STREAM_END
%89 = icmp ne i32 %87, %88
br i1 %89, label %27, label %90
90: ; preds = %86, %42
%91 = call i32 @inflateEnd(%struct.TYPE_5__* %6)
%92 = load i32, i32* %10
%93 = load i32, i32* @Z_STREAM_END
%94 = icmp ne i32 %92, %93
br i1 %94, label %95, label %96
95: ; preds = %90
store i32 130, i32* %3
br label %98
96: ; preds = %90
%97 = load i32, i32* @Z_OK
store i32 %97, i32* %3
br label %98
98: ; preds = %96, %95, %77, %60, %55, %35, %24
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i64, i8*, i32, i8*, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_ERRNO = global i32 0
@Z_NO_FLUSH = global i32 0
@Z_STREAM_ERROR = global i32 0
@Z_STREAM_END = global i32 0
@switch.table.zlib_inflate = [3 x i32] [i32 130, i32 129, i32 130]
define i32 @zlib_inflate(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca %struct.TYPE_5__
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = bitcast %struct.TYPE_5__* %3 to i8*
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** @Z_NULL
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 6
store i8* %9, i8** %10
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 5
store i8* %9, i8** %11
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 4
store i8* %9, i8** %12
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 0
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 1
store i8* %9, i8** %14
%15 = call i32 @inflateInit(%struct.TYPE_5__* %3)
%16 = load i32, i32* @Z_OK
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %69
18: ; preds = %2
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 2
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 3
br label %21
21: ; preds = %18, %59
%22 = phi i32 [ %34, %59 ], [ %15, %18 ]
%23 = call i64 @fread(i8* %7, i32 1, i32 4096, i32* %0)
store i64 %23, i64* %13
%24 = call i64 @ferror(i32* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = call i32 @inflateEnd(%struct.TYPE_5__* %3)
%28 = load i32, i32* @Z_ERRNO
br label %69
29: ; preds = %21
%30 = icmp eq i64 %23, 0
br i1 %30, label %62, label %31
31: ; preds = %29
store i8* %7, i8** %14
br label %32
32: ; preds = %56, %31
store i32 4096, i32* %19
store i8* %8, i8** %20
%33 = load i32, i32* @Z_NO_FLUSH
%34 = call i32 @inflate(%struct.TYPE_5__* %3, i32 %33)
%35 = load i32, i32* @Z_STREAM_ERROR
%36 = icmp eq i32 %34, %35
br i1 %36, label %69, label %37
37: ; preds = %32
%38 = add i32 %34, -128
%39 = icmp ult i32 %38, 3
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = sext i32 %38 to i64
%42 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.zlib_inflate, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = call i32 @inflateEnd(%struct.TYPE_5__* %3)
br label %69
45: ; preds = %37
%46 = load i32, i32* %19
%47 = sub nsw i32 4096, %46
%48 = call i32 @fwrite(i8* %8, i32 1, i32 %47, i32* %1)
%49 = icmp eq i32 %48, %47
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = call i64 @ferror(i32* %1)
%52 = icmp eq i64 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %50, %45
%54 = call i32 @inflateEnd(%struct.TYPE_5__* %3)
%55 = load i32, i32* @Z_ERRNO
br label %69
56: ; preds = %50
%57 = load i32, i32* %19
%58 = icmp eq i32 %57, 0
br i1 %58, label %32, label %59
59: ; preds = %56
%60 = load i32, i32* @Z_STREAM_END
%61 = icmp eq i32 %34, %60
br i1 %61, label %62, label %21
62: ; preds = %29, %59
%63 = phi i32 [ %22, %29 ], [ %34, %59 ]
%64 = call i32 @inflateEnd(%struct.TYPE_5__* %3)
%65 = load i32, i32* @Z_STREAM_END
%66 = icmp eq i32 %63, %65
%67 = load i32, i32* @Z_OK
%68 = select i1 %66, i32 %67, i32 130
br label %69
69: ; preds = %32, %62, %2, %53, %40, %26
%70 = phi i32 [ %28, %26 ], [ %55, %53 ], [ %43, %40 ], [ %15, %2 ], [ %68, %62 ], [ %34, %32 ]
ret i32 %70
}