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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int gz_compress(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *gzopen(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int file_gzip_compress(char *file, char *mode) {
  char outfile[1024];
  FILE *in;
  gzFile out;
  int retval = 0;
  memset(outfile, 0, 1024);
  strcpy(outfile, file);
  strcat(outfile, "~gz");
  if ((in = fopen(file, "rb")) == NULL) {
    printf("Error: unable to fopen inputfile: %s\n", file);
    fflush(stdout);
    return -1;
  }
  if ((out = gzopen(outfile, mode)) == NULL) {
    printf("Error: unable to gzopen outputfile: %s\n", outfile);
    fflush(stdout);
    return -1;
  }
  retval = gz_compress(in, out);
  return retval;
}


x86 assembly (clang, -O0):
<file_gzip_compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x434(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    121e <file_gzip_compress+0x9e>
mov    -0x10(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <file_gzip_compress+0x10e>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <gzopen@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
jne    126c <file_gzip_compress+0xec>
lea    -0x420(%rbp),%rsi
lea    0xde0(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <file_gzip_compress+0x10e>
mov    -0x428(%rbp),%rdi
mov    -0x430(%rbp),%rsi
call   1040 <gz_compress@plt>
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_gzip_compress>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe4a(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strcat@plt>
lea    0xe3f(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f2 <file_gzip_compress+0x72>
mov    %rax,%r15
mov    %rsp,%rdi
mov    %r14,%rsi
call   1080 <gzopen@plt>
test   %rax,%rax
je     11fe <file_gzip_compress+0x7e>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <gz_compress@plt>
jmp    1220 <file_gzip_compress+0xa0>
lea    0xe0e(%rip),%rdi
mov    %rbx,%rsi
jmp    1208 <file_gzip_compress+0x88>
lea    0xe28(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0xffffffff,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"~gz\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [38 x i8] c"Error: unable to fopen inputfile: %s\0A\00"
@stdout = global i32 0
@.str.3 = [40 x i8] c"Error: unable to gzopen outputfile: %s\0A\00"
define i32 @file_gzip_compress(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %9
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 1024)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
store i32 -1, i32* %3
br label %40
25: ; preds = %2
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i32* @gzopen(i8* %26, i8* %27)
store i32* %28, i32** %8
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @stdout
%34 = call i32 @fflush(i32 %33)
store i32 -1, i32* %3
br label %40
35: ; preds = %25
%36 = load i32*, i32** %7
%37 = load i32*, i32** %8
%38 = call i32 @gz_compress(i32* %36, i32* %37)
store i32 %38, i32* %9
%39 = load i32, i32* %9
store i32 %39, i32* %3
br label %40
40: ; preds = %35, %30, %20
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [4 x i8] c"~gz\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [38 x i8] c"Error: unable to fopen inputfile: %s\0A\00"
@stdout = global i32 0
@.str.3 = [40 x i8] c"Error: unable to gzopen outputfile: %s\0A\00"
define i32 @file_gzip_compress(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 1024)
%6 = call i32 @strcpy(i8* %4, i8* %0)
%7 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
br label %23
14: ; preds = %2
%15 = call i32* @gzopen(i8* %4, i8* %1)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
br label %23
21: ; preds = %14
%22 = call i32 @gz_compress(i32* %8, i32* %15)
br label %23
23: ; preds = %21, %17, %10
%24 = phi i32 [ -1, %10 ], [ -1, %17 ], [ %22, %21 ]
ret i32 %24
}