#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 uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int Z_OK;
int /*<<< orphan*/ Z_SYNC_FLUSH;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int gtg_decompress_m2f(z_stream *z, void *in_buf, uint32_t len,
                       FILE *file_out) {
  int status;
  uint8_t out_buf[(128 * 1024)];
  int offset_out = 0;
  int offset_in = 0;
  int total_written = 0;
  int written = 0;
  while (offset_in < len) {
    z->next_in = &((uint8_t *)in_buf)[offset_in];
    z->avail_in = len - offset_in;
    z->next_out = out_buf;
    z->avail_out = (128 * 1024);
    status = inflate(z, Z_SYNC_FLUSH);
    if (Z_OK != status) {
      fprintf(stderr, "error %d in compressing\n", status);
      return -1;
    }
    offset_out = (128 * 1024) - z->avail_out;
    offset_in = len - z->avail_in;
    written = fwrite(out_buf, 1, offset_out, file_out);
    if (written < offset_out) {
      fprintf(stderr, "warning: %d bytes out of %d written\n", written,
              offset_out);
      return -1;
    }
    total_written += written;
  }
  return total_written;
}


x86 assembly (clang, -O0):
<gtg_decompress_m2f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x80034(%rbp)
movl   $0x0,-0x80038(%rbp)
movl   $0x0,-0x8003c(%rbp)
movl   $0x0,-0x80040(%rbp)
mov    -0x80038(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12ab <gtg_decompress_m2f+0x17b>
mov    -0x18(%rbp),%rcx
movslq -0x80038(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x1c(%rbp),%ecx
sub    -0x80038(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x80030(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x20000,0x4(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
call   1030 <inflate@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
je     1211 <gtg_decompress_m2f+0xe1>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b4 <gtg_decompress_m2f+0x184>
mov    -0x10(%rbp),%rcx
mov    $0x20000,%eax
sub    0x4(%rcx),%eax
mov    %eax,-0x80034(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x80038(%rbp)
lea    -0x80030(%rbp),%rdi
mov    -0x80034(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    %eax,-0x80040(%rbp)
mov    -0x80040(%rbp),%eax
cmp    -0x80034(%rbp),%eax
jge    1294 <gtg_decompress_m2f+0x164>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    -0x80040(%rbp),%edx
mov    -0x80034(%rbp),%ecx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b4 <gtg_decompress_m2f+0x184>
mov    -0x80040(%rbp),%eax
add    -0x8003c(%rbp),%eax
mov    %eax,-0x8003c(%rbp)
jmp    1172 <gtg_decompress_m2f+0x42>
mov    -0x8003c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtg_decompress_m2f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80018,%rsp
mov    %rcx,(%rsp)
mov    %rsi,0x8(%rsp)
test   %edx,%edx
jle    11e6 <gtg_decompress_m2f+0xb6>
mov    %edx,%r12d
mov    %rdi,%rbp
xor    %r15d,%r15d
lea    0x10(%rsp),%rbx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ecx,%rax
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,4),%rcx
mov    %rcx,0x10(%rbp)
mov    %r12d,%ecx
sub    %eax,%ecx
mov    %ecx,0x0(%rbp)
mov    %rbx,0x8(%rbp)
movl   $0x20000,0x4(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1030 <inflate@plt>
mov    0x2e45(%rip),%rcx
cmp    %eax,(%rcx)
jne    11eb <gtg_decompress_m2f+0xbb>
mov    %rbx,%rdi
mov    $0x20000,%r14d
sub    0x4(%rbp),%r14d
mov    0x0(%rbp),%r13d
mov    $0x1,%esi
mov    %r14d,%edx
mov    (%rsp),%rcx
call   1050 <fwrite@plt>
cmp    %r14d,%eax
jl     1206 <gtg_decompress_m2f+0xd6>
mov    %r12d,%ecx
sub    %r13d,%ecx
add    %eax,%r15d
test   %r13d,%r13d
jg     1170 <gtg_decompress_m2f+0x40>
jmp    1228 <gtg_decompress_m2f+0xf8>
xor    %r15d,%r15d
jmp    1228 <gtg_decompress_m2f+0xf8>
mov    0x2dde(%rip),%rcx
mov    (%rcx),%edi
lea    0xe05(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1222 <gtg_decompress_m2f+0xf2>
mov    0x2dc3(%rip),%rcx
mov    (%rcx),%edi
lea    0xe03(%rip),%rsi
mov    %eax,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x80018,%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 = [37 x i8] c"warning: %d bytes out of %d written\0A\00"
define i32 @gtg_decompress_m2f(%struct.TYPE_4__* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca %struct.TYPE_4__*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [131072 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
br label %16
16: ; preds = %70, %4
%17 = load i32, i32* %13
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %74
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = bitcast i8* %21 to i32*
%23 = load i32, i32* %13
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %26, i32 0, i32 3
store i32* %25, i32** %27
%28 = load i32, i32* %8
%29 = load i32, i32* %13
%30 = sub nsw i32 %28, %29
%31 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%32 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = getelementptr inbounds [131072 x i32], [131072 x i32]* %11, i64 0, i64 0
%34 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %34, i32 0, i32 2
store i32* %33, i32** %35
%36 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i32 0, i32 1
store i32 131072, i32* %37
%38 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%39 = load i32, i32* @Z_SYNC_FLUSH
%40 = call i32 @inflate(%struct.TYPE_4__* %38, i32 %39)
store i32 %40, i32* %10
%41 = load i32, i32* @Z_OK
%42 = load i32, i32* %10
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %48
44: ; preds = %20
%45 = load i32, i32* @stderr
%46 = load i32, i32* %10
%47 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %46)
store i32 -1, i32* %5
br label %76
48: ; preds = %20
%49 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%50 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = sub nsw i32 131072, %51
store i32 %52, i32* %12
%53 = load i32, i32* %8
%54 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = sub nsw i32 %53, %56
store i32 %57, i32* %13
%58 = getelementptr inbounds [131072 x i32], [131072 x i32]* %11, i64 0, i64 0
%59 = load i32, i32* %12
%60 = load i32*, i32** %9
%61 = call i32 @fwrite(i32* %58, i32 1, i32 %59, i32* %60)
store i32 %61, i32* %15
%62 = load i32, i32* %15
%63 = load i32, i32* %12
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %70
65: ; preds = %48
%66 = load i32, i32* @stderr
%67 = load i32, i32* %15
%68 = load i32, i32* %12
%69 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %67, i32 %68)
store i32 -1, i32* %5
br label %76
70: ; preds = %48
%71 = load i32, i32* %15
%72 = load i32, i32* %14
%73 = add nsw i32 %72, %71
store i32 %73, i32* %14
br label %16
74: ; preds = %16
%75 = load i32, i32* %14
store i32 %75, i32* %5
br label %76
76: ; preds = %74, %65, %44
%77 = load i32, i32* %5
ret i32 %77
}

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 = [37 x i8] c"warning: %d bytes out of %d written\0A\00"
define i32 @gtg_decompress_m2f(%struct.TYPE_4__* %0, i8* %1, i32 %2, i32* nocapture %3) {
%5 = alloca [131072 x i32]
%6 = bitcast [131072 x i32]* %5 to i8*
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %41
8: ; preds = %4
%9 = bitcast i8* %1 to i32*
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 3
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%12 = getelementptr inbounds [131072 x i32], [131072 x i32]* %5, i64 0, i64 0
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
br label %15
15: ; preds = %8, %37
%16 = phi i32 [ 0, %8 ], [ %39, %37 ]
%17 = phi i32 [ 0, %8 ], [ %38, %37 ]
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %9, i64 %18
store i32* %19, i32** %10
%20 = sub nsw i32 %2, %17
store i32 %20, i32* %11
store i32* %12, i32** %13
store i32 131072, i32* %14
%21 = load i32, i32* @Z_SYNC_FLUSH
%22 = call i32 @inflate(%struct.TYPE_4__* %0, i32 %21)
%23 = load i32, i32* @Z_OK
%24 = icmp eq i32 %23, %22
br i1 %24, label %28, label %25
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %41
28: ; preds = %15
%29 = load i32, i32* %14
%30 = sub nsw i32 131072, %29
%31 = load i32, i32* %11
%32 = call i32 @fwrite(i32* %12, i32 1, i32 %30, i32* %3)
%33 = icmp slt i32 %32, %30
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %30)
br label %41
37: ; preds = %28
%38 = sub nsw i32 %2, %31
%39 = add nsw i32 %32, %16
%40 = icmp sgt i32 %31, 0
br i1 %40, label %15, label %41
41: ; preds = %37, %4, %34, %25
%42 = phi i32 [ -1, %25 ], [ -1, %34 ], [ 0, %4 ], [ %39, %37 ]
ret i32 %42
}