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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fwrite(void *, long, int, int /*<<< orphan*/ *);
int gu_decompress_file_to_mem(char const *, void **, long *);
int gu_decompress(const char *filename_in, const char *filename_out) {
  FILE *f = NULL;
  void *dst = NULL;
  long size = 0;
  int ret = 0;
  if (0 != (ret = gu_decompress_file_to_mem(filename_in, &dst, &size))) {
    return ret;
  }
  if (NULL == (f = fopen(filename_out, "wb"))) {
    free(dst);
    return 1;
  }
  fwrite(dst, size, 1, f);
  free(dst);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<gu_decompress>:
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)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1070 <gu_decompress_file_to_mem@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
je     11aa <gu_decompress+0x5a>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1210 <gu_decompress+0xc0>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11e1 <gu_decompress+0x91>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1210 <gu_decompress+0xc0>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gu_decompress>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
call   1070 <gu_decompress_file_to_mem@plt>
test   %eax,%eax
jne    11c6 <gu_decompress+0x76>
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    (%rsp),%rdi
test   %rax,%rax
je     11bc <gu_decompress+0x6c>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11c6 <gu_decompress+0x76>
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define i32 @gu_decompress(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i8* null, i8** %7
store i64 0, i64* %8
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = call i32 @gu_decompress_file_to_mem(i8* %10, i8** %7, i64* %8)
store i32 %11, i32* %9
%12 = icmp ne i32 0, %11
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %9
store i32 %14, i32* %3
br label %31
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = icmp eq i32* null, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = call i32 @free(i8* %20)
store i32 1, i32* %3
br label %31
22: ; preds = %15
%23 = load i8*, i8** %7
%24 = load i64, i64* %8
%25 = load i32*, i32** %6
%26 = call i32 @fwrite(i8* %23, i64 %24, i32 1, i32* %25)
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %3
br label %31
31: ; preds = %22, %19, %13
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @gu_decompress(i8* %0, i8* nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = call i32 @gu_decompress_file_to_mem(i8* %0, i8** %3, i64* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %2
%10 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
%12 = load i8*, i8** %3
br i1 %11, label %13, label %15
13: ; preds = %9
%14 = call i32 @free(i8* %12)
br label %21
15: ; preds = %9
%16 = load i64, i64* %4
%17 = call i32 @fwrite(i8* %12, i64 %16, i32 1, i32* %10)
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
%20 = call i32 @fclose(i32* %10)
br label %21
21: ; preds = %2, %15, %13
%22 = phi i32 [ 1, %13 ], [ 0, %15 ], [ %7, %2 ]
ret i32 %22
}