#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*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ type_cut(int, int /*<<< orphan*/ *, unsigned char *, size_t);
int cutter(char *file) {
  int totalnum;
  char wpath[FILENAME_MAX];
  size_t bufsize;
  unsigned char *buf = NULL;
  FILE *wfp = NULL, *rfp = NULL;
  int ret = 0, i, j;
  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);
  totalnum = (((unsigned int)(buf)[0]) | ((unsigned int)(buf)[1] << 8));
  printf("Total Num : %d\n", totalnum);
  for (j = 0; j < totalnum; j++) {
    for (i = 0; file[i] != '\0'; i++) {
      if (file[i] == '.') {
        break;
      }
    }
    file[i] = '\0';
    sprintf(wpath, "%s.%03d", file, j);
    wfp = fopen(wpath, "wb");
    if (!wfp) {
      ret = -4;
      goto cutter_err;
    }
    type_cut(j, 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    %rdi,-0x10(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1229 <cutter+0x89>
movl   $0xfffffffe,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    13e1 <cutter+0x241>
mov    -0x48(%rbp),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x48(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    126e <cutter+0xce>
movl   $0xfffffffd,-0x4c(%rbp)
jmp    1398 <cutter+0x1f8>
mov    -0x48(%rbp),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rax
movzbl (%rax),%eax
mov    -0x38(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xd41(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1393 <cutter+0x1f3>
movl   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x50(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1323 <cutter+0x183>
mov    -0x10(%rbp),%rax
movslq -0x50(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1310 <cutter+0x170>
jmp    1323 <cutter+0x183>
jmp    1315 <cutter+0x175>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    12e1 <cutter+0x141>
mov    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x50(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdx
mov    -0x54(%rbp),%ecx
lea    0xcd2(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x60(%rbp),%rdi
lea    0xcca(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1371 <cutter+0x1d1>
movl   $0xfffffffc,-0x4c(%rbp)
jmp    1398 <cutter+0x1f8>
mov    -0x54(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1080 <type_cut@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    12ce <cutter+0x12e>
jmp    1398 <cutter+0x1f8>
cmpq   $0x0,-0x48(%rbp)
je     13ac <cutter+0x20c>
mov    -0x48(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x40(%rbp)
je     13c0 <cutter+0x220>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x38(%rbp)
je     13d4 <cutter+0x234>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
mov    -0x20(%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    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe2b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     130b <cutter+0x16b>
mov    %rax,%r13
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r13,%rdi
call   1070 <ftell@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1312 <cutter+0x172>
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
mov    %r14,-0x40(%rbp)
xor    %r14d,%r14d
mov    %r13,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    -0x40(%rbp),%rdx
mov    %r13,%rcx
call   1040 <fread@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r15,-0x30(%rbp)
movzwl (%r15),%r15d
lea    0xda6(%rip),%rdi
mov    %r15d,%esi
call   1060 <printf@plt>
test   %r15d,%r15d
je     1319 <cutter+0x179>
mov    %r13,-0x38(%rbp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%rax,1),%ecx
test   %cl,%cl
je     12b0 <cutter+0x110>
cmp    $0x2e,%cl
je     12b0 <cutter+0x110>
add    $0x1,%rax
jmp    1290 <cutter+0xf0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %r12,%rdi
lea    0xd53(%rip),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   10c0 <sprintf@plt>
mov    %r12,%rdi
lea    0xd46(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1329 <cutter+0x189>
mov    %rax,%r13
mov    %r14d,%edi
mov    %rax,%rsi
mov    -0x30(%rbp),%rdx
mov    -0x40(%rbp),%rcx
call   1080 <type_cut@plt>
add    $0x1,%r14d
cmp    %r15d,%r14d
jne    1280 <cutter+0xe0>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
jmp    1332 <cutter+0x192>
mov    $0xfffffffe,%ebx
jmp    134b <cutter+0x1ab>
mov    $0xfffffffd,%ebx
jmp    1336 <cutter+0x196>
mov    %r13,%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
mov    -0x30(%rbp),%r15
jmp    1343 <cutter+0x1a3>
mov    $0xfffffffc,%ebx
mov    -0x38(%rbp),%r13
mov    -0x30(%rbp),%r15
mov    %r13,%rdi
call   1050 <fclose@plt>
test   %r15,%r15
je     134b <cutter+0x1ab>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%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 = [16 x i8] c"Total Num : %d\0A\00"
@.str.2 = [8 x i8] c"%s.%03d\00"
@.str.3 = [3 x i8] c"wb\00"
define i32 @cutter(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %3
%15 = load i32, i32* @FILENAME_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca i8, i64 %16
store i64 %16, i64* %6
store i8* null, i8** %8
store i32* null, i32** %9
store i32* null, i32** %10
store i32 0, i32* %11
%19 = load i8*, i8** %3
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %1
store i32 -2, i32* %2
store i32 1, i32* %14
br label %126
24: ; preds = %1
%25 = load i32*, i32** %10
%26 = load i32, i32* @SEEK_END
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i32*, i32** %10
%29 = call i64 @ftell(i32* %28)
store i64 %29, i64* %7
%30 = load i64, i64* %7
%31 = call i64 @malloc(i64 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %36
35: ; preds = %24
store i32 -3, i32* %11
br label %106
36: ; preds = %24
%37 = load i32*, i32** %10
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @fseek(i32* %37, i32 0, i32 %38)
%40 = load i8*, i8** %8
%41 = load i64, i64* %7
%42 = load i32*, i32** %10
%43 = call i32 @fread(i8* %40, i32 1, i64 %41, i32* %42)
%44 = load i32*, i32** %10
%45 = call i32 @fclose(i32* %44)
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = shl i32 %53, 8
%55 = or i32 %49, %54
store i32 %55, i32* %4
%56 = load i32, i32* %4
%57 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %56)
store i32 0, i32* %13
br label %58
58: ; preds = %102, %36
%59 = load i32, i32* %13
%60 = load i32, i32* %4
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %105
62: ; preds = %58
store i32 0, i32* %12
br label %63
63: ; preds = %81, %62
%64 = load i8*, i8** %3
%65 = load i32, i32* %12
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %84
71: ; preds = %63
%72 = load i8*, i8** %3
%73 = load i32, i32* %12
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 46
br i1 %78, label %79, label %80
79: ; preds = %71
br label %84
80: ; preds = %71
br label %81
81: ; preds = %80
%82 = load i32, i32* %12
%83 = add nsw i32 %82, 1
store i32 %83, i32* %12
br label %63
84: ; preds = %79, %63
%85 = load i8*, i8** %3
%86 = load i32, i32* %12
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
store i8 0, i8* %88
%89 = load i8*, i8** %3
%90 = load i32, i32* %13
%91 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %89, i32 %90)
%92 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %92, i32** %9
%93 = load i32*, i32** %9
%94 = icmp ne i32* %93, null
br i1 %94, label %96, label %95
95: ; preds = %84
store i32 -4, i32* %11
br label %106
96: ; preds = %84
%97 = load i32, i32* %13
%98 = load i32*, i32** %9
%99 = load i8*, i8** %8
%100 = load i64, i64* %7
%101 = call i32 @type_cut(i32 %97, i32* %98, i8* %99, i64 %100)
br label %102
102: ; preds = %96
%103 = load i32, i32* %13
%104 = add nsw i32 %103, 1
store i32 %104, i32* %13
br label %58
105: ; preds = %58
br label %106
106: ; preds = %105, %95, %35
%107 = load i32*, i32** %10
%108 = icmp ne i32* %107, null
br i1 %108, label %109, label %112
109: ; preds = %106
%110 = load i32*, i32** %10
%111 = call i32 @fclose(i32* %110)
br label %112
112: ; preds = %109, %106
%113 = load i32*, i32** %9
%114 = icmp ne i32* %113, null
br i1 %114, label %115, label %118
115: ; preds = %112
%116 = load i32*, i32** %9
%117 = call i32 @fclose(i32* %116)
br label %118
118: ; preds = %115, %112
%119 = load i8*, i8** %8
%120 = icmp ne i8* %119, null
br i1 %120, label %121, label %124
121: ; preds = %118
%122 = load i8*, i8** %8
%123 = call i32 @free(i8* %122)
br label %124
124: ; preds = %121, %118
%125 = load i32, i32* %11
store i32 %125, i32* %2
store i32 1, i32* %14
br label %126
126: ; preds = %124, %23
%127 = load i8*, i8** %5
%128 = load i32, i32* %2
ret i32 %128
}

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