#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;
  char *next_in;
  int avail_out;
  char *next_out;
  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 Z_STREAM_END;
int Z_STREAM_ERROR;
int /*<<< orphan*/ assert(int);
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*/ *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
unsigned int fwrite(char *, int, unsigned int, int /*<<< orphan*/ *);
int def(FILE *source, FILE *dest, int level) {
  int ret, flush;
  unsigned have;
  z_stream strm;
  char in[16384];
  char out[16384];
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  ret = deflateInit(&strm, level);
  if (ret != Z_OK)
    return ret;
  do {
    strm.avail_in = fread(in, 1, 16384, source);
    if (ferror(source)) {
      (void)deflateEnd(&strm);
      return Z_ERRNO;
    }
    flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
    strm.next_in = in;
    do {
      strm.avail_out = 16384;
      strm.next_out = out;
      ret = deflate(&strm, flush);
      assert(ret != Z_STREAM_ERROR);
      have = 16384 - strm.avail_out;
      if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
        (void)deflateEnd(&strm);
        return Z_ERRNO;
      }
    } while (strm.avail_out == 0);
    assert(strm.avail_in == 0);
  } while (flush != Z_FINISH);
  assert(ret == Z_STREAM_END);
  (void)deflateEnd(&strm);
  return Z_OK;
}


x86 assembly (clang, -O0):
<def>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8070,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%esi
lea    -0x60(%rbp),%rdi
call   1080 <deflateInit@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%eax
je     11ec <def+0x6c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    137a <def+0x1fa>
jmp    11f1 <def+0x71>
lea    -0x4060(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1040 <fread@plt>
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     123c <def+0xbc>
lea    -0x60(%rbp),%rdi
call   1090 <deflateEnd@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137a <def+0x1fa>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1263 <def+0xe3>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8064(%rbp)
jmp    1272 <def+0xf2>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8064(%rbp)
mov    -0x8064(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x4060(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x4000,-0x50(%rbp)
lea    -0x8060(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x60(%rbp),%rdi
call   1050 <deflate@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2d17(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x4000,%eax
sub    -0x50(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x8060(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
cmp    -0x28(%rbp),%eax
jne    12ff <def+0x17f>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1319 <def+0x199>
lea    -0x60(%rbp),%rdi
call   1090 <deflateEnd@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137a <def+0x1fa>
jmp    131e <def+0x19e>
cmpl   $0x0,-0x50(%rbp)
je     1286 <def+0x106>
cmpq   $0x0,-0x60(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x24(%rbp),%eax
mov    0x2c6c(%rip),%rcx
cmp    (%rcx),%eax
jne    11f1 <def+0x71>
mov    -0x20(%rbp),%eax
mov    0x2c8a(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x60(%rbp),%rdi
call   1090 <deflateEnd@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<def>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8048,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    0x2e1a(%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   1080 <deflateInit@plt>
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%eax
jne    12f0 <def+0x170>
lea    0x40(%rsp),%r14
lea    0x4040(%rsp),%r12
lea    0x8(%rsp),%r13
mov    %rbp,(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rax,0x8(%rsp)
mov    %rbp,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    12dd <def+0x15d>
mov    %rbp,%rdi
call   1070 <feof@plt>
mov    0x2d95(%rip),%rcx
test   %rax,%rax
jne    1227 <def+0xa7>
mov    0x2d99(%rip),%rcx
mov    (%rcx),%ebp
mov    %r14,0x10(%rsp)
xchg   %ax,%ax
movl   $0x4000,0x18(%rsp)
mov    %r12,0x20(%rsp)
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <deflate@plt>
mov    %eax,%r15d
xor    %edi,%edi
mov    0x2d75(%rip),%rax
cmp    (%rax),%r15d
setne  %dil
call   1060 <assert@plt>
mov    $0x4000,%r14d
sub    0x18(%rsp),%r14d
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
cmp    %r14d,%eax
jne    12dd <def+0x15d>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    12dd <def+0x15d>
cmpl   $0x0,0x18(%rsp)
je     1230 <def+0xb0>
xor    %edi,%edi
cmpq   $0x0,0x8(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    0x2d02(%rip),%rax
cmp    (%rax),%ebp
mov    (%rsp),%rbp
lea    0x40(%rsp),%r14
jne    11e1 <def+0x61>
mov    0x2d1a(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%r15d
sete   %dil
call   1060 <assert@plt>
mov    0x2d15(%rip),%rbx
jmp    12e4 <def+0x164>
mov    0x2cf4(%rip),%rbx
lea    0x8(%rsp),%rdi
call   1090 <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 { i64, i8*, i32, i8*, 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
@Z_STREAM_ERROR = global i32 0
@Z_STREAM_END = global i32 0
define i32 @def(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* %8
%23 = load i32, i32* @Z_OK
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %3
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %101
27: ; preds = %3
br label %28
28: ; preds = %89, %27
%29 = getelementptr inbounds [16384 x i8], [16384 x i8]* %12, i64 0, i64 0
%30 = load i32*, i32** %5
%31 = call i64 @fread(i8* %29, i32 1, i32 16384, i32* %30)
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 0
store i64 %31, i64* %32
%33 = load i32*, i32** %5
%34 = call i64 @ferror(i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = call i32 @deflateEnd(%struct.TYPE_5__* %11)
%38 = load i32, i32* @Z_ERRNO
store i32 %38, i32* %4
br label %101
39: ; preds = %28
%40 = load i32*, i32** %5
%41 = call i64 @feof(i32* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i32, i32* @Z_FINISH
br label %47
45: ; preds = %39
%46 = load i32, i32* @Z_NO_FLUSH
br label %47
47: ; preds = %45, %43
%48 = phi i32 [ %44, %43 ], [ %46, %45 ]
store i32 %48, i32* %9
%49 = getelementptr inbounds [16384 x i8], [16384 x i8]* %12, i64 0, i64 0
%50 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 1
store i8* %49, i8** %50
br label %51
51: ; preds = %79, %47
%52 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 2
store i32 16384, i32* %52
%53 = getelementptr inbounds [16384 x i8], [16384 x i8]* %13, i64 0, i64 0
%54 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 3
store i8* %53, i8** %54
%55 = load i32, i32* %9
%56 = call i32 @deflate(%struct.TYPE_5__* %11, i32 %55)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = load i32, i32* @Z_STREAM_ERROR
%59 = icmp ne i32 %57, %58
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 2
%63 = load i32, i32* %62
%64 = sub nsw i32 16384, %63
store i32 %64, i32* %10
%65 = getelementptr inbounds [16384 x i8], [16384 x i8]* %13, i64 0, i64 0
%66 = load i32, i32* %10
%67 = load i32*, i32** %6
%68 = call i32 @fwrite(i8* %65, i32 1, i32 %66, i32* %67)
%69 = load i32, i32* %10
%70 = icmp ne i32 %68, %69
br i1 %70, label %75, label %71
71: ; preds = %51
%72 = load i32*, i32** %6
%73 = call i64 @ferror(i32* %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %71, %51
%76 = call i32 @deflateEnd(%struct.TYPE_5__* %11)
%77 = load i32, i32* @Z_ERRNO
store i32 %77, i32* %4
br label %101
78: ; preds = %71
br label %79
79: ; preds = %78
%80 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 2
%81 = load i32, i32* %80
%82 = icmp eq i32 %81, 0
br i1 %82, label %51, label %83
83: ; preds = %79
%84 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 0
%85 = load i64, i64* %84
%86 = icmp eq i64 %85, 0
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
br label %89
89: ; preds = %83
%90 = load i32, i32* %9
%91 = load i32, i32* @Z_FINISH
%92 = icmp ne i32 %90, %91
br i1 %92, label %28, label %93
93: ; preds = %89
%94 = load i32, i32* %8
%95 = load i32, i32* @Z_STREAM_END
%96 = icmp eq i32 %94, %95
%97 = zext i1 %96 to i32
%98 = call i32 @assert(i32 %97)
%99 = call i32 @deflateEnd(%struct.TYPE_5__* %11)
%100 = load i32, i32* @Z_OK
store i32 %100, i32* %4
br label %101
101: ; preds = %93, %75, %36, %25
%102 = load i32, i32* %4
ret i32 %102
}

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_FINISH = global i32 0
@Z_NO_FLUSH = global i32 0
@Z_STREAM_ERROR = global i32 0
@Z_STREAM_END = global i32 0
define i32 @def(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 %64
17: ; preds = %3
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 2
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 3
br label %22
22: ; preds = %17, %48
%23 = call i64 @fread(i8* %8, i32 1, i32 16384, i32* %0)
store i64 %23, i64* %18
%24 = call i64 @ferror(i32* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %60
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 = %45, %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* @Z_STREAM_ERROR
%35 = icmp ne i32 %33, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i32, i32* %20
%39 = sub nsw i32 16384, %38
%40 = call i32 @fwrite(i8* %9, i32 1, i32 %39, i32* %1)
%41 = icmp eq i32 %40, %39
br i1 %41, label %42, label %60
42: ; preds = %32
%43 = call i64 @ferror(i32* %1)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %60
45: ; preds = %42
%46 = load i32, i32* %20
%47 = icmp eq i32 %46, 0
br i1 %47, label %32, label %48
48: ; preds = %45
%49 = load i64, i64* %18
%50 = icmp eq i64 %49, 0
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = load i32, i32* @Z_FINISH
%54 = icmp eq i32 %31, %53
br i1 %54, label %55, label %22
55: ; preds = %48
%56 = load i32, i32* @Z_STREAM_END
%57 = icmp eq i32 %33, %56
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
br label %60
60: ; preds = %22, %32, %42, %55
%61 = phi i32* [ @Z_OK, %55 ], [ @Z_ERRNO, %42 ], [ @Z_ERRNO, %32 ], [ @Z_ERRNO, %22 ]
%62 = call i32 @deflateEnd(%struct.TYPE_5__* %4)
%63 = load i32, i32* %61
br label %64
64: ; preds = %60, %3
%65 = phi i32 [ %14, %3 ], [ %63, %60 ]
ret i32 %65
}