#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 FILENAME_MAX;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
char *get_filename(int, unsigned char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ type_lzw(int, int /*<<< orphan*/ *, unsigned char *, size_t);
int cutter(int num, char *file) {
  char wpath[FILENAME_MAX];
  size_t bufsize;
  unsigned char *buf = NULL;
  FILE *wfp = NULL, *rfp = NULL;
  int ret = 0, i;
  rfp = fopen(file, "rb");
  if (!rfp) {
    return -2;
  }
  fseek(rfp, 0, SEEK_END);
  bufsize = ftell(rfp);
  buf = (unsigned char *)malloc(bufsize);
  if (buf == NULL) {
    ret = -3;
    goto cutter_err;
  }
  fseek(rfp, 0, SEEK_SET);
  fread(buf, 1, bufsize, rfp);
  fclose(rfp);
  wfp = fopen(get_filename(num, buf), "wb");
  if (!wfp) {
    ret = -4;
    goto cutter_err;
  }
  type_lzw(num, wfp, buf, bufsize);
cutter_err:
  if (rfp) {
    fclose(rfp);
  }
  if (wfp) {
    fclose(wfp);
  }
  if (buf) {
    free(buf);
  }
  return ret;
}


x86 assembly (clang, -O0):
<cutter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1204 <cutter+0x74>
movl   $0xfffffffe,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    130f <cutter+0x17f>
mov    -0x40(%rbp),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1249 <cutter+0xb9>
movl   $0xfffffffd,-0x44(%rbp)
jmp    12c6 <cutter+0x136>
mov    -0x40(%rbp),%rdi
mov    0x2d7c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1040 <get_filename@plt>
mov    %rax,%rdi
lea    0xd71(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12b2 <cutter+0x122>
movl   $0xfffffffc,-0x44(%rbp)
jmp    12c6 <cutter+0x136>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1070 <type_lzw@plt>
cmpq   $0x0,-0x40(%rbp)
je     12da <cutter+0x14a>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
cmpq   $0x0,-0x38(%rbp)
je     12ee <cutter+0x15e>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
je     1302 <cutter+0x172>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cutter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %edi,%r14d
lea    0xe58(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     125b <cutter+0xcb>
mov    %rax,%rbx
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     1263 <cutter+0xd3>
mov    %rax,%r13
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14d,%edi
mov    %r13,%rsi
call   1040 <get_filename@plt>
lea    0xdd6(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1273 <cutter+0xe3>
mov    %rax,%rbp
mov    %r14d,%edi
mov    %rax,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
call   1070 <type_lzw@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rbx
jmp    1279 <cutter+0xe9>
mov    $0xfffffffe,%r15d
jmp    1289 <cutter+0xf9>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    $0xfffffffd,%r15d
jmp    1289 <cutter+0xf9>
mov    $0xfffffffc,%r15d
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [3 x i8] c"wb\00"
define i32 @cutter(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%15 = load i32, i32* @FILENAME_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %6
%18 = alloca i8, i64 %16
store i64 %16, i64* %7
store i8* null, i8** %9
store i32* null, i32** %10
store i32* null, i32** %11
store i32 0, i32* %12
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %11
%21 = load i32*, i32** %11
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %2
store i32 -2, i32* %3
store i32 1, i32* %14
br label %79
24: ; preds = %2
%25 = load i32*, i32** %11
%26 = load i32, i32* @SEEK_END
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i32*, i32** %11
%29 = call i64 @ftell(i32* %28)
store i64 %29, i64* %8
%30 = load i64, i64* %8
%31 = call i64 @malloc(i64 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %36
35: ; preds = %24
store i32 -3, i32* %12
br label %59
36: ; preds = %24
%37 = load i32*, i32** %11
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @fseek(i32* %37, i32 0, i32 %38)
%40 = load i8*, i8** %9
%41 = load i64, i64* %8
%42 = load i32*, i32** %11
%43 = call i32 @fread(i8* %40, i32 1, i64 %41, i32* %42)
%44 = load i32*, i32** %11
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* %4
%47 = load i8*, i8** %9
%48 = call i8* @get_filename(i32 %46, i8* %47)
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %49, i32** %10
%50 = load i32*, i32** %10
%51 = icmp ne i32* %50, null
br i1 %51, label %53, label %52
52: ; preds = %36
store i32 -4, i32* %12
br label %59
53: ; preds = %36
%54 = load i32, i32* %4
%55 = load i32*, i32** %10
%56 = load i8*, i8** %9
%57 = load i64, i64* %8
%58 = call i32 @type_lzw(i32 %54, i32* %55, i8* %56, i64 %57)
br label %59
59: ; preds = %53, %52, %35
%60 = load i32*, i32** %11
%61 = icmp ne i32* %60, null
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i32*, i32** %11
%64 = call i32 @fclose(i32* %63)
br label %65
65: ; preds = %62, %59
%66 = load i32*, i32** %10
%67 = icmp ne i32* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32*, i32** %10
%70 = call i32 @fclose(i32* %69)
br label %71
71: ; preds = %68, %65
%72 = load i8*, i8** %9
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = load i8*, i8** %9
%76 = call i32 @free(i8* %75)
br label %77
77: ; preds = %74, %71
%78 = load i32, i32* %12
store i32 %78, i32* %3
store i32 1, i32* %14
br label %79
79: ; preds = %77, %23
%80 = load i8*, i8** %6
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [3 x i8] c"wb\00"
define i32 @cutter(i32 %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %30, 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 i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = tail call i32 @fclose(i32* %3)
br label %30
14: ; preds = %5
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %3, i32 0, i32 %15)
%17 = tail call i32 @fread(i8* %10, i32 1, i64 %8, i32* %3)
%18 = tail call i32 @fclose(i32* %3)
%19 = tail call i8* @get_filename(i32 %0, i8* %10)
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %14
%23 = tail call i32 @type_lzw(i32 %0, i32* %20, i8* %10, i64 %8)
%24 = tail call i32 @fclose(i32* %3)
br label %25
25: ; preds = %14, %22
%26 = phi i32* [ %20, %22 ], [ %3, %14 ]
%27 = phi i32 [ 0, %22 ], [ -4, %14 ]
%28 = tail call i32 @fclose(i32* %26)
%29 = tail call i32 @free(i8* %10)
br label %30
30: ; preds = %12, %25, %2
%31 = phi i32 [ -2, %2 ], [ %27, %25 ], [ -3, %12 ]
ret i32 %31
}