#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;
  int avail_out;
  unsigned char *next_out;
  scalar_t__ avail_in;
  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;
scalar_t__ ferror(int /*<<< orphan*/ *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned int fwrite(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int zinflate(FILE *source, FILE *dest) {
  int ret;
  unsigned int have;
  z_stream stream;
  unsigned char in[16384];
  unsigned char out[16384];
  stream.zalloc = Z_NULL;
  stream.zfree = Z_NULL;
  stream.opaque = Z_NULL;
  stream.avail_in = 0;
  stream.next_in = Z_NULL;
  if ((ret = inflateInit(&stream)) != Z_OK)
    return ret;
  do {
    stream.avail_in = fread(in, 1, 16384, source);
    if (ferror(source)) {
      inflateEnd(&stream);
      return Z_ERRNO;
    }
    if (!stream.avail_in)
      break;
    stream.next_in = in;
    do {
      stream.avail_out = 16384;
      stream.next_out = out;
      ret = inflate(&stream, Z_NO_FLUSH);
      switch (ret) {
      case Z_NEED_DICT:
        ret = Z_DATA_ERROR;
      case Z_DATA_ERROR:
      case Z_MEM_ERROR:
        inflateEnd(&stream);
        return ret;
      }
      have = 16384 - stream.avail_out;
      if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
        inflateEnd(&stream);
        return Z_ERRNO;
      }
    } while (!stream.avail_out);
  } while (ret != Z_STREAM_END);
  inflateEnd(&stream);
  return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}


x86 assembly (clang, -O0):
<zinflate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8070,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
lea    -0x58(%rbp),%rdi
call   1060 <inflateInit@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%eax
je     11d9 <zinflate+0x79>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1386 <zinflate+0x226>
jmp    11de <zinflate+0x7e>
lea    -0x4060(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1050 <fread@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1229 <zinflate+0xc9>
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1386 <zinflate+0x226>
cmpq   $0x0,-0x40(%rbp)
jne    1239 <zinflate+0xd9>
jmp    133e <zinflate+0x1de>
lea    -0x4060(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x4000,-0x50(%rbp)
lea    -0x8060(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x8064(%rbp)
sub    $0x80,%eax
je     129d <zinflate+0x13d>
jmp    1284 <zinflate+0x124>
mov    -0x8064(%rbp),%eax
add    $0xffffff7f,%eax
sub    $0x2,%eax
jb     12a4 <zinflate+0x144>
jmp    12b8 <zinflate+0x158>
movl   $0x82,-0x1c(%rbp)
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1386 <zinflate+0x226>
mov    $0x4000,%eax
sub    -0x50(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x8060(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
cmp    -0x20(%rbp),%eax
jne    12f7 <zinflate+0x197>
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1311 <zinflate+0x1b1>
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1386 <zinflate+0x226>
jmp    1316 <zinflate+0x1b6>
cmpl   $0x0,-0x50(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1244 <zinflate+0xe4>
jmp    132c <zinflate+0x1cc>
mov    -0x1c(%rbp),%eax
mov    0x2caa(%rip),%rcx
cmp    (%rcx),%eax
jne    11de <zinflate+0x7e>
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    -0x1c(%rbp),%eax
mov    0x2c8f(%rip),%rcx
cmp    (%rcx),%eax
jne    136d <zinflate+0x20d>
mov    0x2c90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8068(%rbp)
jmp    137d <zinflate+0x21d>
mov    $0x82,%eax
mov    %eax,-0x8068(%rbp)
jmp    137d <zinflate+0x21d>
mov    -0x8068(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zinflate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8048,%rsp
mov    %rsi,%r14
mov    %rdi,0x38(%rsp)
mov    0x2e40(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1060 <inflateInit@plt>
mov    %eax,%ebx
mov    0x2e40(%rip),%rax
cmp    (%rax),%ebx
jne    12bc <zinflate+0x15c>
lea    0x4040(%rsp),%r12
lea    0x40(%rsp),%r13
mov    %r12,%r15
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    0x38(%rsp),%rbp
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rax,%r12
mov    %rax,0x18(%rsp)
mov    %rbp,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1295 <zinflate+0x135>
test   %r12,%r12
je     1274 <zinflate+0x114>
mov    %r15,%r12
mov    %r15,(%rsp)
mov    0x2dba(%rip),%r15
xchg   %ax,%ax
movl   $0x4000,0x8(%rsp)
mov    %r13,0x10(%rsp)
mov    (%r15),%esi
mov    %rsp,%rdi
call   1030 <inflate@plt>
mov    %eax,%ebx
lea    -0x80(%rbx),%eax
cmp    $0x2,%eax
jbe    12a8 <zinflate+0x148>
mov    $0x4000,%ebp
sub    0x8(%rsp),%ebp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    %ebp,%eax
jne    1295 <zinflate+0x135>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1295 <zinflate+0x135>
cmpl   $0x0,0x8(%rsp)
je     1210 <zinflate+0xb0>
mov    0x2d74(%rip),%rax
cmp    (%rax),%ebx
jne    11c5 <zinflate+0x65>
mov    %rsp,%rdi
call   1070 <inflateEnd@plt>
mov    0x2d5d(%rip),%rax
cmp    (%rax),%ebx
mov    $0x82,%ebx
jne    12bc <zinflate+0x15c>
mov    0x2d5d(%rip),%rax
jmp    12a4 <zinflate+0x144>
mov    %rsp,%rdi
call   1070 <inflateEnd@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%ebx
jmp    12bc <zinflate+0x15c>
cltq
lea    0xd4f(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
mov    %rsp,%rdi
call   1070 <inflateEnd@plt>
mov    %ebx,%eax
add    $0x8048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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