#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 */
struct timespec {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
scalar_t__ EOF;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int create_line(char *, size_t, char *, unsigned int);
int /*<<< orphan*/ elapsed_time_hr(struct timespec, struct timespec, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fsync(int /*<<< orphan*/);
int /*<<< orphan*/ rapl_deinit();
int /*<<< orphan*/ rapl_end();
int /*<<< orphan*/ rapl_init();
int /*<<< orphan*/ rapl_start();
int seek_match(char *, size_t, char *, unsigned int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
size_t strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
void fileparse(unsigned int num_rows) {
  char search_phrase[] = "AdeptProject";
  size_t sp_len = strlen(search_phrase);
  unsigned int desired_line_len = 81;
  char line[desired_line_len];
  srand(time(NULL));
  int i = 0;
  int r = 0;
  int m = 0;
  int mismatch = 0;
  int r_count = 0;
  int m_count = 0;
  struct timespec start, end;
  FILE *fp;
  fp = fopen("testfile", "w+");
  for (i = 0; i < num_rows; i++) {
    r = create_line(search_phrase, sp_len, line, desired_line_len);
    m = seek_match(search_phrase, sp_len, line, desired_line_len);
    if (r != m) {
      mismatch++;
    }
    if (r == 0) {
      r_count++;
    }
    fprintf(fp, "%s\n", line);
  }
  fsync(fileno(fp));
  fclose(fp);
  m = 0;
  rapl_init();
  rapl_start();
  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
  fp = fopen("testfile", "r");
  while (fscanf(fp, "%s\n", line) != EOF) {
    m = seek_match(search_phrase, sp_len, line, desired_line_len);
    if (m == 0) {
      m_count++;
    }
  }
  fclose(fp);
  clock_gettime(CLOCK_MONOTONIC_RAW, &end);
  rapl_end();
  rapl_deinit();
  elapsed_time_hr(start, end, "Fileparse");
  unlink("testfile");
}


x86 assembly (clang, -O0):
<fileparse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
movabs $0x7463656a6f7250,%rax
mov    %rax,-0x13(%rbp)
movabs $0x6f72507470656441,%rax
50 72 6f
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x51,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%edi
call   10b0 <srand@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
lea    0xd4b(%rip),%rdi
lea    0xd4d(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    135d <fileparse+0x13d>
mov    -0x70(%rbp),%rdx
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   10f0 <create_line@plt>
mov    -0x70(%rbp),%rdx
mov    %eax,-0x40(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   10a0 <seek_match@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x44(%rbp),%eax
je     1328 <fileparse+0x108>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    133b <fileparse+0x11b>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rdi
lea    0xccf(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12d9 <fileparse+0xb9>
mov    -0x68(%rbp),%rdi
call   10e0 <fileno@plt>
mov    %eax,%edi
call   1100 <fsync@plt>
mov    -0x68(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x44(%rbp)
mov    $0x0,%al
call   1130 <rapl_init@plt>
mov    $0x0,%al
call   1080 <rapl_start@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
lea    -0x58(%rbp),%rsi
call   1050 <clock_gettime@plt>
lea    0xc69(%rip),%rdi
lea    0xc72(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rdi
lea    0xc56(%rip),%rsi
call   1090 <fscanf@plt>
mov    0x2c19(%rip),%rcx
cmp    (%rcx),%rax
je     1407 <fileparse+0x1e7>
mov    -0x70(%rbp),%rdx
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   10a0 <seek_match@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    1402 <fileparse+0x1e2>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    13b4 <fileparse+0x194>
mov    -0x68(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2bc9(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    $0x0,%al
call   1110 <rapl_end@plt>
mov    $0x0,%al
call   1140 <rapl_deinit@plt>
mov    -0x58(%rbp),%edi
mov    -0x60(%rbp),%esi
lea    0xbe2(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
lea    0xbc4(%rip),%rdi
call   1040 <unlink@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileparse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %edi,%ebp
movabs $0x7463656a6f7250,%rax
mov    %rax,0x1d(%rsp)
movabs $0x6f72507470656441,%rax
50 72 6f
mov    %rax,0x18(%rsp)
lea    0x18(%rsp),%rdi
call   1070 <strlen@plt>
mov    %rax,%r15
mov    %rsp,0x28(%rsp)
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,%edi
call   10b0 <srand@plt>
lea    0xd95(%rip),%rdi
lea    0xd97(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
je     12d9 <fileparse+0xb9>
lea    0x18(%rsp),%r12
lea    0x30(%rsp),%rbx
lea    0xd7d(%rip),%r13
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x51,%ecx
call   10f0 <create_line@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x51,%ecx
call   10a0 <seek_match@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10c0 <fprintf@plt>
add    $0xffffffff,%ebp
jne    12a0 <fileparse+0x80>
mov    %r14,%rdi
call   10e0 <fileno@plt>
mov    %eax,%edi
call   1100 <fsync@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
call   1130 <rapl_init@plt>
xor    %eax,%eax
call   1080 <rapl_start@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1050 <clock_gettime@plt>
lea    0xcf5(%rip),%rdi
lea    0xcfe(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,%rbp
lea    0xceb(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %rax,%rdi
call   1090 <fscanf@plt>
mov    0x2ca6(%rip),%r13
cmp    0x0(%r13),%rax
je     1387 <fileparse+0x167>
lea    0x18(%rsp),%r14
lea    0x30(%rsp),%rbx
lea    0xcc0(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x51,%ecx
call   10a0 <seek_match@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1090 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    1360 <fileparse+0x140>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <clock_gettime@plt>
xor    %eax,%eax
call   1110 <rapl_end@plt>
xor    %eax,%eax
call   1140 <rapl_deinit@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%esi
lea    0xc60(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
lea    0xc42(%rip),%rdi
call   1040 <unlink@plt>
mov    0x28(%rsp),%rsp
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@__const.fileparse.search_phrase = [13 x i8] c"AdeptProject\00"
@.str = [9 x i8] c"testfile\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@CLOCK_MONOTONIC_RAW = global i32 0
@.str.3 = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.4 = [10 x i8] c"Fileparse\00"
define void @fileparse(i32 %0) {
%2 = alloca i32
%3 = alloca [13 x i8]
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.timespec
%15 = alloca %struct.timespec
%16 = alloca i32*
store i32 %0, i32* %2
%17 = bitcast [13 x i8]* %3 to i8*
%18 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %4
store i32 81, i32* %5
%20 = load i32, i32* %5
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %6
%23 = alloca i8, i64 %21
store i64 %21, i64* %7
%24 = call i32 @time(i32* null)
%25 = call i32 @srand(i32 %24)
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%26 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %16
store i32 0, i32* %8
br label %27
27: ; preds = %55, %1
%28 = load i32, i32* %8
%29 = load i32, i32* %2
%30 = icmp ult i32 %28, %29
br i1 %30, label %31, label %58
31: ; preds = %27
%32 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%33 = load i64, i64* %4
%34 = load i32, i32* %5
%35 = call i32 @create_line(i8* %32, i64 %33, i8* %23, i32 %34)
store i32 %35, i32* %9
%36 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%37 = load i64, i64* %4
%38 = load i32, i32* %5
%39 = call i32 @seek_match(i8* %36, i64 %37, i8* %23, i32 %38)
store i32 %39, i32* %10
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %46
43: ; preds = %31
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %46
46: ; preds = %43, %31
%47 = load i32, i32* %9
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %12
%51 = add nsw i32 %50, 1
store i32 %51, i32* %12
br label %52
52: ; preds = %49, %46
%53 = load i32*, i32** %16
%54 = call i32 @fprintf(i32* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %55
55: ; preds = %52
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %27
58: ; preds = %27
%59 = load i32*, i32** %16
%60 = call i32 @fileno(i32* %59)
%61 = call i32 @fsync(i32 %60)
%62 = load i32*, i32** %16
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %10
%64 = call i32 (...) @rapl_init()
%65 = call i32 (...) @rapl_start()
%66 = load i32, i32* @CLOCK_MONOTONIC_RAW
%67 = call i32 @clock_gettime(i32 %66, %struct.timespec* %14)
%68 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %68, i32** %16
br label %69
69: ; preds = %84, %58
%70 = load i32*, i32** %16
%71 = call i64 @fscanf(i32* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%72 = load i64, i64* @EOF
%73 = icmp ne i64 %71, %72
br i1 %73, label %74, label %85
74: ; preds = %69
%75 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%76 = load i64, i64* %4
%77 = load i32, i32* %5
%78 = call i32 @seek_match(i8* %75, i64 %76, i8* %23, i32 %77)
store i32 %78, i32* %10
%79 = load i32, i32* %10
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %74
%82 = load i32, i32* %13
%83 = add nsw i32 %82, 1
store i32 %83, i32* %13
br label %84
84: ; preds = %81, %74
br label %69
85: ; preds = %69
%86 = load i32*, i32** %16
%87 = call i32 @fclose(i32* %86)
%88 = load i32, i32* @CLOCK_MONOTONIC_RAW
%89 = call i32 @clock_gettime(i32 %88, %struct.timespec* %15)
%90 = call i32 (...) @rapl_end()
%91 = call i32 (...) @rapl_deinit()
%92 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 0
%93 = load i32, i32* %92
%94 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 0
%95 = load i32, i32* %94
%96 = call i32 @elapsed_time_hr(i32 %93, i32 %95, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%97 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%98 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@__const.fileparse.search_phrase = [13 x i8] c"AdeptProject\00"
@.str = [9 x i8] c"testfile\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@CLOCK_MONOTONIC_RAW = global i32 0
@.str.3 = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.4 = [10 x i8] c"Fileparse\00"
define void @fileparse(i32 %0) {
%2 = alloca [13 x i8]
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%6 = call i64 @strlen(i8* %5)
%7 = tail call i8* @llvm.stacksave()
%8 = alloca [81 x i8]
%9 = getelementptr inbounds [81 x i8], [81 x i8]* %8, i64 0, i64 0
%10 = tail call i32 @time(i32* null)
%11 = tail call i32 @srand(i32 %10)
%12 = bitcast %struct.timespec* %3 to i8*
%13 = bitcast %struct.timespec* %4 to i8*
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %0, 0
br i1 %15, label %23, label %16
16: ; preds = %1, %16
%17 = phi i32 [ %21, %16 ], [ 0, %1 ]
%18 = call i32 @create_line(i8* %5, i64 %6, i8* %9, i32 81)
%19 = call i32 @seek_match(i8* %5, i64 %6, i8* %9, i32 81)
%20 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%21 = add nuw i32 %17, 1
%22 = icmp eq i32 %21, %0
br i1 %22, label %23, label %16
23: ; preds = %16, %1
%24 = call i32 @fileno(i32* %14)
%25 = call i32 @fsync(i32 %24)
%26 = call i32 @fclose(i32* %14)
%27 = call i32 (...) @rapl_init()
%28 = call i32 (...) @rapl_start()
%29 = load i32, i32* @CLOCK_MONOTONIC_RAW
%30 = call i32 @clock_gettime(i32 %29, %struct.timespec* %3)
%31 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = call i64 @fscanf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %40, label %35
35: ; preds = %23, %35
%36 = call i32 @seek_match(i8* %5, i64 %6, i8* %9, i32 81)
%37 = call i64 @fscanf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%38 = load i64, i64* @EOF
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %35
40: ; preds = %35, %23
%41 = call i32 @fclose(i32* %31)
%42 = load i32, i32* @CLOCK_MONOTONIC_RAW
%43 = call i32 @clock_gettime(i32 %42, %struct.timespec* %4)
%44 = call i32 (...) @rapl_end()
%45 = call i32 (...) @rapl_deinit()
%46 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @elapsed_time_hr(i32 %47, i32 %49, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%51 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
ret void
}