#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int searchFile(char *filename, char *word) {
  FILE *fp = NULL;
  char temp[100], c;
  int count = 0, i;
  if (word == NULL)
    return -1;
  fp = fopen(filename, "r");
  if (NULL == fp) {
    printf("\nERROR: file open failed\n");
    return -1;
  }
  while ((c = getc(fp)) != EOF) {
    if (c != ' ' && c != '\n') {
      temp[i] = c;
      i++;
    } else {
      temp[i] = '\0';
      i = 0;
      if (0 == strcmp(word, temp))
        count++;
    }
  }
  fclose(fp);
  return (count);
}


x86 assembly (clang, -O0):
<searchFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x98(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <searchFile+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1297 <searchFile+0x147>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11c4 <searchFile+0x74>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1297 <searchFile+0x147>
jmp    11c9 <searchFile+0x79>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %al,-0x91(%rbp)
movsbl %al,%eax
mov    0x2e06(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1285 <searchFile+0x135>
movsbl -0x91(%rbp),%eax
cmp    $0x20,%eax
je     1235 <searchFile+0xe5>
movsbl -0x91(%rbp),%eax
cmp    $0xa,%eax
je     1235 <searchFile+0xe5>
mov    -0x91(%rbp),%cl
movslq -0x9c(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1280 <searchFile+0x130>
movslq -0x9c(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
movl   $0x0,-0x9c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    127b <searchFile+0x12b>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1280 <searchFile+0x130>
jmp    11c9 <searchFile+0x79>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x98(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    $0xffffffff,%ebx
test   %rsi,%rsi
je     11ac <searchFile+0x5c>
mov    %rsi,%r14
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a0 <searchFile+0x50>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <getc@plt>
mov    0x2e5a(%rip),%r13
xor    %ebx,%ebx
cmp    0x0(%r13),%al
jne    11bd <searchFile+0x6d>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    11ac <searchFile+0x5c>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
mov    %rsp,%r12
jmp    11f6 <searchFile+0xa6>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x0,(%rsp,%rbp,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebx
xor    %ebp,%ebp
mov    %r15,%rdi
call   1070 <getc@plt>
cmp    0x0(%r13),%al
je     1196 <searchFile+0x46>
movslq %ebp,%rbp
cmp    $0xa,%al
je     11d0 <searchFile+0x80>
cmp    $0x20,%al
je     11d0 <searchFile+0x80>
mov    %al,(%rsp,%rbp,1)
add    $0x1,%ebp
jmp    11e8 <searchFile+0x98>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"\0AERROR: file open failed\0A\00"
@EOF = global i8 0
define i32 @searchFile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [100 x i8]
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i32 0, i32* %9
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %61
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* null, %17
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %61
21: ; preds = %14
br label %22
22: ; preds = %56, %21
%23 = load i32*, i32** %6
%24 = call signext i8 @getc(i32* %23)
store i8 %24, i8* %8
%25 = sext i8 %24 to i32
%26 = load i8, i8* @EOF
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %57
29: ; preds = %22
%30 = load i8, i8* %8
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 32
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load i8, i8* %8
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i8, i8* %8
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %40
store i8 %38, i8* %41
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %56
44: ; preds = %33, %29
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %46
store i8 0, i8* %47
store i32 0, i32* %10
%48 = load i8*, i8** %5
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%50 = call i64 @strcmp(i8* %48, i8* %49)
%51 = icmp eq i64 0, %50
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %55
55: ; preds = %52, %44
br label %56
56: ; preds = %55, %37
br label %22
57: ; preds = %22
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %9
store i32 %60, i32* %3
br label %61
61: ; preds = %57, %19, %13
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@str = [25 x i8] c"\0AERROR: file open failed\00"
define i32 @searchFile(i8* nocapture %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %39, label %6
6: ; preds = %2
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = call signext i8 @getc(i32* %7)
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %36, label %15
13: ; preds = %6
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %39
15: ; preds = %9, %30
%16 = phi i8 [ %33, %30 ], [ %10, %9 ]
%17 = phi i32 [ %32, %30 ], [ undef, %9 ]
%18 = phi i32 [ %31, %30 ], [ 0, %9 ]
switch i8 %16, label %19 [
i8 32, label %23
i8 10, label %23
]
19: ; preds = %15
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %20
store i8 %16, i8* %21
%22 = add nsw i32 %17, 1
br label %30
23: ; preds = %15, %15
%24 = sext i32 %17 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i64 @strcmp(i8* %1, i8* %4)
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = add nsw i32 %18, %28
br label %30
30: ; preds = %23, %19
%31 = phi i32 [ %18, %19 ], [ %29, %23 ]
%32 = phi i32 [ %22, %19 ], [ 0, %23 ]
%33 = call signext i8 @getc(i32* %7)
%34 = load i8, i8* @EOF
%35 = icmp eq i8 %33, %34
br i1 %35, label %36, label %15
36: ; preds = %30, %9
%37 = phi i32 [ 0, %9 ], [ %31, %30 ]
%38 = call i32 @fclose(i32* %7)
br label %39
39: ; preds = %2, %36, %13
%40 = phi i32 [ -1, %13 ], [ %37, %36 ], [ -1, %2 ]
ret i32 %40
}