#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 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 stop = 0, tn;
  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;
  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
  fp = fopen("testfile", "r");
#pragma omp parallel reduction(+ : m_count)
  while (!stop) {
#pragma omp critical
    if (fscanf(fp, "%s\n", line) == EOF) {
      stop = 1;
#pragma omp flush(stop)
    } else {
      m = seek_match(search_phrase, sp_len, line, desired_line_len);
      if (m == 0) {
        m_count++;
      }
    }
  }
  fclose(fp);
  clock_gettime(CLOCK_MONOTONIC_RAW, &end);
  elapsed_time_hr(start, end, "Fileparse");
  unlink("testfile");
}


x86 assembly (clang, -O0):
<fileparse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%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,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
lea    0xd81(%rip),%rdi
lea    0xd83(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1327 <fileparse+0x147>
mov    -0x78(%rbp),%rdx
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   10e0 <create_line@plt>
mov    -0x78(%rbp),%rdx
mov    %eax,-0x40(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   1090 <seek_match@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x44(%rbp),%eax
je     12f2 <fileparse+0x112>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    1305 <fileparse+0x125>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x78(%rbp),%rdx
mov    -0x70(%rbp),%rdi
lea    0xd05(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12a3 <fileparse+0xc3>
mov    -0x70(%rbp),%rdi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   10f0 <fsync@plt>
mov    -0x70(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x44(%rbp)
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
call   1050 <clock_gettime@plt>
lea    0xcad(%rip),%rdi
lea    0xcb6(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x70(%rbp)
cmpl   $0x0,-0x48(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1386 <fileparse+0x1a6>
jmp    13ea <fileparse+0x20a>
mov    -0x78(%rbp),%rdx
mov    -0x70(%rbp),%rdi
lea    0xc84(%rip),%rsi
call   1080 <fscanf@plt>
mov    0x2c47(%rip),%rcx
cmp    (%rcx),%rax
jne    13b6 <fileparse+0x1d6>
movl   $0x1,-0x48(%rbp)
jmp    13e5 <fileparse+0x205>
mov    -0x78(%rbp),%rdx
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   1090 <seek_match@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    13e0 <fileparse+0x200>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    13e5 <fileparse+0x205>
jmp    1370 <fileparse+0x190>
mov    -0x70(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    -0x68(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x60(%rbp),%edi
mov    -0x68(%rbp),%esi
lea    0xc0d(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
lea    0xbef(%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,%r12
mov    %rsp,0x28(%rsp)
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
lea    0xdd5(%rip),%rdi
lea    0xdd7(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
je     1299 <fileparse+0xb9>
lea    0x18(%rsp),%r15
lea    0x30(%rsp),%rbx
lea    0xdbd(%rip),%r13
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    $0x51,%ecx
call   10e0 <create_line@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    $0x51,%ecx
call   1090 <seek_match@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10b0 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1260 <fileparse+0x80>
mov    %r14,%rdi
call   10d0 <fileno@plt>
mov    %eax,%edi
call   10f0 <fsync@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1050 <clock_gettime@plt>
lea    0xd43(%rip),%rdi
lea    0xd4c(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%rbp
lea    0xd39(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %rax,%rdi
call   1080 <fscanf@plt>
mov    0x2cf4(%rip),%r13
cmp    0x0(%r13),%rax
je     1337 <fileparse+0x157>
lea    0x18(%rsp),%r14
lea    0x30(%rsp),%rbx
lea    0xd0e(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    $0x51,%ecx
call   1090 <seek_match@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    1310 <fileparse+0x130>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%esi
lea    0xcbe(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
lea    0xca0(%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 i32
%15 = alloca i32
%16 = alloca %struct.timespec
%17 = alloca %struct.timespec
%18 = alloca i32*
store i32 %0, i32* %2
%19 = bitcast [13 x i8]* %3 to i8*
%20 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %4
store i32 81, i32* %5
%22 = load i32, i32* %5
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %6
%25 = alloca i8, i64 %23
store i64 %23, i64* %7
%26 = call i32 @time(i32* null)
%27 = call i32 @srand(i32 %26)
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%28 = 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* %28, i32** %18
store i32 0, i32* %8
br label %29
29: ; preds = %57, %1
%30 = load i32, i32* %8
%31 = load i32, i32* %2
%32 = icmp ult i32 %30, %31
br i1 %32, label %33, label %60
33: ; preds = %29
%34 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%35 = load i64, i64* %4
%36 = load i32, i32* %5
%37 = call i32 @create_line(i8* %34, i64 %35, i8* %25, i32 %36)
store i32 %37, i32* %9
%38 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%39 = load i64, i64* %4
%40 = load i32, i32* %5
%41 = call i32 @seek_match(i8* %38, i64 %39, i8* %25, i32 %40)
store i32 %41, i32* %10
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %33
%46 = load i32, i32* %13
%47 = add nsw i32 %46, 1
store i32 %47, i32* %13
br label %48
48: ; preds = %45, %33
%49 = load i32, i32* %9
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* %14
%53 = add nsw i32 %52, 1
store i32 %53, i32* %14
br label %54
54: ; preds = %51, %48
%55 = load i32*, i32** %18
%56 = call i32 @fprintf(i32* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %57
57: ; preds = %54
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %29
60: ; preds = %29
%61 = load i32*, i32** %18
%62 = call i32 @fileno(i32* %61)
%63 = call i32 @fsync(i32 %62)
%64 = load i32*, i32** %18
%65 = call i32 @fclose(i32* %64)
store i32 0, i32* %10
%66 = load i32, i32* @CLOCK_MONOTONIC_RAW
%67 = call i32 @clock_gettime(i32 %66, %struct.timespec* %16)
%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** %18
br label %69
69: ; preds = %90, %60
%70 = load i32, i32* %11
%71 = icmp ne i32 %70, 0
%72 = xor i1 %71, true
br i1 %72, label %73, label %91
73: ; preds = %69
%74 = load i32*, i32** %18
%75 = call i64 @fscanf(i32* %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%76 = load i64, i64* @EOF
%77 = icmp eq i64 %75, %76
br i1 %77, label %78, label %79
78: ; preds = %73
store i32 1, i32* %11
br label %90
79: ; preds = %73
%80 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%81 = load i64, i64* %4
%82 = load i32, i32* %5
%83 = call i32 @seek_match(i8* %80, i64 %81, i8* %25, i32 %82)
store i32 %83, i32* %10
%84 = load i32, i32* %10
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %79
%87 = load i32, i32* %15
%88 = add nsw i32 %87, 1
store i32 %88, i32* %15
br label %89
89: ; preds = %86, %79
br label %90
90: ; preds = %89, %78
br label %69
91: ; preds = %69
%92 = load i32*, i32** %18
%93 = call i32 @fclose(i32* %92)
%94 = load i32, i32* @CLOCK_MONOTONIC_RAW
%95 = call i32 @clock_gettime(i32 %94, %struct.timespec* %17)
%96 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 0
%97 = load i32, i32* %96
%98 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 0
%99 = load i32, i32* %98
%100 = call i32 @elapsed_time_hr(i32 %97, i32 %99, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%101 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%102 = 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 = load i32, i32* @CLOCK_MONOTONIC_RAW
%28 = call i32 @clock_gettime(i32 %27, %struct.timespec* %3)
%29 = 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))
%30 = call i64 @fscanf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%31 = load i64, i64* @EOF
%32 = icmp eq i64 %30, %31
br i1 %32, label %38, label %33
33: ; preds = %23, %33
%34 = call i32 @seek_match(i8* %5, i64 %6, i8* %9, i32 81)
%35 = call i64 @fscanf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%36 = load i64, i64* @EOF
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %33
38: ; preds = %33, %23
%39 = call i32 @fclose(i32* %29)
%40 = load i32, i32* @CLOCK_MONOTONIC_RAW
%41 = call i32 @clock_gettime(i32 %40, %struct.timespec* %4)
%42 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @elapsed_time_hr(i32 %43, i32 %45, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
ret void
}