#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ gzclose_w(int /*<<< orphan*/ *);
int /*<<< orphan*/ *gzopen(char const *, char *);
int /*<<< orphan*/ gzwrite(int /*<<< orphan*/ *, char *, long);
char *malloc(long);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int gu_compress(const char *filename_in, const char *filename_out) {
  gzFile gzf = NULL;
  FILE *f = NULL;
  char *buf = NULL;
  long size = 0;
  if (NULL == (f = fopen(filename_in, "rb"))) {
    return 1;
  }
  fseek(f, 0, SEEK_END);
  size = ftell(f);
  rewind(f);
  buf = malloc(size);
  fread(buf, 1, size, f);
  fclose(f);
  if (NULL == (gzf = gzopen(filename_out, "wb"))) {
    return 1;
  }
  gzwrite(gzf, buf, size);
  gzclose_w(gzf);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<gu_compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    120e <gu_compress+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    12bc <gu_compress+0x10c>
mov    -0x28(%rbp),%rdi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x38(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   10c0 <gzopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1292 <gu_compress+0xe2>
movl   $0x1,-0x4(%rbp)
jmp    12bc <gu_compress+0x10c>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   10b0 <gzwrite@plt>
mov    -0x20(%rbp),%rdi
call   1090 <gzclose_w@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gu_compress>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
lea    0xe3e(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     125d <gu_compress+0xad>
mov    %rax,%rbx
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    $0x1,%ebp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xdd8(%rip),%rsi
mov    %r14,%rdi
call   10c0 <gzopen@plt>
test   %rax,%rax
je     1262 <gu_compress+0xb2>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10b0 <gzwrite@plt>
mov    %rbx,%rdi
call   1090 <gzclose_w@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    1262 <gu_compress+0xb2>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [3 x i8] c"wb\00"
define i32 @gu_compress(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i8* null, i8** %8
store i64 0, i64* %9
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = icmp eq i32* null, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %43
14: ; preds = %2
%15 = load i32*, i32** %7
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %7
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %9
%20 = load i32*, i32** %7
%21 = call i32 @rewind(i32* %20)
%22 = load i64, i64* %9
%23 = call i8* @malloc(i64 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = load i64, i64* %9
%26 = load i32*, i32** %7
%27 = call i32 @fread(i8* %24, i32 1, i64 %25, i32* %26)
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %5
%31 = call i32* @gzopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %6
%32 = icmp eq i32* null, %31
br i1 %32, label %33, label %34
33: ; preds = %14
store i32 1, i32* %3
br label %43
34: ; preds = %14
%35 = load i32*, i32** %6
%36 = load i8*, i8** %8
%37 = load i64, i64* %9
%38 = call i32 @gzwrite(i32* %35, i8* %36, i64 %37)
%39 = load i32*, i32** %6
%40 = call i32 @gzclose_w(i32* %39)
%41 = load i8*, i8** %8
%42 = call i32 @free(i8* %41)
store i32 0, i32* %3
br label %43
43: ; preds = %34, %33, %13
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [3 x i8] c"wb\00"
define i32 @gu_compress(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %3, i32 0, i32 %6)
%8 = tail call i64 @ftell(i32* %3)
%9 = tail call i32 @rewind(i32* %3)
%10 = tail call i8* @malloc(i64 %8)
%11 = tail call i32 @fread(i8* %10, i32 1, i64 %8, i32* %3)
%12 = tail call i32 @fclose(i32* %3)
%13 = tail call i32* @gzopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %19, label %15
15: ; preds = %5
%16 = tail call i32 @gzwrite(i32* %13, i8* %10, i64 %8)
%17 = tail call i32 @gzclose_w(i32* %13)
%18 = tail call i32 @free(i8* %10)
br label %19
19: ; preds = %5, %2, %15
%20 = phi i32 [ 0, %15 ], [ 1, %2 ], [ 1, %5 ]
ret i32 %20
}