#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int strcmp2(char *, char *);
int main() {
  char line[256];
  char *query = "TESTING";
  int res;
  FILE *searchFPtr = fopen("7LetterWordlist.txt", "r");
  if (searchFPtr == NULL)
    printf("Search file could not be opened.\n");
  else {
    while (fgets(line, sizeof line, searchFPtr) != NULL) {
      res = strcmp2(line, query);
      if (res == 0) {
        printf("%s found in file\n", query);
        break;
      } else if (res > 0) {
        printf("quitting on word %s\n", line);
        printf("%s not found in file\n", query);
        break;
      }
    }
    fclose(searchFPtr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x118(%rbp)
lea    0xe91(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11ab <main+0x5b>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <main+0x114>
jmp    11b0 <main+0x60>
lea    -0x110(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1258 <main+0x108>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rsi
call   1060 <strcmp2@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0x0,-0x11c(%rbp)
jne    1212 <main+0xc2>
mov    -0x118(%rbp),%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1258 <main+0x108>
cmpl   $0x0,-0x11c(%rbp)
jle    124e <main+0xfe>
lea    -0x110(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1258 <main+0x108>
jmp    1253 <main+0x103>
jmp    11b0 <main+0x60>
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe93(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f9 <main+0x99>
mov    %rax,%r15
mov    %rsp,%rbx
lea    0xe6d(%rip),%r12
lea    0xe84(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11ef <main+0x8f>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strcmp2@plt>
test   %eax,%eax
je     11de <main+0x7e>
jle    11a0 <main+0x40>
lea    0xe63(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe67(%rip),%r14
lea    0xe1b(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    1205 <main+0xa5>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"TESTING\00"
@.str.1 = [20 x i8] c"7LetterWordlist.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [34 x i8] c"Search file could not be opened.\0A\00"
@.str.4 = [18 x i8] c"%s found in file\0A\00"
@.str.5 = [21 x i8] c"quitting on word %s\0A\00"
@.str.6 = [22 x i8] c"%s not found in file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %39
11: ; preds = %0
br label %12
12: ; preds = %35, %11
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%14 = load i32*, i32** %5
%15 = call i32* @fgets(i8* %13, i32 256, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %36
17: ; preds = %12
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @strcmp2(i8* %18, i8* %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %24)
br label %36
26: ; preds = %17
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %32)
br label %36
34: ; preds = %26
br label %35
35: ; preds = %34
br label %12
36: ; preds = %29, %23, %12
%37 = load i32*, i32** %5
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %36, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"TESTING\00"
@.str.1 = [20 x i8] c"7LetterWordlist.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [18 x i8] c"%s found in file\0A\00"
@.str.5 = [21 x i8] c"quitting on word %s\0A\00"
@.str.6 = [22 x i8] c"%s not found in file\0A\00"
@str = [33 x i8] c"Search file could not be opened.\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %22
7: ; preds = %0, %13
%8 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %20, label %10
10: ; preds = %7
%11 = call i32 @strcmp2(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %7
15: ; preds = %13
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %2)
br label %17
17: ; preds = %10, %15
%18 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), %15 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), %10 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %7, %17
%21 = call i32 @fclose(i32* %3)
br label %22
22: ; preds = %20, %5
ret i32 0
}