#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*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
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);
  for (i = 0; file[i] != '\0'; i++) {
    if (file[i] == '.') {
      break;
    }
  }
  file[i] = '\0';
  sprintf(wpath, "%s.%03d", file, num);
  wfp = fopen(wpath, "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    $0x60,%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,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
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    0xe0b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    121c <cutter+0x8c>
movl   $0xfffffffe,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1388 <cutter+0x1f8>
mov    -0x40(%rbp),%rdi
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1261 <cutter+0xd1>
movl   $0xfffffffd,-0x44(%rbp)
jmp    133f <cutter+0x1af>
mov    -0x40(%rbp),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12dd <cutter+0x14d>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    12ca <cutter+0x13a>
jmp    12dd <cutter+0x14d>
jmp    12cf <cutter+0x13f>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    129b <cutter+0x10b>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%ecx
lea    0xd08(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x58(%rbp),%rdi
lea    0xd00(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    132b <cutter+0x19b>
movl   $0xfffffffc,-0x44(%rbp)
jmp    133f <cutter+0x1af>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1060 <type_lzw@plt>
cmpq   $0x0,-0x40(%rbp)
je     1353 <cutter+0x1c3>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x38(%rbp)
je     1367 <cutter+0x1d7>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
je     137b <cutter+0x1eb>
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
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r13
mov    %edi,%r14d
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe38(%rip),%rsi
mov    %r13,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12d7 <cutter+0x147>
mov    %rax,%r15
mov    %rbx,-0x48(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
call   1070 <ftell@plt>
mov    %r15,%rbx
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     12df <cutter+0x14f>
mov    %r14d,-0x2c(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r12,-0x38(%rbp)
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,-0x40(%rbp)
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %rbx,%r15
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x0(%r13,%r14,1),%eax
test   %al,%al
je     1274 <cutter+0xe4>
cmp    $0x2e,%al
je     1274 <cutter+0xe4>
add    $0x1,%r14
jmp    1260 <cutter+0xd0>
mov    %r14d,%eax
movb   $0x0,0x0(%r13,%rax,1)
lea    0xd7f(%rip),%rsi
mov    -0x48(%rbp),%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
mov    -0x2c(%rbp),%r14d
mov    %r14d,%ecx
call   10b0 <sprintf@plt>
lea    0xd6a(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12ea <cutter+0x15a>
mov    %rax,%r13
mov    %r14d,%edi
mov    %rax,%rsi
mov    -0x38(%rbp),%r12
mov    %r12,%rdx
mov    -0x40(%rbp),%rcx
call   1060 <type_lzw@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %r14d,%r14d
mov    %r13,%r15
jmp    12f4 <cutter+0x164>
mov    $0xfffffffe,%r14d
jmp    1309 <cutter+0x179>
mov    $0xfffffffd,%r14d
mov    %rbx,%r15
jmp    12f4 <cutter+0x164>
mov    $0xfffffffc,%r14d
mov    -0x38(%rbp),%r12
mov    %r15,%rdi
call   1050 <fclose@plt>
test   %r12,%r12
je     1309 <cutter+0x179>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
lea    -0x28(%rbp),%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 = [8 x i8] c"%s.%03d\00"
@.str.2 = [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 %105
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 %85
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)
store i32 0, i32* %13
br label %46
46: ; preds = %64, %36
%47 = load i8*, i8** %5
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %67
54: ; preds = %46
%55 = load i8*, i8** %5
%56 = load i32, i32* %13
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 46
br i1 %61, label %62, label %63
62: ; preds = %54
br label %67
63: ; preds = %54
br label %64
64: ; preds = %63
%65 = load i32, i32* %13
%66 = add nsw i32 %65, 1
store i32 %66, i32* %13
br label %46
67: ; preds = %62, %46
%68 = load i8*, i8** %5
%69 = load i32, i32* %13
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
store i8 0, i8* %71
%72 = load i8*, i8** %5
%73 = load i32, i32* %4
%74 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %72, i32 %73)
%75 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %75, i32** %10
%76 = load i32*, i32** %10
%77 = icmp ne i32* %76, null
br i1 %77, label %79, label %78
78: ; preds = %67
store i32 -4, i32* %12
br label %85
79: ; preds = %67
%80 = load i32, i32* %4
%81 = load i32*, i32** %10
%82 = load i8*, i8** %9
%83 = load i64, i64* %8
%84 = call i32 @type_lzw(i32 %80, i32* %81, i8* %82, i64 %83)
br label %85
85: ; preds = %79, %78, %35
%86 = load i32*, i32** %11
%87 = icmp ne i32* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i32*, i32** %11
%90 = call i32 @fclose(i32* %89)
br label %91
91: ; preds = %88, %85
%92 = load i32*, i32** %10
%93 = icmp ne i32* %92, null
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = load i32*, i32** %10
%96 = call i32 @fclose(i32* %95)
br label %97
97: ; preds = %94, %91
%98 = load i8*, i8** %9
%99 = icmp ne i8* %98, null
br i1 %99, label %100, label %103
100: ; preds = %97
%101 = load i8*, i8** %9
%102 = call i32 @free(i8* %101)
br label %103
103: ; preds = %100, %97
%104 = load i32, i32* %12
store i32 %104, i32* %3
store i32 1, i32* %14
br label %105
105: ; preds = %103, %23
%106 = load i8*, i8** %6
%107 = load i32, i32* %3
ret i32 %107
}

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 = [8 x i8] c"%s.%03d\00"
@.str.2 = [3 x i8] c"wb\00"
define i32 @cutter(i32 %0, i8* %1) {
%3 = load i32, i32* @FILENAME_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %41, label %8
8: ; preds = %2
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %6, i32 0, i32 %9)
%11 = tail call i64 @ftell(i32* %6)
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %35, label %15
15: ; preds = %8
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @fseek(i32* %6, i32 0, i32 %16)
%18 = tail call i32 @fread(i8* %13, i32 1, i64 %11, i32* %6)
%19 = tail call i32 @fclose(i32* %6)
br label %20
20: ; preds = %24, %15
%21 = phi i64 [ %25, %24 ], [ 0, %15 ]
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = load i8, i8* %22
switch i8 %23, label %24 [
i8 0, label %26
i8 46, label %26
]
24: ; preds = %20
%25 = add nuw i64 %21, 1
br label %20
26: ; preds = %20, %20
%27 = and i64 %21, 4294967295
%28 = getelementptr inbounds i8, i8* %1, i64 %27
store i8 0, i8* %28
%29 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %0)
%30 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = tail call i32 @type_lzw(i32 %0, i32* %30, i8* %13, i64 %11)
%34 = tail call i32 @fclose(i32* %6)
br label %35
35: ; preds = %26, %8, %32
%36 = phi i32* [ %30, %32 ], [ %6, %8 ], [ %6, %26 ]
%37 = phi i32 [ 0, %32 ], [ -3, %8 ], [ -4, %26 ]
%38 = tail call i32 @fclose(i32* %36)
br i1 %14, label %41, label %39
39: ; preds = %35
%40 = tail call i32 @free(i8* %13)
br label %41
41: ; preds = %35, %39, %2
%42 = phi i32 [ -2, %2 ], [ %37, %39 ], [ %37, %35 ]
ret i32 %42
}