#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;
  void *avail_out;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ uint8_t;
typedef void *uint32_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 /*<<< orphan*/ stderr;
int gtg_compress_f2m(z_stream *z, FILE *file_in, void *out_buf,
                     uint32_t out_max_len) {
  int status;
  int offset = 0;
  uint8_t in_buf[(128 * 1024)];
  int in_len = 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 = out_max_len - offset;
    z->next_out = &((uint8_t *)out_buf)[offset];
    status = deflate(z, Z_SYNC_FLUSH);
    if (Z_OK != status) {
      fprintf(stderr, "error %d in compressing\n", status);
      return -1;
    }
    offset = out_max_len - z->avail_out;
  }
  return offset;
}


x86 assembly (clang, -O0):
<gtg_compress_f2m>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x80034(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118a <gtg_compress_f2m+0x4a>
jmp    1256 <gtg_compress_f2m+0x116>
lea    -0x80030(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x20000,%edx
call   1030 <fread@plt>
mov    %eax,-0x80034(%rbp)
mov    -0x80034(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x80030(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x28(%rbp),%rcx
movslq -0x30(%rbp),%rdx
xor    %eax,%eax
sub    %rdx,%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rcx
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1040 <deflate@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
je     123f <gtg_compress_f2m+0xff>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xdd2(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125c <gtg_compress_f2m+0x11c>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x30(%rbp)
jmp    116c <gtg_compress_f2m+0x2c>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtg_compress_f2m>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80008,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1060 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11fd <gtg_compress_f2m+0xbd>
xor    %ebp,%ebp
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x20000,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %eax,(%rbx)
mov    %r13,0x18(%rbx)
movslq %ebp,%rax
mov    %r15,%rcx
sub    %rax,%rcx
mov    %rcx,0x8(%rbx)
lea    (%r14,%rax,4),%rax
mov    %rax,0x10(%rbx)
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <deflate@plt>
mov    0x2e28(%rip),%rcx
cmp    %eax,(%rcx)
jne    11e1 <gtg_compress_f2m+0xa1>
mov    %r15,%rbp
sub    0x8(%rbx),%rbp
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1180 <gtg_compress_f2m+0x40>
jmp    11fd <gtg_compress_f2m+0xbd>
mov    0x2de8(%rip),%rcx
mov    (%rcx),%edi
lea    0xe0f(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x80008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i8*, 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"
define i32 @gtg_compress_f2m(%struct.TYPE_4__* %0, i32* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.TYPE_4__*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [131072 x i32]
%13 = alloca i32
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 0, i32* %11
store i32 0, i32* %13
br label %14
14: ; preds = %53, %4
%15 = load i32*, i32** %7
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %62
19: ; preds = %14
%20 = getelementptr inbounds [131072 x i32], [131072 x i32]* %12, i64 0, i64 0
%21 = load i32*, i32** %7
%22 = call i32 @fread(i32* %20, i32 4, i32 131072, i32* %21)
store i32 %22, i32* %13
%23 = load i32, i32* %13
%24 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = getelementptr inbounds [131072 x i32], [131072 x i32]* %12, i64 0, i64 0
%27 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 3
store i32* %26, i32** %28
%29 = load i8*, i8** %9
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = sub i64 0, %31
%33 = getelementptr i8, i8* %29, i64 %32
%34 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %34, i32 0, i32 1
store i8* %33, i8** %35
%36 = load i8*, i8** %8
%37 = bitcast i8* %36 to i32*
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%42 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %41, i32 0, i32 2
store i32* %40, i32** %42
%43 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%44 = load i32, i32* @Z_SYNC_FLUSH
%45 = call i32 @deflate(%struct.TYPE_4__* %43, i32 %44)
store i32 %45, i32* %10
%46 = load i32, i32* @Z_OK
%47 = load i32, i32* %10
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %19
%50 = load i32, i32* @stderr
%51 = load i32, i32* %10
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %51)
store i32 -1, i32* %5
br label %64
53: ; preds = %19
%54 = load i8*, i8** %9
%55 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%56 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %55, i32 0, i32 1
%57 = load i8*, i8** %56
%58 = ptrtoint i8* %54 to i64
%59 = ptrtoint i8* %57 to i64
%60 = sub i64 %58, %59
%61 = trunc i64 %60 to i32
store i32 %61, i32* %11
br label %14
62: ; preds = %14
%63 = load i32, i32* %11
store i32 %63, i32* %5
br label %64
64: ; preds = %62, %49
%65 = load i32, i32* %5
ret i32 %65
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i8*, 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"
define i32 @gtg_compress_f2m(%struct.TYPE_4__* %0, i32* nocapture %1, i8* %2, i8* %3) {
%5 = alloca [131072 x i32]
%6 = bitcast [131072 x i32]* %5 to i8*
%7 = call i32 @feof(i32* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %40
9: ; preds = %4
%10 = getelementptr inbounds [131072 x i32], [131072 x i32]* %5, i64 0, i64 0
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 3
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%14 = bitcast i8* %2 to i32*
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%16 = ptrtoint i8* %3 to i64
br label %17
17: ; preds = %9, %32
%18 = phi i64 [ 0, %9 ], [ %35, %32 ]
%19 = call i32 @fread(i32* %10, i32 4, i32 131072, i32* %1)
store i32 %19, i32* %11
store i32* %10, i32** %12
%20 = shl i64 %18, 32
%21 = ashr exact i64 %20, 32
%22 = sub nsw i64 0, %21
%23 = getelementptr i8, i8* %3, i64 %22
store i8* %23, i8** %13
%24 = getelementptr inbounds i32, i32* %14, i64 %21
store i32* %24, i32** %15
%25 = load i32, i32* @Z_SYNC_FLUSH
%26 = call i32 @deflate(%struct.TYPE_4__* %0, i32 %25)
%27 = load i32, i32* @Z_OK
%28 = icmp eq i32 %27, %26
br i1 %28, label %32, label %29
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %40
32: ; preds = %17
%33 = load i8*, i8** %13
%34 = ptrtoint i8* %33 to i64
%35 = sub i64 %16, %34
%36 = call i32 @feof(i32* %1)
%37 = icmp eq i32 %36, 0
br i1 %37, label %17, label %38
38: ; preds = %32
%39 = trunc i64 %35 to i32
br label %40
40: ; preds = %4, %38, %29
%41 = phi i32 [ -1, %29 ], [ %39, %38 ], [ 0, %4 ]
ret i32 %41
}