#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ mystrupr(char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
int spell_check(const char *dictionary, const char *word) {
  char buffer[50 + 2], upperWord[50 + 2];
  int wordLength;
  FILE *infile;
  strcpy(upperWord, word);
  mystrupr(upperWord);
  infile = fopen(dictionary, "rt");
  if (infile != NULL) {
    while (!feof(infile)) {
      fgets(buffer, 50 + 1, infile);
      wordLength = strlen(buffer);
      buffer[wordLength - 1] = '\0';
      wordLength--;
      if (strcmp(mystrupr(buffer), upperWord) == 0) {
        fclose(infile);
        return 1;
      }
      if (buffer[0] > upperWord[0]) {
        break;
      }
    }
    fclose(infile);
  } else {
    return -2;
  }
  return 2;
}


x86 assembly (clang, -O0):
<spell_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x90(%rbp),%rdi
call   1090 <mystrupr@plt>
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
je     12a4 <spell_check+0x124>
jmp    11d9 <spell_check+0x59>
mov    -0xa0(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fa <spell_check+0x7a>
jmp    1293 <spell_check+0x113>
lea    -0x50(%rbp),%rdi
mov    -0xa0(%rbp),%rdx
mov    $0x33,%esi
call   1060 <fgets@plt>
lea    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x50(%rbp,%rax,1)
mov    -0x94(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x94(%rbp)
lea    -0x50(%rbp),%rdi
call   1090 <mystrupr@plt>
mov    %eax,%edi
lea    -0x90(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1276 <spell_check+0xf6>
mov    -0xa0(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <spell_check+0x137>
movsbl -0x50(%rbp),%eax
movsbl -0x90(%rbp),%ecx
cmp    %ecx,%eax
jle    128e <spell_check+0x10e>
jmp    1293 <spell_check+0x113>
jmp    11d9 <spell_check+0x59>
mov    -0xa0(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12b0 <spell_check+0x130>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12b7 <spell_check+0x137>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spell_check>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1090 <mystrupr@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     121e <spell_check+0x9e>
mov    %rax,%r14
lea    0x40(%rsp),%rbx
mov    %rsp,%r15
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    122a <spell_check+0xaa>
mov    %rbx,%rdi
mov    $0x33,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1090 <mystrupr@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1225 <spell_check+0xa5>
movzbl 0x40(%rsp),%eax
cmp    (%rsp),%al
jle    11d0 <spell_check+0x50>
jmp    122a <spell_check+0xaa>
mov    $0xfffffffe,%ebp
jmp    1232 <spell_check+0xb2>
mov    $0x1,%ebp
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
define i32 @spell_check(i8* nocapture %0, i8* %1) {
%3 = alloca [52 x i8]
%4 = alloca [52 x i8]
%5 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [52 x i8], [52 x i8]* %4, i64 0, i64 0
%7 = call i32 @strcpy(i8* %6, i8* %1)
%8 = call i32 @mystrupr(i8* %6)
%9 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %30, label %11
11: ; preds = %2, %23
%12 = call i32 @feof(i32* %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %11
%15 = call i32 @fgets(i8* %5, i32 51, i32* %9)
%16 = call i32 @strlen(i8* %5)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @mystrupr(i8* %5)
%21 = call i64 @strcmp(i32 %20, i8* %6)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %14
%24 = load i8, i8* %5
%25 = load i8, i8* %6
%26 = icmp sgt i8 %24, %25
br i1 %26, label %27, label %11
27: ; preds = %11, %23, %14
%28 = phi i32 [ 1, %14 ], [ 2, %23 ], [ 2, %11 ]
%29 = call i32 @fclose(i32* %9)
br label %30
30: ; preds = %27, %2
%31 = phi i32 [ -2, %2 ], [ %28, %27 ]
ret i32 %31
}