#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__ {
  void *avail_out;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
  void *avail_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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
void *fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int gtg_decompress_f2m(z_stream *z, FILE *file_in, void *out_buf,
                       uint32_t out_max_len) {
  int status;
  uint8_t in_buf[(128 * 1024)];
  uint32_t in_len = 0;
  int offset_out = 0;
  while (!feof(file_in)) {
    in_len = fread(in_buf, (128 * 1024), sizeof(uint8_t), file_in);
    z->avail_in = in_len;
    z->next_in = in_buf;
    z->avail_out = out_max_len - offset_out;
    z->next_out = &((uint8_t *)out_buf)[offset_out];
    status = inflate(z, Z_SYNC_FLUSH);
    if (Z_OK != status) {
      fprintf(stderr, "error %d in compressing\n", status);
      return -1;
    }
    offset_out = out_max_len - z->avail_out;
  }
  return offset_out;
}


x86 assembly (clang, -O0):
<gtg_decompress_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)
movq   $0x0,-0x80038(%rbp)
movl   $0x0,-0x8003c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118e <gtg_decompress_f2m+0x4e>
jmp    1265 <gtg_decompress_f2m+0x125>
lea    -0x80030(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x20000,%esi
mov    $0x4,%edx
call   1040 <fread@plt>
mov    %rax,-0x80038(%rbp)
mov    -0x80038(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
lea    -0x80030(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x28(%rbp),%rcx
movslq -0x8003c(%rbp),%rdx
xor    %eax,%eax
sub    %rdx,%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
movslq -0x8003c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
call   1030 <inflate@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
je     124c <gtg_decompress_f2m+0x10c>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xdc5(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126e <gtg_decompress_f2m+0x12e>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %eax,-0x8003c(%rbp)
jmp    1170 <gtg_decompress_f2m+0x30>
mov    -0x8003c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtg_decompress_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_decompress_f2m+0xbd>
xor    %ebp,%ebp
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x20000,%esi
mov    $0x4,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rax,0x18(%rbx)
mov    %r13,0x10(%rbx)
movslq %ebp,%rax
mov    %r15,%rcx
sub    %rax,%rcx
mov    %rcx,(%rbx)
lea    (%r14,%rax,4),%rax
mov    %rax,0x8(%rbx)
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <inflate@plt>
mov    0x2e27(%rip),%rcx
cmp    %eax,(%rcx)
jne    11e1 <gtg_decompress_f2m+0xa1>
mov    %r15,%rbp
sub    (%rbx),%rbp
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1180 <gtg_decompress_f2m+0x40>
jmp    11fd <gtg_decompress_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 { i8*, i32*, i32*, i8* }
@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_decompress_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 [131072 x i32]
%12 = alloca i8*
%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 i8* null, i8** %12
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]* %11, i64 0, i64 0
%21 = load i32*, i32** %7
%22 = call i8* @fread(i32* %20, i32 131072, i32 4, i32* %21)
store i8* %22, i8** %12
%23 = load i8*, i8** %12
%24 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 3
store i8* %23, i8** %25
%26 = getelementptr inbounds [131072 x i32], [131072 x i32]* %11, 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 2
store i32* %26, i32** %28
%29 = load i8*, i8** %9
%30 = load i32, i32* %13
%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 0
store i8* %33, i8** %35
%36 = load i8*, i8** %8
%37 = bitcast i8* %36 to i32*
%38 = load i32, i32* %13
%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 1
store i32* %40, i32** %42
%43 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%44 = load i32, i32* @Z_SYNC_FLUSH
%45 = call i32 @inflate(%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 0
%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* %13
br label %14
62: ; preds = %14
%63 = load i32, i32* %13
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 { i8*, i32*, i32*, i8* }
@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_decompress_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 3
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%14 = bitcast i8* %2 to i32*
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%16 = ptrtoint i8* %3 to i64
br label %17
17: ; preds = %9, %32
%18 = phi i64 [ 0, %9 ], [ %35, %32 ]
%19 = call i8* @fread(i32* %10, i32 131072, i32 4, i32* %1)
store i8* %19, i8** %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 @inflate(%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
}