#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int avail_in;
  int avail_out;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int Z_OK;
int /*<<< orphan*/ Z_SYNC_FLUSH;
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int gtg_compress_f2f(z_stream *z, FILE *file_in, FILE *file_out) {
  int status;
  int offset = 0;
  uint8_t in_buf[(128 * 1024)];
  uint8_t out_buf[(128 * 1024)];
  int in_len = 0;
  int total_written = 0;
  int written = 0;
  while (!feof(file_in)) {
    in_len = fread(in_buf, sizeof(uint8_t), (128 * 1024), file_in);
    z->avail_in = in_len;
    z->next_in = in_buf;
    z->avail_out = (128 * 1024);
    z->next_out = out_buf;
    status = deflate(z, Z_SYNC_FLUSH);
    if (Z_OK != status) {
      fprintf(stderr, "error %d in compressing\n", status);
      return -1;
    }
    offset = (128 * 1024) - z->avail_out;
    written = fwrite(out_buf, sizeof(uint8_t), offset, file_out);
    if (written < offset) {
      fprintf(stderr, "warning: %d bytes out of %d were written to disk\n",
              written, offset);
    }
    total_written += written;
  }
  return total_written;
}


x86 assembly (clang, -O0):
<gtg_compress_f2f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x100034(%rbp)
movl   $0x0,-0x100038(%rbp)
movl   $0x0,-0x10003c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11aa <gtg_compress_f2f+0x5a>
jmp    12bf <gtg_compress_f2f+0x16f>
lea    -0x80030(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x20000,%edx
call   1030 <fread@plt>
mov    %eax,-0x100034(%rbp)
mov    -0x100034(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x80030(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rax
movl   $0x20000,0x4(%rax)
lea    -0x100030(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
call   1040 <deflate@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
je     124c <gtg_compress_f2f+0xfc>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c8 <gtg_compress_f2f+0x178>
mov    -0x10(%rbp),%rcx
mov    $0x20000,%eax
sub    0x4(%rcx),%eax
mov    %eax,-0x28(%rbp)
lea    -0x100030(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1070 <fwrite@plt>
mov    %eax,-0x10003c(%rbp)
mov    -0x10003c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12a8 <gtg_compress_f2f+0x158>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x10003c(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10003c(%rbp),%eax
add    -0x100038(%rbp),%eax
mov    %eax,-0x100038(%rbp)
jmp    118c <gtg_compress_f2f+0x3c>
mov    -0x100038(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtg_compress_f2f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100018,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1060 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    1258 <gtg_compress_f2f+0x108>
lea    0x10(%rsp),%r13
xor    %ebp,%ebp
jmp    11a3 <gtg_compress_f2f+0x53>
nopw   0x0(%rax,%rax,1)
add    %r12d,%ebp
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1258 <gtg_compress_f2f+0x108>
lea    0x80010(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x20000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %eax,(%rbx)
mov    %r14,0x10(%rbx)
movl   $0x20000,0x4(%rbx)
mov    %r13,0x8(%rbx)
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <deflate@plt>
mov    0x2e07(%rip),%rcx
cmp    %eax,(%rcx)
jne    123a <gtg_compress_f2f+0xea>
mov    $0x20000,%r14d
sub    0x4(%rbx),%r14d
mov    %r13,%rdi
mov    $0x4,%esi
mov    %r14d,%edx
mov    0x8(%rsp),%rcx
call   1070 <fwrite@plt>
mov    %eax,%r12d
cmp    %r14d,%eax
jge    1190 <gtg_compress_f2f+0x40>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    %r12d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1190 <gtg_compress_f2f+0x40>
mov    0x2d8f(%rip),%rcx
mov    (%rcx),%edi
lea    0xdb6(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x100018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32*, i32* }
@Z_SYNC_FLUSH = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"error %d in compressing\0A\00"
@.str.1 = [50 x i8] c"warning: %d bytes out of %d were written to disk\0A\00"
define i32 @gtg_compress_f2f(%struct.TYPE_4__* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_4__*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [131072 x i32]
%11 = alloca [131072 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 0, i32* %9
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
br label %15
15: ; preds = %62, %3
%16 = load i32*, i32** %6
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %66
20: ; preds = %15
%21 = getelementptr inbounds [131072 x i32], [131072 x i32]* %10, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i32 @fread(i32* %21, i32 4, i32 131072, i32* %22)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = getelementptr inbounds [131072 x i32], [131072 x i32]* %10, i64 0, i64 0
%28 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %28, i32 0, i32 3
store i32* %27, i32** %29
%30 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %30, i32 0, i32 1
store i32 131072, i32* %31
%32 = getelementptr inbounds [131072 x i32], [131072 x i32]* %11, i64 0, i64 0
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 2
store i32* %32, i32** %34
%35 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%36 = load i32, i32* @Z_SYNC_FLUSH
%37 = call i32 @deflate(%struct.TYPE_4__* %35, i32 %36)
store i32 %37, i32* %8
%38 = load i32, i32* @Z_OK
%39 = load i32, i32* %8
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %20
%42 = load i32, i32* @stderr
%43 = load i32, i32* %8
%44 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %43)
store i32 -1, i32* %4
br label %68
45: ; preds = %20
%46 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%47 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = sub nsw i32 131072, %48
store i32 %49, i32* %9
%50 = getelementptr inbounds [131072 x i32], [131072 x i32]* %11, i64 0, i64 0
%51 = load i32, i32* %9
%52 = load i32*, i32** %7
%53 = call i32 @fwrite(i32* %50, i32 4, i32 %51, i32* %52)
store i32 %53, i32* %14
%54 = load i32, i32* %14
%55 = load i32, i32* %9
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %62
57: ; preds = %45
%58 = load i32, i32* @stderr
%59 = load i32, i32* %14
%60 = load i32, i32* %9
%61 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %59, i32 %60)
br label %62
62: ; preds = %57, %45
%63 = load i32, i32* %14
%64 = load i32, i32* %13
%65 = add nsw i32 %64, %63
store i32 %65, i32* %13
br label %15
66: ; preds = %15
%67 = load i32, i32* %13
store i32 %67, i32* %4
br label %68
68: ; preds = %66, %41
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32*, i32* }
@Z_SYNC_FLUSH = global i32 0
@Z_OK = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"error %d in compressing\0A\00"
@.str.1 = [50 x i8] c"warning: %d bytes out of %d were written to disk\0A\00"
define i32 @gtg_compress_f2f(%struct.TYPE_4__* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca [131072 x i32]
%5 = alloca [131072 x i32]
%6 = bitcast [131072 x i32]* %4 to i8*
%7 = bitcast [131072 x i32]* %5 to i8*
%8 = call i32 @feof(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %39
10: ; preds = %3
%11 = getelementptr inbounds [131072 x i32], [131072 x i32]* %4, i64 0, i64 0
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 3
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%15 = getelementptr inbounds [131072 x i32], [131072 x i32]* %5, i64 0, i64 0
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
br label %17
17: ; preds = %10, %35
%18 = phi i32 [ 0, %10 ], [ %36, %35 ]
%19 = call i32 @fread(i32* %11, i32 4, i32 131072, i32* %1)
store i32 %19, i32* %12
store i32* %11, i32** %13
store i32 131072, i32* %14
store i32* %15, i32** %16
%20 = load i32, i32* @Z_SYNC_FLUSH
%21 = call i32 @deflate(%struct.TYPE_4__* %0, i32 %20)
%22 = load i32, i32* @Z_OK
%23 = icmp eq i32 %22, %21
br i1 %23, label %27, label %24
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %39
27: ; preds = %17
%28 = load i32, i32* %14
%29 = sub nsw i32 131072, %28
%30 = call i32 @fwrite(i32* %15, i32 4, i32 %29, i32* %2)
%31 = icmp slt i32 %30, %29
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %29)
br label %35
35: ; preds = %32, %27
%36 = add nsw i32 %30, %18
%37 = call i32 @feof(i32* %1)
%38 = icmp eq i32 %37, 0
br i1 %38, label %17, label %39
39: ; preds = %35, %3, %24
%40 = phi i32 [ -1, %24 ], [ 0, %3 ], [ %36, %35 ]
ret i32 %40
}