#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 def(FILE *source, FILE *dest, int level) {
  int ret, flush;
  unsigned have;
  z_stream strm;
  unsigned char in[32768];
  unsigned char out[32768];
  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, 32768, 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 = 32768;
      strm.next_out = out;
      ret = deflate(&strm, flush);
      have = 32768 - strm.avail_out;
      if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
        (void)deflateEnd(&strm);
        return Z_ERRNO;
      }
    } while (strm.avail_out == 0);
  } while (flush != Z_FINISH);
  (void)deflateEnd(&strm);
  return Z_OK;
}


x86 assembly (clang, -O0):
<def>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10070,%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    -0x20(%rbp),%eax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%eax
je     11dc <def+0x6c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    132a <def+0x1ba>
jmp    11e1 <def+0x71>
lea    -0x8060(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8000,%edx
call   1040 <fread@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     122b <def+0xbb>
lea    -0x60(%rbp),%rdi
call   1080 <deflateEnd@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132a <def+0x1ba>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1252 <def+0xe2>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10064(%rbp)
jmp    1261 <def+0xf1>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10064(%rbp)
mov    -0x10064(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x8060(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x8000,-0x58(%rbp)
lea    -0x10060(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x60(%rbp),%rdi
call   1050 <deflate@plt>
mov    %eax,-0x20(%rbp)
mov    $0x8000,%eax
sub    -0x58(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x10060(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
cmp    -0x28(%rbp),%eax
jne    12d5 <def+0x165>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12ef <def+0x17f>
lea    -0x60(%rbp),%rdi
call   1080 <deflateEnd@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132a <def+0x1ba>
jmp    12f4 <def+0x184>
cmpl   $0x0,-0x58(%rbp)
je     1275 <def+0x105>
jmp    1303 <def+0x193>
mov    -0x24(%rbp),%eax
mov    0x2cb3(%rip),%rcx
cmp    (%rcx),%eax
jne    11e1 <def+0x71>
lea    -0x60(%rbp),%rdi
call   1080 <deflateEnd@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<def>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10048,%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 <def+0x131>
lea    0x40(%rsp),%r15
mov    0x2df9(%rip),%rbp
lea    0x8040(%rsp),%r12
lea    0x8(%rsp),%r13
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,0x20(%rsp)
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    128e <def+0x11e>
mov    %r14,%rdi
call   1060 <feof@plt>
mov    %rbp,%rcx
test   %rax,%rax
jne    1215 <def+0xa5>
mov    0x2dbb(%rip),%rcx
mov    (%rcx),%ebp
mov    %r15,0x8(%rsp)
nopl   0x0(%rax)
movl   $0x8000,0x10(%rsp)
mov    %r12,0x18(%rsp)
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <deflate@plt>
mov    $0x8000,%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 <def+0x11e>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    128e <def+0x11e>
cmpl   $0x0,0x10(%rsp)
je     1220 <def+0xb0>
mov    0x2d4b(%rip),%rax
cmp    (%rax),%ebp
mov    %rax,%rbp
lea    0x40(%rsp),%r15
jne    11d4 <def+0x64>
mov    0x2d64(%rip),%rbx
jmp    1295 <def+0x125>
mov    0x2d4b(%rip),%rbx
lea    0x8(%rsp),%rdi
call   1080 <deflateEnd@plt>
mov    (%rbx),%eax
add    $0x10048,%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 @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 [32768 x i8]
%13 = alloca [32768 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 %86
27: ; preds = %3
br label %28
28: ; preds = %79, %27
%29 = getelementptr inbounds [32768 x i8], [32768 x i8]* %12, i64 0, i64 0
%30 = load i32*, i32** %5
%31 = call i32 @fread(i8* %29, i32 1, i32 32768, i32* %30)
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 3
store i32 %31, i32* %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 %86
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 [32768 x i8], [32768 x i8]* %12, i64 0, i64 0
%50 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 0
store i8* %49, i8** %50
br label %51
51: ; preds = %74, %47
%52 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 1
store i32 32768, i32* %52
%53 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 0
%54 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 2
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 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 1
%58 = load i32, i32* %57
%59 = sub nsw i32 32768, %58
store i32 %59, i32* %10
%60 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 0
%61 = load i32, i32* %10
%62 = load i32*, i32** %6
%63 = call i32 @fwrite(i8* %60, i32 1, i32 %61, i32* %62)
%64 = load i32, i32* %10
%65 = icmp ne i32 %63, %64
br i1 %65, label %70, label %66
66: ; preds = %51
%67 = load i32*, i32** %6
%68 = call i64 @ferror(i32* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %66, %51
%71 = call i32 @deflateEnd(%struct.TYPE_5__* %11)
%72 = load i32, i32* @Z_ERRNO
store i32 %72, i32* %4
br label %86
73: ; preds = %66
br label %74
74: ; preds = %73
%75 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %11, i32 0, i32 1
%76 = load i32, i32* %75
%77 = icmp eq i32 %76, 0
br i1 %77, label %51, label %78
78: ; preds = %74
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 %28, 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, %70, %36, %25
%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 @def(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca %struct.TYPE_5__
%5 = alloca [32768 x i8]
%6 = alloca [32768 x i8]
%7 = bitcast %struct.TYPE_5__* %4 to i8*
%8 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [32768 x i8], [32768 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 32768, 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 32768, 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 32768, %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
}