#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 */

/* Type definitions */
typedef int uInt;
typedef int /*<<< orphan*/ *gzFile;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int gz_uncompress(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *gzopen(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int file_gzip_uncompress(char *file) {
  char buf[1024];
  char *infile;
  char *outfile;
  FILE *out;
  gzFile in;
  uInt len;
  int retval = 0;
  len = (uInt)strlen(file);
  memset(buf, 0, 1024);
  strcpy(buf, file);
  infile = file;
  outfile = buf;
  outfile[len - ((sizeof("~gz") - 1))] = '\0';
  if ((in = gzopen(infile, "rb")) == NULL) {
    printf("Error: unable to gzopen inputfile: %s\n", infile);
    fflush(stdout);
    return -1;
  }
  if ((out = fopen(outfile, "wb")) == NULL) {
    printf("Error: unable to fopen outputfile: %s\n", outfile);
    fflush(stdout);
    return -1;
  }
  retval = gz_uncompress(in, out);
  if (retval == -1) {
    printf("infile: %s, outfile: %s\n", infile, outfile);
  }
  remove(infile);
  return retval;
}


x86 assembly (clang, -O0):
<file_gzip_uncompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x438(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x434(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
movslq -0x434(%rbp),%rcx
sub    $0x3,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x418(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   10a0 <gzopen@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
jne    125d <file_gzip_uncompress+0xcd>
mov    -0x418(%rbp),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1307 <file_gzip_uncompress+0x177>
mov    -0x420(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    12b0 <file_gzip_uncompress+0x120>
mov    -0x420(%rbp),%rsi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1307 <file_gzip_uncompress+0x177>
mov    -0x430(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1080 <gz_uncompress@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0xffffffff,-0x438(%rbp)
jne    12f2 <file_gzip_uncompress+0x162>
mov    -0x418(%rbp),%rsi
mov    -0x420(%rbp),%rdx
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x418(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x438(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_gzip_uncompress>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
movslq %ebp,%rax
movb   $0x0,-0x3(%rax,%rbx,1)
lea    0xe2e(%rip),%rsi
mov    %r14,%rdi
call   10a0 <gzopen@plt>
test   %rax,%rax
je     1226 <file_gzip_uncompress+0x96>
mov    %rax,%rbp
lea    0xe41(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1232 <file_gzip_uncompress+0xa2>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1080 <gz_uncompress@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    121c <file_gzip_uncompress+0x8c>
lea    0xe45(%rip),%rdi
mov    %rsp,%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <remove@plt>
jmp    1256 <file_gzip_uncompress+0xc6>
lea    0xdd6(%rip),%rdi
mov    %r14,%rsi
jmp    123c <file_gzip_uncompress+0xac>
lea    0xdf4(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [39 x i8] c"Error: unable to gzopen inputfile: %s\0A\00"
@stdout = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [39 x i8] c"Error: unable to fopen outputfile: %s\0A\00"
@.str.4 = [25 x i8] c"infile: %s, outfile: %s\0A\00"
define i32 @file_gzip_uncompress(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %10
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
%13 = trunc i64 %12 to i32
store i32 %13, i32* %9
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 1024)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %3
store i8* %19, i8** %5
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = sub i64 %23, 3
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %5
%27 = call i32* @gzopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %8
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %1
%30 = load i8*, i8** %5
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
store i32 -1, i32* %2
br label %57
34: ; preds = %1
%35 = load i8*, i8** %6
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %36, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @stdout
%42 = call i32 @fflush(i32 %41)
store i32 -1, i32* %2
br label %57
43: ; preds = %34
%44 = load i32*, i32** %8
%45 = load i32*, i32** %7
%46 = call i32 @gz_uncompress(i32* %44, i32* %45)
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %43
%50 = load i8*, i8** %5
%51 = load i8*, i8** %6
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %50, i8* %51)
br label %53
53: ; preds = %49, %43
%54 = load i8*, i8** %5
%55 = call i32 @remove(i8* %54)
%56 = load i32, i32* %10
store i32 %56, i32* %2
br label %57
57: ; preds = %53, %38, %29
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [39 x i8] c"Error: unable to gzopen inputfile: %s\0A\00"
@stdout = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [39 x i8] c"Error: unable to fopen outputfile: %s\0A\00"
@.str.4 = [25 x i8] c"infile: %s, outfile: %s\0A\00"
define i32 @file_gzip_uncompress(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = call i32 @memset(i8* %3, i32 0, i32 1024)
%6 = call i32 @strcpy(i8* %3, i8* %0)
%7 = shl i64 %4, 32
%8 = ashr exact i64 %7, 32
%9 = add nsw i64 %8, -3
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32* @gzopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
br label %31
17: ; preds = %1
%18 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
br label %31
24: ; preds = %17
%25 = call i32 @gz_uncompress(i32* %11, i32* %18)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %3)
br label %29
29: ; preds = %27, %24
%30 = call i32 @remove(i8* %0)
br label %31
31: ; preds = %29, %20, %13
%32 = phi i32 [ -1, %13 ], [ -1, %20 ], [ %25, %29 ]
ret i32 %32
}