#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__ {
  int avail_in;
  unsigned char *next_in;
  int avail_out;
  unsigned char *next_out;
  void *opaque;
  void *zfree;
  void *zalloc;
  int /*<<< orphan*/ member_0;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ in;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ MAX_WBITS;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ Z_NO_FLUSH;
void *Z_NULL;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int /*<<< orphan*/ inflateInit2(TYPE_1__ *, scalar_t__);
void gzip_decode_file(char *gzfilename, int offset, char *binfilename) {
  FILE *file;
  FILE *fout;
  z_stream strm = {0};
  unsigned char in[0x4000];
  unsigned char out[0x4000];
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  strm.avail_in = 0;
  inflateInit2(&strm, 16 + MAX_WBITS);
  file = fopen(gzfilename, "rb");
  fout = fopen(binfilename, "wb");
  fseek(file, offset, SEEK_SET);
  while (1) {
    int bytes_read;
    bytes_read = fread(in, sizeof(char), sizeof(in), file);
    strm.avail_in = bytes_read;
    strm.next_in = in;
    do {
      strm.avail_out = 0x4000;
      strm.next_out = out;
      inflate(&strm, Z_NO_FLUSH);
      fwrite(out, sizeof(char), 0x4000 - strm.avail_out, fout);
    } while (strm.avail_out == 0);
    if (feof(file)) {
      inflateEnd(&strm);
      break;
    }
  }
  fclose(file);
  fclose(fout);
}


x86 assembly (clang, -O0):
<gzip_decode_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8080,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x68(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x68(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%rsi
add    $0x10,%rsi
lea    -0x68(%rbp),%rdi
call   1060 <inflateInit2@plt>
mov    -0x8(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
lea    -0x4070(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1040 <fread@plt>
mov    %eax,-0x8074(%rbp)
mov    -0x8074(%rbp),%eax
mov    %eax,-0x68(%rbp)
lea    -0x4070(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x4000,-0x58(%rbp)
lea    -0x8070(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdi
call   1030 <inflate@plt>
lea    -0x8070(%rbp),%rdi
mov    $0x4000,%edx
sub    -0x58(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
cmpl   $0x0,-0x58(%rbp)
je     127f <gzip_decode_file+0xdf>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     12eb <gzip_decode_file+0x14b>
lea    -0x68(%rbp),%rdi
call   1090 <inflateEnd@plt>
jmp    12f0 <gzip_decode_file+0x150>
jmp    124b <gzip_decode_file+0xab>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x8080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gzip_decode_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8048,%rsp
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e01(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
movl   $0x0,(%rsp)
mov    0x2e01(%rip),%rax
mov    (%rax),%rsi
add    $0x10,%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   1060 <inflateInit2@plt>
lea    0xe00(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r12d,%esi
call   1090 <fseek@plt>
lea    0x4040(%rsp),%r12
lea    0x40(%rsp),%rbp
mov    0x2d8b(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,(%rsp)
mov    %r12,0x8(%rsp)
nopl   (%rax)
movl   $0x4000,0x10(%rsp)
mov    %rbp,0x18(%rsp)
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1030 <inflate@plt>
mov    $0x4000,%edx
sub    0x10(%rsp),%edx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
cmpl   $0x0,0x10(%rsp)
je     1270 <gzip_decode_file+0xe0>
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     1250 <gzip_decode_file+0xc0>
mov    %rsp,%rdi
call   1080 <inflateEnd@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x8048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i8*, i32, i8*, i8*, i8*, i8*, i32 }
@Z_NULL = global i8* null
@MAX_WBITS = global i64 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@SEEK_SET = global i32 0
@Z_NO_FLUSH = global i32 0
define void @gzip_decode_file(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca %struct.TYPE_5__
%10 = alloca [16384 x i8]
%11 = alloca [16384 x i8]
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%13 = bitcast %struct.TYPE_5__* %9 to i8*
%14 = load i8*, i8** @Z_NULL
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 6
store i8* %14, i8** %15
%16 = load i8*, i8** @Z_NULL
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 5
store i8* %16, i8** %17
%18 = load i8*, i8** @Z_NULL
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 4
store i8* %18, i8** %19
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
store i32 0, i32* %20
%21 = load i64, i64* @MAX_WBITS
%22 = add nsw i64 16, %21
%23 = call i32 @inflateInit2(%struct.TYPE_5__* %9, i64 %22)
%24 = load i8*, i8** %4
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i8*, i8** %6
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i32*, i32** %7
%29 = load i32, i32* %5
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %28, i32 %29, i32 %30)
br label %32
32: ; preds = %3, %62
%33 = getelementptr inbounds [16384 x i8], [16384 x i8]* %10, i64 0, i64 0
%34 = load i32*, i32** %7
%35 = call i32 @fread(i8* %33, i32 1, i32 16384, i32* %34)
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
store i32 %36, i32* %37
%38 = getelementptr inbounds [16384 x i8], [16384 x i8]* %10, i64 0, i64 0
%39 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 1
store i8* %38, i8** %39
br label %40
40: ; preds = %52, %32
%41 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 2
store i32 16384, i32* %41
%42 = getelementptr inbounds [16384 x i8], [16384 x i8]* %11, i64 0, i64 0
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 3
store i8* %42, i8** %43
%44 = load i32, i32* @Z_NO_FLUSH
%45 = call i32 @inflate(%struct.TYPE_5__* %9, i32 %44)
%46 = getelementptr inbounds [16384 x i8], [16384 x i8]* %11, i64 0, i64 0
%47 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 2
%48 = load i32, i32* %47
%49 = sub nsw i32 16384, %48
%50 = load i32*, i32** %8
%51 = call i32 @fwrite(i8* %46, i32 1, i32 %49, i32* %50)
br label %52
52: ; preds = %40
%53 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 2
%54 = load i32, i32* %53
%55 = icmp eq i32 %54, 0
br i1 %55, label %40, label %56
56: ; preds = %52
%57 = load i32*, i32** %7
%58 = call i64 @feof(i32* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 @inflateEnd(%struct.TYPE_5__* %9)
br label %63
62: ; preds = %56
br label %32
63: ; preds = %60
%64 = load i32*, i32** %7
%65 = call i32 @fclose(i32* %64)
%66 = load i32*, i32** %8
%67 = call i32 @fclose(i32* %66)
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i8*, i32, i8*, i8*, i8*, i8*, i32 }
@Z_NULL = global i8* null
@MAX_WBITS = global i64 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@SEEK_SET = global i32 0
@Z_NO_FLUSH = global i32 0
define void @gzip_decode_file(i8* nocapture %0, i32 %1, i8* nocapture %2) {
%4 = alloca %struct.TYPE_5__
%5 = alloca [16384 x i8]
%6 = alloca [16384 x i8]
%7 = bitcast %struct.TYPE_5__* %4 to i8*
%8 = getelementptr inbounds [16384 x i8], [16384 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [16384 x i8], [16384 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 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 0
store i32 0, i32* %14
%15 = load i64, i64* @MAX_WBITS
%16 = add nsw i64 %15, 16
%17 = call i32 @inflateInit2(%struct.TYPE_5__* %4, i64 %16)
%18 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %18, i32 %1, i32 %20)
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 1
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 2
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 3
br label %25
25: ; preds = %35, %3
%26 = call i32 @fread(i8* %8, i32 1, i32 16384, i32* %18)
store i32 %26, i32* %14
store i8* %8, i8** %22
br label %27
27: ; preds = %27, %25
store i32 16384, i32* %23
store i8* %9, i8** %24
%28 = load i32, i32* @Z_NO_FLUSH
%29 = call i32 @inflate(%struct.TYPE_5__* %4, i32 %28)
%30 = load i32, i32* %23
%31 = sub nsw i32 16384, %30
%32 = call i32 @fwrite(i8* %9, i32 1, i32 %31, i32* %19)
%33 = load i32, i32* %23
%34 = icmp eq i32 %33, 0
br i1 %34, label %27, label %35
35: ; preds = %27
%36 = call i64 @feof(i32* %18)
%37 = icmp eq i64 %36, 0
br i1 %37, label %25, label %38
38: ; preds = %35
%39 = call i32 @inflateEnd(%struct.TYPE_5__* %4)
%40 = call i32 @fclose(i32* %18)
%41 = call i32 @fclose(i32* %19)
ret void
}