#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 */
char EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char const *);
int searchInFile(const char *fileName, const char *string, FILE *logFile) {
  FILE *textFile;
  int i = 0;
  int rowNumber = 1;
  int columnNumber = 1;
  int totalOccurence = 0;
  int counter = 0;
  char ch;
  if ((textFile = fopen(fileName, "r")) == NULL) {
    fprintf(stderr, "Failed to open %s. Error: %s\n", fileName,
            strerror(errno));
    return -1;
  }
  for (ch = fgetc(textFile); ch != EOF; ch = fgetc(textFile)) {
    counter++;
    if (ch == '\n') {
      ++rowNumber;
      columnNumber = 1;
    }
    for (i = 0; i < strlen(string); ++i) {
      if (ch == string[i]) {
        ch = fgetc(textFile);
        while (ch == '\t' || ch == ' ' || ch == '\n')
          ch = fgetc(textFile);
      } else
        break;
    }
    if (i == strlen(string)) {
      fprintf(logFile, "%s: [%d,%d] %s first character is found.\n", fileName,
              rowNumber, columnNumber, string);
      ++totalOccurence;
    }
    fseek(textFile, counter, SEEK_SET);
    if (ch != '\n')
      ++columnNumber;
  }
  fclose(textFile);
  return totalOccurence;
}


x86 assembly (clang, -O0):
<searchInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120e <searchInFile+0x9e>
mov    0x2e0c(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a2 <searchInFile+0x232>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x3d(%rbp)
movsbl -0x3d(%rbp),%eax
mov    0x2dc3(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1393 <searchInFile+0x223>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movsbl -0x3d(%rbp),%eax
cmp    $0xa,%eax
jne    1256 <searchInFile+0xe6>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jge    130c <searchInFile+0x19c>
movsbl -0x3d(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    12f4 <searchInFile+0x184>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x3d(%rbp)
movsbl -0x3d(%rbp),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x55(%rbp)
je     12ce <searchInFile+0x15e>
movsbl -0x3d(%rbp),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x55(%rbp)
je     12ce <searchInFile+0x15e>
movsbl -0x3d(%rbp),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    12de <searchInFile+0x16e>
jmp    12ef <searchInFile+0x17f>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x3d(%rbp)
jmp    129d <searchInFile+0x12d>
jmp    12f9 <searchInFile+0x189>
jmp    130c <searchInFile+0x19c>
jmp    12fe <searchInFile+0x18e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    125d <searchInFile+0xed>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cmp    %ecx,%eax
jne    1352 <searchInFile+0x1e2>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x18(%rbp),%r9
lea    0xcde(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    0x2c68(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
movsbl -0x3d(%rbp),%eax
cmp    $0xa,%eax
je     137d <searchInFile+0x20d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1382 <searchInFile+0x212>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x3d(%rbp)
jmp    121a <searchInFile+0xaa>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchInFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x20(%rsp)
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11cf <searchInFile+0x5f>
mov    %rax,%rbx
mov    %rbp,0x18(%rsp)
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r14d
mov    0x2e34(%rip),%rax
movl   $0x0,0xc(%rsp)
cmp    (%rax),%r14b
jne    1212 <searchInFile+0xa2>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
jmp    1203 <searchInFile+0x93>
mov    0x2e02(%rip),%rax
movslq (%rax),%rbx
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movabs $0x100000600,%rbp
xor    %r15d,%r15d
movl   $0x0,0xc(%rsp)
mov    $0x1,%r13d
movl   $0x1,0x8(%rsp)
jmp    12ab <searchInFile+0x13b>
nopw   0x0(%rax,%rax,1)
mov    0x20(%rsp),%rdi
lea    0xdd4(%rip),%rsi
mov    0x18(%rsp),%rdx
mov    %r15d,%ecx
mov    0x14(%rsp),%r13d
mov    %r13d,%r8d
mov    %r12,%r9
xor    %eax,%eax
call   1060 <fprintf@plt>
addl   $0x1,0xc(%rsp)
mov    0x10(%rsp),%r15d
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1070 <fseek@plt>
xor    %eax,%eax
cmp    $0xa,%r14b
setne  %al
add    %eax,%r13d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r14d
mov    0x2d46(%rip),%rax
cmp    (%rax),%r14b
je     11c1 <searchInFile+0x51>
cmp    $0xa,%r14b
sete   0x7(%rsp)
mov    $0x1,%eax
cmove  %eax,%r13d
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
mov    %r15d,0x10(%rsp)
mov    %r13d,0x14(%rsp)
jle    1330 <searchInFile+0x1c0>
xor    %r15d,%r15d
xor    %r13d,%r13d
mov    0x8(%rsp),%eax
jmp    12fb <searchInFile+0x18b>
nop
add    $0x1,%r15
add    $0x1,%r13d
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%r15
mov    0x8(%rsp),%eax
jge    1343 <searchInFile+0x1d3>
cmp    (%r12,%r15,1),%r14b
jne    1340 <searchInFile+0x1d0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r14d
cmp    $0x20,%al
ja     12e0 <searchInFile+0x170>
movzbl %r14b,%eax
bt     %rax,%rbp
jb     1310 <searchInFile+0x1a0>
jmp    12e0 <searchInFile+0x170>
nopl   0x0(%rax,%rax,1)
xor    %r13d,%r13d
mov    0x8(%rsp),%eax
jmp    1343 <searchInFile+0x1d3>
nopl   0x0(%rax)
mov    %r15d,%r13d
addl   $0x1,0x10(%rsp)
xor    %ecx,%ecx
mov    0x7(%rsp),%dl
mov    %dl,%cl
add    %ecx,%eax
mov    %r12,%rdi
mov    %eax,%r15d
call   1040 <strlen@plt>
cmp    %eax,%r13d
mov    %r15d,0x8(%rsp)
je     1240 <searchInFile+0xd0>
mov    0x14(%rsp),%r13d
jmp    126b <searchInFile+0xfb>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Failed to open %s. Error: %s\0A\00"
@errno = global i32 0
@EOF = global i8 0
@.str.2 = [42 x i8] c"%s: [%d,%d] %s first character is found.\0A\00"
@SEEK_SET = global i32 0
define i32 @searchInFile(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 0, i32* %9
store i32 1, i32* %10
store i32 1, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %26
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i32*
%22 = load i8*, i8** %5
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %24)
store i32 -1, i32* %4
br label %119
26: ; preds = %3
%27 = load i32*, i32** %8
%28 = call signext i8 @fgetc(i32* %27)
store i8 %28, i8* %14
br label %29
29: ; preds = %112, %26
%30 = load i8, i8* %14
%31 = sext i8 %30 to i32
%32 = load i8, i8* @EOF
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %31, %33
br i1 %34, label %35, label %115
35: ; preds = %29
%36 = load i32, i32* %13
%37 = add nsw i32 %36, 1
store i32 %37, i32* %13
%38 = load i8, i8* %14
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
store i32 1, i32* %11
br label %44
44: ; preds = %41, %35
store i32 0, i32* %9
br label %45
45: ; preds = %83, %44
%46 = load i32, i32* %9
%47 = load i8*, i8** %6
%48 = call i32 @strlen(i8* %47)
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %86
50: ; preds = %45
%51 = load i8, i8* %14
%52 = sext i8 %51 to i32
%53 = load i8*, i8** %6
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %52, %58
br i1 %59, label %60, label %81
60: ; preds = %50
%61 = load i32*, i32** %8
%62 = call signext i8 @fgetc(i32* %61)
store i8 %62, i8* %14
br label %63
63: ; preds = %77, %60
%64 = load i8, i8* %14
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 9
br i1 %66, label %75, label %67
67: ; preds = %63
%68 = load i8, i8* %14
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 32
br i1 %70, label %75, label %71
71: ; preds = %67
%72 = load i8, i8* %14
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 10
br label %75
75: ; preds = %71, %67, %63
%76 = phi i1 [ true, %67 ], [ true, %63 ], [ %74, %71 ]
br i1 %76, label %77, label %80
77: ; preds = %75
%78 = load i32*, i32** %8
%79 = call signext i8 @fgetc(i32* %78)
store i8 %79, i8* %14
br label %63
80: ; preds = %75
br label %82
81: ; preds = %50
br label %86
82: ; preds = %80
br label %83
83: ; preds = %82
%84 = load i32, i32* %9
%85 = add nsw i32 %84, 1
store i32 %85, i32* %9
br label %45
86: ; preds = %81, %45
%87 = load i32, i32* %9
%88 = load i8*, i8** %6
%89 = call i32 @strlen(i8* %88)
%90 = icmp eq i32 %87, %89
br i1 %90, label %91, label %100
91: ; preds = %86
%92 = load i32*, i32** %7
%93 = load i8*, i8** %5
%94 = load i32, i32* %10
%95 = load i32, i32* %11
%96 = load i8*, i8** %6
%97 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %93, i32 %94, i32 %95, i8* %96)
%98 = load i32, i32* %12
%99 = add nsw i32 %98, 1
store i32 %99, i32* %12
br label %100
100: ; preds = %91, %86
%101 = load i32*, i32** %8
%102 = load i32, i32* %13
%103 = load i32, i32* @SEEK_SET
%104 = call i32 @fseek(i32* %101, i32 %102, i32 %103)
%105 = load i8, i8* %14
%106 = sext i8 %105 to i32
%107 = icmp ne i32 %106, 10
br i1 %107, label %108, label %111
108: ; preds = %100
%109 = load i32, i32* %11
%110 = add nsw i32 %109, 1
store i32 %110, i32* %11
br label %111
111: ; preds = %108, %100
br label %112
112: ; preds = %111
%113 = load i32*, i32** %8
%114 = call signext i8 @fgetc(i32* %113)
store i8 %114, i8* %14
br label %29
115: ; preds = %29
%116 = load i32*, i32** %8
%117 = call i32 @fclose(i32* %116)
%118 = load i32, i32* %12
store i32 %118, i32* %4
br label %119
119: ; preds = %115, %18
%120 = load i32, i32* %4
ret i32 %120
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Failed to open %s. Error: %s\0A\00"
@errno = global i32 0
@EOF = global i8 0
@.str.2 = [42 x i8] c"%s: [%d,%d] %s first character is found.\0A\00"
@SEEK_SET = global i32 0
define i32 @searchInFile(i8* %0, i8* %1, i32* nocapture %2) {
%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 %6, label %13
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %11)
br label %69
13: ; preds = %3
%14 = tail call signext i8 @fgetc(i32* %4)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %66, label %17
17: ; preds = %13, %56
%18 = phi i8 [ %63, %56 ], [ %14, %13 ]
%19 = phi i32 [ %23, %56 ], [ 0, %13 ]
%20 = phi i32 [ %57, %56 ], [ 0, %13 ]
%21 = phi i32 [ %62, %56 ], [ 1, %13 ]
%22 = phi i32 [ %26, %56 ], [ 1, %13 ]
%23 = add nuw nsw i32 %19, 1
%24 = icmp eq i8 %18, 10
%25 = zext i1 %24 to i32
%26 = add nuw nsw i32 %22, %25
%27 = select i1 %24, i32 1, i32 %21
%28 = tail call i32 @strlen(i8* %1)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %48
30: ; preds = %17, %40
%31 = phi i64 [ %41, %40 ], [ 0, %17 ]
%32 = phi i8 [ %38, %40 ], [ %18, %17 ]
%33 = phi i32 [ %42, %40 ], [ 0, %17 ]
%34 = getelementptr inbounds i8, i8* %1, i64 %31
%35 = load i8, i8* %34
%36 = icmp eq i8 %32, %35
br i1 %36, label %37, label %46
37: ; preds = %30, %39
%38 = tail call signext i8 @fgetc(i32* %4)
switch i8 %38, label %40 [
i8 32, label %39
i8 10, label %39
i8 9, label %39
]
39: ; preds = %37, %37, %37
br label %37
40: ; preds = %37
%41 = add nuw nsw i64 %31, 1
%42 = add nuw nsw i32 %33, 1
%43 = tail call i32 @strlen(i8* %1)
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %41, %44
br i1 %45, label %30, label %48
46: ; preds = %30
%47 = trunc i64 %31 to i32
br label %48
48: ; preds = %40, %46, %17
%49 = phi i32 [ 0, %17 ], [ %47, %46 ], [ %42, %40 ]
%50 = phi i8 [ %18, %17 ], [ %32, %46 ], [ %38, %40 ]
%51 = tail call i32 @strlen(i8* %1)
%52 = icmp eq i32 %49, %51
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %26, i32 %27, i8* %1)
%55 = add nsw i32 %20, 1
br label %56
56: ; preds = %53, %48
%57 = phi i32 [ %55, %53 ], [ %20, %48 ]
%58 = load i32, i32* @SEEK_SET
%59 = tail call i32 @fseek(i32* %4, i32 %23, i32 %58)
%60 = icmp ne i8 %50, 10
%61 = zext i1 %60 to i32
%62 = add nsw i32 %27, %61
%63 = tail call signext i8 @fgetc(i32* %4)
%64 = load i8, i8* @EOF
%65 = icmp eq i8 %63, %64
br i1 %65, label %66, label %17
66: ; preds = %56, %13
%67 = phi i32 [ 0, %13 ], [ %57, %56 ]
%68 = tail call i32 @fclose(i32* %4)
br label %69
69: ; preds = %66, %6
%70 = phi i32 [ -1, %6 ], [ %67, %66 ]
ret i32 %70
}