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

/* Variables and functions */
int Z_ERRNO;
int Z_FINISH;
int Z_NO_FLUSH;
void *Z_NULL;
int Z_OK;
int deflate(TYPE_1__ *, int);
int /*<<< orphan*/ deflateEnd(TYPE_1__ *);
int deflateInit(TYPE_1__ *, int);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned int fwrite(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int zdeflate(FILE *source, FILE *dest, int level) {
  int ret, flush;
  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;
  if ((ret = deflateInit(&stream, level)) != Z_OK)
    return ret;
  do {
    stream.avail_in = fread(in, 1, 16384, source);
    if (ferror(source)) {
      deflateEnd(&stream);
      return Z_ERRNO;
    }
    flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
    stream.next_in = in;
    do {
      stream.avail_out = 16384;
      stream.next_out = out;
      ret = deflate(&stream, flush);
      have = 16384 - stream.avail_out;
      if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
        deflateEnd(&stream);
        return Z_ERRNO;
      }
    } while (!stream.avail_out);
  } while (flush != Z_FINISH);
  deflateEnd(&stream);
  return Z_OK;
}


x86 assembly (clang, -O0):
<zdeflate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8070,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%esi
lea    -0x60(%rbp),%rdi
call   1070 <deflateInit@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%eax
je     11d9 <zdeflate+0x69>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    132e <zdeflate+0x1be>
jmp    11de <zdeflate+0x6e>
lea    -0x4060(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1040 <fread@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1228 <zdeflate+0xb8>
lea    -0x60(%rbp),%rdi
call   1080 <deflateEnd@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132e <zdeflate+0x1be>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     124f <zdeflate+0xdf>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8064(%rbp)
jmp    125e <zdeflate+0xee>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8064(%rbp)
mov    -0x8064(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x4060(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x4000,-0x58(%rbp)
lea    -0x8060(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x60(%rbp),%rdi
call   1050 <deflate@plt>
mov    %eax,-0x20(%rbp)
mov    $0x4000,%eax
sub    -0x58(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x8060(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
cmp    -0x28(%rbp),%eax
jne    12d2 <zdeflate+0x162>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12ec <zdeflate+0x17c>
lea    -0x60(%rbp),%rdi
call   1080 <deflateEnd@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132e <zdeflate+0x1be>
jmp    12f1 <zdeflate+0x181>
cmpl   $0x0,-0x58(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1272 <zdeflate+0x102>
jmp    1307 <zdeflate+0x197>
mov    -0x24(%rbp),%eax
mov    0x2caf(%rip),%rcx
cmp    (%rcx),%eax
jne    11de <zdeflate+0x6e>
lea    -0x60(%rbp),%rdi
call   1080 <deflateEnd@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zdeflate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8048,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x38(%rsp)
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
lea    0x8(%rsp),%rdi
mov    %edx,%esi
call   1070 <deflateInit@plt>
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%eax
jne    12a1 <zdeflate+0x131>
lea    0x40(%rsp),%r15
mov    0x2df9(%rip),%rbp
lea    0x4040(%rsp),%r12
lea    0x8(%rsp),%r13
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,0x20(%rsp)
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    128e <zdeflate+0x11e>
mov    %r14,%rdi
call   1060 <feof@plt>
mov    %rbp,%rcx
test   %rax,%rax
jne    1215 <zdeflate+0xa5>
mov    0x2dbb(%rip),%rcx
mov    (%rcx),%ebp
mov    %r15,0x8(%rsp)
nopl   0x0(%rax)
movl   $0x4000,0x10(%rsp)
mov    %r12,0x18(%rsp)
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <deflate@plt>
mov    $0x4000,%r15d
sub    0x10(%rsp),%r15d
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
cmp    %r15d,%eax
jne    128e <zdeflate+0x11e>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    128e <zdeflate+0x11e>
cmpl   $0x0,0x10(%rsp)
je     1220 <zdeflate+0xb0>
mov    0x2d4b(%rip),%rax
cmp    (%rax),%ebp
mov    %rax,%rbp
lea    0x40(%rsp),%r15
jne    11d4 <zdeflate+0x64>
mov    0x2d64(%rip),%rbx
jmp    1295 <zdeflate+0x125>
mov    0x2d4b(%rip),%rbx
lea    0x8(%rsp),%rdi
call   1080 <deflateEnd@plt>
mov    (%rbx),%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*, i32, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_ERRNO = global i32 0
@Z_FINISH = global i32 0
@Z_NO_FLUSH = global i32 0
define i32 @zdeflate(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.TYPE_5__
%12 = alloca [16384 x i8]
%13 = alloca [16384 x i8]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%14 = load i8*, i8** @Z_NULL
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 6
store i8* %14, i8** %15
%16 = load i8*, i8** @Z_NULL
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 5
store i8* %16, i8** %17
%18 = load i8*, i8** @Z_NULL
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 4
store i8* %18, i8** %19
%20 = load i32, i32* %7
%21 = call i32 @deflateInit(%struct.TYPE_5__* %11, i32 %20)
store i32 %21, i32* %8
%22 = load i32, i32* @Z_OK
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %3
%25 = load i32, i32* %8
store i32 %25, i32* %4
br label %86
26: ; preds = %3
br label %27
27: ; preds = %79, %26
%28 = getelementptr inbounds [16384 x i8], [16384 x i8]* %12, i64 0, i64 0
%29 = load i32*, i32** %5
%30 = call i32 @fread(i8* %28, i32 1, i32 16384, i32* %29)
%31 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 3
store i32 %30, i32* %31
%32 = load i32*, i32** %5
%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 @deflateEnd(%struct.TYPE_5__* %11)
%37 = load i32, i32* @Z_ERRNO
store i32 %37, i32* %4
br label %86
38: ; preds = %27
%39 = load i32*, i32** %5
%40 = call i64 @feof(i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = load i32, i32* @Z_FINISH
br label %46
44: ; preds = %38
%45 = load i32, i32* @Z_NO_FLUSH
br label %46
46: ; preds = %44, %42
%47 = phi i32 [ %43, %42 ], [ %45, %44 ]
store i32 %47, i32* %9
%48 = getelementptr inbounds [16384 x i8], [16384 x i8]* %12, i64 0, i64 0
%49 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 0
store i8* %48, i8** %49
br label %50
50: ; preds = %73, %46
%51 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 1
store i32 16384, i32* %51
%52 = getelementptr inbounds [16384 x i8], [16384 x i8]* %13, i64 0, i64 0
%53 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 2
store i8* %52, i8** %53
%54 = load i32, i32* %9
%55 = call i32 @deflate(%struct.TYPE_5__* %11, i32 %54)
store i32 %55, i32* %8
%56 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 1
%57 = load i32, i32* %56
%58 = sub nsw i32 16384, %57
store i32 %58, i32* %10
%59 = getelementptr inbounds [16384 x i8], [16384 x i8]* %13, i64 0, i64 0
%60 = load i32, i32* %10
%61 = load i32*, i32** %6
%62 = call i32 @fwrite(i8* %59, i32 1, i32 %60, i32* %61)
%63 = load i32, i32* %10
%64 = icmp ne i32 %62, %63
br i1 %64, label %69, label %65
65: ; preds = %50
%66 = load i32*, i32** %6
%67 = call i64 @ferror(i32* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %65, %50
%70 = call i32 @deflateEnd(%struct.TYPE_5__* %11)
%71 = load i32, i32* @Z_ERRNO
store i32 %71, i32* %4
br label %86
72: ; preds = %65
br label %73
73: ; preds = %72
%74 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 1
%75 = load i32, i32* %74
%76 = icmp ne i32 %75, 0
%77 = xor i1 %76, true
br i1 %77, label %50, label %78
78: ; preds = %73
br label %79
79: ; preds = %78
%80 = load i32, i32* %9
%81 = load i32, i32* @Z_FINISH
%82 = icmp ne i32 %80, %81
br i1 %82, label %27, label %83
83: ; preds = %79
%84 = call i32 @deflateEnd(%struct.TYPE_5__* %11)
%85 = load i32, i32* @Z_OK
store i32 %85, i32* %4
br label %86
86: ; preds = %83, %69, %35, %24
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i8*, i32, i8*, i32, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_ERRNO = global i32 0
@Z_FINISH = global i32 0
@Z_NO_FLUSH = global i32 0
define i32 @zdeflate(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca %struct.TYPE_5__
%5 = alloca [16384 x i8]
%6 = alloca [16384 x i8]
%7 = bitcast %struct.TYPE_5__* %4 to i8*
%8 = getelementptr inbounds [16384 x i8], [16384 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** @Z_NULL
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 6
store i8* %10, i8** %11
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 5
store i8* %10, i8** %12
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 4
store i8* %10, i8** %13
%14 = call i32 @deflateInit(%struct.TYPE_5__* %4, i32 %2)
%15 = load i32, i32* @Z_OK
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %51
17: ; preds = %3
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 3
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 2
br label %22
22: ; preds = %17, %44
%23 = call i32 @fread(i8* %8, i32 1, i32 16384, i32* %0)
store i32 %23, i32* %18
%24 = call i64 @ferror(i32* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %47
26: ; preds = %22
%27 = call i64 @feof(i32* %0)
%28 = icmp eq i64 %27, 0
%29 = load i32, i32* @Z_FINISH
%30 = load i32, i32* @Z_NO_FLUSH
%31 = select i1 %28, i32 %30, i32 %29
store i8* %8, i8** %19
br label %32
32: ; preds = %41, %26
store i32 16384, i32* %20
store i8* %9, i8** %21
%33 = call i32 @deflate(%struct.TYPE_5__* %4, i32 %31)
%34 = load i32, i32* %20
%35 = sub nsw i32 16384, %34
%36 = call i32 @fwrite(i8* %9, i32 1, i32 %35, i32* %1)
%37 = icmp eq i32 %36, %35
br i1 %37, label %38, label %47
38: ; preds = %32
%39 = call i64 @ferror(i32* %1)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i32, i32* %20
%43 = icmp eq i32 %42, 0
br i1 %43, label %32, label %44
44: ; preds = %41
%45 = load i32, i32* @Z_FINISH
%46 = icmp eq i32 %31, %45
br i1 %46, label %47, label %22
47: ; preds = %44, %22, %32, %38
%48 = phi i32* [ @Z_ERRNO, %38 ], [ @Z_ERRNO, %32 ], [ @Z_ERRNO, %22 ], [ @Z_OK, %44 ]
%49 = call i32 @deflateEnd(%struct.TYPE_5__* %4)
%50 = load i32, i32* %48
br label %51
51: ; preds = %47, %3
%52 = phi i32 [ %14, %3 ], [ %50, %47 ]
ret i32 %52
}