#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, unsigned int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, unsigned int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ lzs_decode(unsigned char *, unsigned char *, unsigned int *,
                              unsigned int *);
scalar_t__ malloc(unsigned int);
int decode_file(char *in_filename, char *out_filename) {
  FILE *infile, *outfile;
  unsigned char *in, *out;
  unsigned int lengthin = 0, lengthout = 0;
  infile = fopen(in_filename, "rb");
  outfile = fopen(out_filename, "wb");
  if (infile == NULL || outfile == NULL)
    return -1;
  fseek(infile, 0, SEEK_END);
  lengthin = ftell(infile);
  fseek(infile, 0, SEEK_SET);
  in = (unsigned char *)malloc(lengthin);
  out = (unsigned char *)malloc(lengthin * 9);
  fread(in, 1, lengthin, infile);
  lzs_decode(in, out, &lengthin, &lengthout);
  fwrite(out, 1, lengthout, outfile);
  fflush(infile);
  fflush(outfile);
  fclose(infile);
  fclose(outfile);
  free(in);
  free(out);
  return 0;
}


x86 assembly (clang, -O0):
<decode_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11fc <decode_file+0x5c>
cmpq   $0x0,-0x28(%rbp)
jne    1208 <decode_file+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d1 <decode_file+0x131>
mov    -0x20(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x3c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
imul   $0x9,-0x3c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10a0 <lzs_decode@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x28(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
movl   $0x0,(%rsp)
lea    0xe44(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0xe38(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
mov    $0xffffffff,%r14d
test   %rbx,%rbx
je     12a3 <decode_file+0x103>
mov    %rax,%r13
test   %rax,%rax
je     12a3 <decode_file+0x103>
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    %eax,0x4(%rsp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0x0(%rbp,%rbp,8),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %r15,%rdi
mov    %r12,%rsi
call   10a0 <lzs_decode@plt>
mov    (%rsp),%edx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r13,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %r13,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @decode_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %10
store i32 0, i32* %11
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %18, %2
store i32 -1, i32* %3
br label %61
22: ; preds = %18
%23 = load i32*, i32** %6
%24 = load i32, i32* @SEEK_END
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = load i32*, i32** %6
%27 = call i32 @ftell(i32* %26)
store i32 %27, i32* %10
%28 = load i32*, i32** %6
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @fseek(i32* %28, i32 0, i32 %29)
%31 = load i32, i32* %10
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %8
%34 = load i32, i32* %10
%35 = mul i32 %34, 9
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %9
%38 = load i8*, i8** %8
%39 = load i32, i32* %10
%40 = load i32*, i32** %6
%41 = call i32 @fread(i8* %38, i32 1, i32 %39, i32* %40)
%42 = load i8*, i8** %8
%43 = load i8*, i8** %9
%44 = call i32 @lzs_decode(i8* %42, i8* %43, i32* %10, i32* %11)
%45 = load i8*, i8** %9
%46 = load i32, i32* %11
%47 = load i32*, i32** %7
%48 = call i32 @fwrite(i8* %45, i32 1, i32 %46, i32* %47)
%49 = load i32*, i32** %6
%50 = call i32 @fflush(i32* %49)
%51 = load i32*, i32** %7
%52 = call i32 @fflush(i32* %51)
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
%55 = load i32*, i32** %7
%56 = call i32 @fclose(i32* %55)
%57 = load i8*, i8** %8
%58 = call i32 @free(i8* %57)
%59 = load i8*, i8** %9
%60 = call i32 @free(i8* %59)
store i32 0, i32* %3
br label %61
61: ; preds = %22, %21
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @decode_file(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %7, null
%10 = icmp eq i32* %8, null
%11 = or i1 %9, %10
br i1 %11, label %33, label %12
12: ; preds = %2
%13 = load i32, i32* @SEEK_END
%14 = tail call i32 @fseek(i32* %7, i32 0, i32 %13)
%15 = tail call i32 @ftell(i32* %7)
store i32 %15, i32* %3
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @fseek(i32* %7, i32 0, i32 %16)
%18 = tail call i64 @malloc(i32 %15)
%19 = inttoptr i64 %18 to i8*
%20 = mul i32 %15, 9
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = tail call i32 @fread(i8* %19, i32 1, i32 %15, i32* %7)
%24 = call i32 @lzs_decode(i8* %19, i8* %22, i32* %3, i32* %4)
%25 = load i32, i32* %4
%26 = call i32 @fwrite(i8* %22, i32 1, i32 %25, i32* %8)
%27 = call i32 @fflush(i32* %7)
%28 = call i32 @fflush(i32* %8)
%29 = call i32 @fclose(i32* %7)
%30 = call i32 @fclose(i32* %8)
%31 = call i32 @free(i8* %19)
%32 = call i32 @free(i8* %22)
br label %33
33: ; preds = %2, %12
%34 = phi i32 [ 0, %12 ], [ -1, %2 ]
ret i32 %34
}