#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 ProgramWrapper(char *, unsigned int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
unsigned int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isspace(unsigned int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int writeBuffer(int, int, int);
int ParseFile(char *Filename) {
  FILE *traceFile;
  unsigned int characterInLine;
  unsigned int operation;
  char lineHolder[100];
  int counter = 0;
  int isSpace = 0;
  int victimCounter = 0;
  int victimReturn = 0;
  traceFile = fopen(Filename, "r");
  if (traceFile == NULL) {
    fprintf(stderr, "fopen failed\n");
    exit(1);
  }
  while (1) {
    characterInLine = fgetc(traceFile);
    if (feof(traceFile)) {
      lineHolder[counter] = '\0';
      if ((isSpace == 0) && (counter > 0)) {
        writeBuffer(-1, 2, -1);
        break;
      } else {
        int returnValue = ProgramWrapper(lineHolder, operation);
        if (returnValue < 0)
          return -1;
      }
      writeBuffer(-1, 2, -1);
      break;
    }
    if (characterInLine == '\n') {
      ++victimCounter;
      if (victimCounter > 3) {
        printf("\n------------------------------------------Write Buffer "
               "eviction because of Timer------------------\n");
        victimReturn = writeBuffer(-1, -1, victimCounter);
        printf("\n------------------------------------------End Write Buffer "
               "Timer Eviction-------------------------\n\n");
        if (victimReturn == -1)
          return -1;
        victimCounter = 0;
      }
      lineHolder[counter] = '\0';
      int returnValue = ProgramWrapper(lineHolder, operation);
      if (returnValue < 0)
        return -1;
      isSpace = 0;
      continue;
    }
    if (isspace(characterInLine)) {
      isSpace = 1;
      counter = 0;
      continue;
    }
    if (!isSpace)
      operation = characterInLine - '0';
    else
      lineHolder[counter] = characterInLine;
    ++counter;
  }
  fclose(traceFile);
  return 0;
}


x86 assembly (clang, -O0):
<ParseFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
movl   $0x0,-0x9c(%rbp)
movl   $0x0,-0xa0(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1215 <ParseFile+0x75>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    121a <ParseFile+0x7a>
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
je     12c1 <ParseFile+0x121>
movslq -0x94(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
cmpl   $0x0,-0x98(%rbp)
jne    1278 <ParseFile+0xd8>
cmpl   $0x0,-0x94(%rbp)
jle    1278 <ParseFile+0xd8>
mov    $0xffffffff,%edx
mov    $0x2,%esi
mov    %edx,%edi
call   1040 <writeBuffer@plt>
jmp    13f3 <ParseFile+0x253>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <ProgramWrapper@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jge    12a6 <ParseFile+0x106>
movl   $0xffffffff,-0x4(%rbp)
jmp    1403 <ParseFile+0x263>
jmp    12ab <ParseFile+0x10b>
mov    $0xffffffff,%edx
mov    $0x2,%esi
mov    %edx,%edi
call   1040 <writeBuffer@plt>
jmp    13f3 <ParseFile+0x253>
cmpl   $0xa,-0x1c(%rbp)
jne    1386 <ParseFile+0x1e6>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
cmpl   $0x3,-0x9c(%rbp)
jle    133a <ParseFile+0x19a>
lea    0xd22(%rip),%rdi
call   1060 <printf@plt>
mov    -0x9c(%rbp),%edx
mov    $0xffffffff,%esi
mov    %esi,%edi
call   1040 <writeBuffer@plt>
mov    %eax,-0xa0(%rbp)
lea    0xd63(%rip),%rdi
call   1060 <printf@plt>
cmpl   $0xffffffff,-0xa0(%rbp)
jne    1330 <ParseFile+0x190>
movl   $0xffffffff,-0x4(%rbp)
jmp    1403 <ParseFile+0x263>
movl   $0x0,-0x9c(%rbp)
movslq -0x94(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <ProgramWrapper@plt>
mov    %eax,-0xa8(%rbp)
cmpl   $0x0,-0xa8(%rbp)
jge    1377 <ParseFile+0x1d7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1403 <ParseFile+0x263>
movl   $0x0,-0x98(%rbp)
jmp    121a <ParseFile+0x7a>
mov    -0x1c(%rbp),%edi
call   1080 <isspace@plt>
cmp    $0x0,%rax
je     13b1 <ParseFile+0x211>
movl   $0x1,-0x98(%rbp)
movl   $0x0,-0x94(%rbp)
jmp    121a <ParseFile+0x7a>
cmpl   $0x0,-0x98(%rbp)
jne    13cc <ParseFile+0x22c>
mov    -0x1c(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x20(%rbp)
jmp    13df <ParseFile+0x23f>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
movslq -0x94(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    121a <ParseFile+0x7a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ParseFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xe4b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1314 <ParseFile+0x174>
mov    %rax,%r13
xor    %ecx,%ecx
xor    %edx,%edx
xor    %ebx,%ebx
mov    %ecx,0xc(%rsp)
movslq %ecx,%r12
mov    %edx,%r14d
jmp    1200 <ParseFile+0x60>
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x10(%rsp,%r12,1)
lea    0x10(%rsp),%rdi
mov    %r15d,%esi
call   1030 <ProgramWrapper@plt>
xor    %r14d,%r14d
mov    %ebp,%ebx
test   %eax,%eax
js     12fc <ParseFile+0x15c>
mov    %r13,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   10a0 <feof@plt>
test   %rax,%rax
jne    12b8 <ParseFile+0x118>
cmp    $0xa,%ebp
jne    1280 <ParseFile+0xe0>
lea    0x1(%rbx),%ebp
cmp    $0x3,%ebx
jl     11e0 <ParseFile+0x40>
lea    0xde1(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%r14d
mov    $0xffffffff,%edi
mov    $0xffffffff,%esi
mov    %ebp,%edx
call   1040 <writeBuffer@plt>
mov    %r15d,%ebx
mov    %eax,%r15d
lea    0xe1c(%rip),%rdi
call   1050 <puts@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%r15d
mov    %ebx,%r15d
jne    11e0 <ParseFile+0x40>
jmp    1302 <ParseFile+0x162>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1080 <isspace@plt>
mov    $0x1,%edx
xor    %ecx,%ecx
test   %rax,%rax
jne    11cc <ParseFile+0x2c>
test   %r14d,%r14d
je     12a3 <ParseFile+0x103>
mov    %bpl,0x10(%rsp,%r12,1)
jmp    12a9 <ParseFile+0x109>
add    $0xffffffd0,%ebp
mov    %ebp,%r15d
mov    0xc(%rsp),%ecx
add    $0x1,%ecx
mov    %r14d,%edx
jmp    11cc <ParseFile+0x2c>
movb   $0x0,0x10(%rsp,%r12,1)
test   %r14d,%r14d
jne    12ca <ParseFile+0x12a>
cmpl   $0x0,0xc(%rsp)
jg     12db <ParseFile+0x13b>
lea    0x10(%rsp),%rdi
mov    %r15d,%esi
call   1030 <ProgramWrapper@plt>
test   %eax,%eax
js     12fc <ParseFile+0x15c>
mov    $0xffffffff,%edi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   1040 <writeBuffer@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
xor    %r14d,%r14d
jmp    1302 <ParseFile+0x162>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
lea    0xcde(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [14 x i8] c"fopen failed\0A\00"
@.str.2 = [101 x i8] c"\0A------------------------------------------Write Buffer eviction because of Timer------------------\0A\00"
@.str.3 = [102 x i8] c"\0A------------------------------------------End Write Buffer Timer Eviction-------------------------\0A\0A\00"
define i32 @ParseFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%14 = load i8*, i8** %3
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %1
br label %23
23: ; preds = %22, %77, %82, %95
%24 = load i32*, i32** %4
%25 = call i32 @fgetc(i32* %24)
store i32 %25, i32* %5
%26 = load i32*, i32** %4
%27 = call i64 @feof(i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %50
29: ; preds = %23
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %31
store i8 0, i8* %32
%33 = load i32, i32* %9
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* %8
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @writeBuffer(i32 -1, i32 2, i32 -1)
br label %98
40: ; preds = %35, %29
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%42 = load i32, i32* %6
%43 = call i32 @ProgramWrapper(i8* %41, i32 %42)
store i32 %43, i32* %12
%44 = load i32, i32* %12
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 -1, i32* %2
br label %101
47: ; preds = %40
br label %48
48: ; preds = %47
%49 = call i32 @writeBuffer(i32 -1, i32 2, i32 -1)
br label %98
50: ; preds = %23
%51 = load i32, i32* %5
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %78
53: ; preds = %50
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp sgt i32 %56, 3
br i1 %57, label %58, label %67
58: ; preds = %53
%59 = call i32 @printf(i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.2, i64 0, i64 0))
%60 = load i32, i32* %10
%61 = call i32 @writeBuffer(i32 -1, i32 -1, i32 %60)
store i32 %61, i32* %11
%62 = call i32 @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* %11
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %66
65: ; preds = %58
store i32 -1, i32* %2
br label %101
66: ; preds = %58
store i32 0, i32* %10
br label %67
67: ; preds = %66, %53
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %69
store i8 0, i8* %70
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%72 = load i32, i32* %6
%73 = call i32 @ProgramWrapper(i8* %71, i32 %72)
store i32 %73, i32* %13
%74 = load i32, i32* %13
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %67
store i32 -1, i32* %2
br label %101
77: ; preds = %67
store i32 0, i32* %9
br label %23
78: ; preds = %50
%79 = load i32, i32* %5
%80 = call i64 @isspace(i32 %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %78
store i32 1, i32* %9
store i32 0, i32* %8
br label %23
83: ; preds = %78
%84 = load i32, i32* %9
%85 = icmp ne i32 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %83
%87 = load i32, i32* %5
%88 = sub i32 %87, 48
store i32 %88, i32* %6
br label %95
89: ; preds = %83
%90 = load i32, i32* %5
%91 = trunc i32 %90 to i8
%92 = load i32, i32* %8
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %93
store i8 %91, i8* %94
br label %95
95: ; preds = %89, %86
%96 = load i32, i32* %8
%97 = add nsw i32 %96, 1
store i32 %97, i32* %8
br label %23
98: ; preds = %48, %38
%99 = load i32*, i32** %4
%100 = call i32 @fclose(i32* %99)
store i32 0, i32* %2
br label %101
101: ; preds = %98, %76, %65, %46
%102 = load i32, i32* %2
ret i32 %102
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [14 x i8] c"fopen failed\0A\00"
@str = [100 x i8] c"\0A------------------------------------------Write Buffer eviction because of Timer------------------\00"
@str.4 = [101 x i8] c"\0A------------------------------------------End Write Buffer Timer Eviction-------------------------\0A\00"
define i32 @ParseFile(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %11, label %6
6: ; preds = %1, %57
%7 = phi i32 [ %59, %57 ], [ 0, %1 ]
%8 = phi i32 [ %16, %57 ], [ 0, %1 ]
%9 = phi i32 [ %17, %57 ], [ 0, %1 ]
%10 = phi i32 [ %58, %57 ], [ undef, %1 ]
br label %45
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %45, %38
%16 = phi i32 [ 0, %38 ], [ %47, %45 ]
%17 = phi i32 [ %39, %38 ], [ %48, %45 ]
%18 = call i32 @fgetc(i32* %4)
%19 = call i64 @feof(i32* %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %15
store i8 0, i8* %50
%22 = icmp eq i32 %16, 0
%23 = icmp sgt i32 %46, 0
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %60, label %25
25: ; preds = %21
%26 = call i32 @ProgramWrapper(i8* %3, i32 %10)
%27 = icmp slt i32 %26, 0
br i1 %27, label %63, label %60
28: ; preds = %15
%29 = icmp eq i32 %18, 10
br i1 %29, label %30, label %42
30: ; preds = %28
%31 = add nsw i32 %17, 1
%32 = icmp sgt i32 %17, 2
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @str, i64 0, i64 0))
%35 = call i32 @writeBuffer(i32 -1, i32 -1, i32 %31)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([101 x i8], [101 x i8]* @str.4, i64 0, i64 0))
%37 = icmp eq i32 %35, -1
br i1 %37, label %63, label %38
38: ; preds = %33, %30
%39 = phi i32 [ %31, %30 ], [ 0, %33 ]
store i8 0, i8* %50
%40 = call i32 @ProgramWrapper(i8* %3, i32 %10)
%41 = icmp slt i32 %40, 0
br i1 %41, label %63, label %15
42: ; preds = %28
%43 = call i64 @isspace(i32 %18)
%44 = icmp eq i64 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %6, %42
%46 = phi i32 [ 0, %42 ], [ %7, %6 ]
%47 = phi i32 [ 1, %42 ], [ %8, %6 ]
%48 = phi i32 [ %17, %42 ], [ %9, %6 ]
%49 = sext i32 %46 to i64
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %49
br label %15
51: ; preds = %42
%52 = icmp eq i32 %16, 0
br i1 %52, label %53, label %55
53: ; preds = %51
%54 = add i32 %18, -48
br label %57
55: ; preds = %51
%56 = trunc i32 %18 to i8
store i8 %56, i8* %50
br label %57
57: ; preds = %55, %53
%58 = phi i32 [ %10, %55 ], [ %54, %53 ]
%59 = add nsw i32 %46, 1
br label %6
60: ; preds = %25, %21
%61 = call i32 @writeBuffer(i32 -1, i32 2, i32 -1)
%62 = call i32 @fclose(i32* %4)
br label %63
63: ; preds = %33, %38, %25, %60
%64 = phi i32 [ 0, %60 ], [ -1, %25 ], [ -1, %38 ], [ -1, %33 ]
ret i32 %64
}