#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int ok(int, char *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char *word;
  char want[16];
  int f;
  if (argc != 2) {
    printf("Input error\n");
    printf("Correct usage: ok <word>\n");
    return -1;
  }
  word = argv[1];
  int file = open("/cs_Share/class/cs360/lib/webster", O_RDONLY, 0);
  if (file < 0) {
    printf("The dictionary does not exist\n");
    return -1;
  }
  int eof = (int)lseek(file, 0, SEEK_END);
  if (eof < 0) {
    printf("There was an error reading the file\n");
    return -1;
  }
  for (int n = 0; n < (strlen(word)); n++) {
    want[n] = word[n];
    f = n;
  }
  while (f < 15) {
    f++;
    want[f] = ' ';
  }
  want[15] = '\0';
  int status = ok(file, want);
  if (status == 1)
    printf("yes\n");
  else if (status == 2) {
    printf("There was an error reading the file\n");
    return 2;
  } else
    printf("no\n");
  close(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a4 <main+0x44>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <main+0x1a4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11ec <main+0x8c>
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <main+0x1a4>
mov    -0x38(%rbp),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1224 <main+0xc4>
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <main+0x1a4>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
cmp    %ecx,%eax
jge    126e <main+0x10e>
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x40(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x40(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    122b <main+0xcb>
jmp    1273 <main+0x113>
cmpl   $0xf,-0x34(%rbp)
jge    1294 <main+0x134>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
movb   $0x20,-0x30(%rbp,%rax,1)
jmp    1273 <main+0x113>
movb   $0x0,-0x21(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1030 <ok@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x1,-0x44(%rbp)
jne    12c2 <main+0x162>
lea    0xdd5(%rip),%rdi
call   1050 <printf@plt>
jmp    12f5 <main+0x195>
cmpl   $0x2,-0x44(%rbp)
jne    12e4 <main+0x184>
lea    0xd95(%rip),%rdi
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1304 <main+0x1a4>
lea    0xda7(%rip),%rdi
call   1050 <printf@plt>
jmp    12f5 <main+0x195>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1248 <main+0xd8>
mov    0x8(%rsi),%rbx
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
xor    %edx,%edx
call   1090 <open@plt>
test   %eax,%eax
js     125d <main+0xed>
mov    %eax,%r14d
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
test   $0x80000000,%eax
jne    1266 <main+0xf6>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    121b <main+0xab>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx,%rbp,1),%eax
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     11e0 <main+0x70>
lea    -0x1(%rbp),%eax
cmp    $0xe,%eax
jg     121b <main+0xab>
lea    (%rsp,%rbp,1),%rdi
mov    $0xf,%edx
sub    %ebp,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1070 <memset@plt>
movb   $0x0,0xf(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
call   1040 <ok@plt>
cmp    $0x1,%eax
je     1280 <main+0x110>
cmp    $0x2,%eax
jne    1289 <main+0x119>
lea    0xded(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
jmp    1277 <main+0x107>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1c(%rip),%rdi
jmp    126d <main+0xfd>
lea    0xde9(%rip),%rdi
jmp    126d <main+0xfd>
lea    0xdbc(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd9e(%rip),%rdi
jmp    1290 <main+0x120>
lea    0xd92(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
jmp    1277 <main+0x107>

LLVM IR (-O0):
@.str = [13 x i8] c"Input error\0A\00"
@.str.1 = [26 x i8] c"Correct usage: ok <word>\0A\00"
@.str.2 = [34 x i8] c"/cs_Share/class/cs360/lib/webster\00"
@O_RDONLY = global i32 0
@.str.3 = [31 x i8] c"The dictionary does not exist\0A\00"
@SEEK_END = global i32 0
@.str.4 = [37 x i8] c"There was an error reading the file\0A\00"
@.str.5 = [5 x i8] c"yes\0A\00"
@.str.6 = [4 x i8] c"no\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [16 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = 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 %86
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 0)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %86
28: ; preds = %18
%29 = load i32, i32* %9
%30 = load i32, i32* @SEEK_END
%31 = call i64 @lseek(i32 %29, i32 0, i32 %30)
%32 = trunc i64 %31 to i32
store i32 %32, i32* %10
%33 = load i32, i32* %10
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %86
37: ; preds = %28
store i32 0, i32* %11
br label %38
38: ; preds = %53, %37
%39 = load i32, i32* %11
%40 = load i8*, i8** %6
%41 = call i32 @strlen(i8* %40)
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %56
43: ; preds = %38
%44 = load i8*, i8** %6
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %50
store i8 %48, i8* %51
%52 = load i32, i32* %11
store i32 %52, i32* %8
br label %53
53: ; preds = %43
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %38
56: ; preds = %38
br label %57
57: ; preds = %60, %56
%58 = load i32, i32* %8
%59 = icmp slt i32 %58, 15
br i1 %59, label %60, label %66
60: ; preds = %57
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %64
store i8 32, i8* %65
br label %57
66: ; preds = %57
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 15
store i8 0, i8* %67
%68 = load i32, i32* %9
%69 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%70 = call i32 @ok(i32 %68, i8* %69)
store i32 %70, i32* %12
%71 = load i32, i32* %12
%72 = icmp eq i32 %71, 1
br i1 %72, label %73, label %75
73: ; preds = %66
%74 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %83
75: ; preds = %66
%76 = load i32, i32* %12
%77 = icmp eq i32 %76, 2
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %86
80: ; preds = %75
%81 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %82
82: ; preds = %80
br label %83
83: ; preds = %82, %73
%84 = load i32, i32* %9
%85 = call i32 @close(i32 %84)
store i32 0, i32* %3
br label %86
86: ; preds = %83, %78, %35, %26, %15
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str.2 = [34 x i8] c"/cs_Share/class/cs360/lib/webster\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@str = [3 x i8] c"no\00"
@str.8 = [4 x i8] c"yes\00"
@str.9 = [36 x i8] c"There was an error reading the file\00"
@str.10 = [30 x i8] c"The dictionary does not exist\00"
@str.11 = [12 x i8] c"Input error\00"
@str.12 = [25 x i8] c"Correct usage: ok <word>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
br label %57
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
br label %57
17: ; preds = %9
%18 = load i32, i32* @SEEK_END
%19 = tail call i64 @lseek(i32 %13, i32 0, i32 %18)
%20 = and i64 %19, 2147483648
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @strlen(i8* %11)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %38, label %47
25: ; preds = %17
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
br label %57
27: ; preds = %38
%28 = trunc i64 %39 to i32
%29 = icmp slt i32 %28, 15
br i1 %29, label %30, label %47
30: ; preds = %27
%31 = shl i64 %39, 32
%32 = ashr exact i64 %31, 32
%33 = add nsw i64 %32, 1
%34 = getelementptr [16 x i8], [16 x i8]* %3, i64 0, i64 %33
%35 = sub nsw i64 14, %39
%36 = and i64 %35, 4294967295
%37 = add nuw nsw i64 %36, 1
br label %47
38: ; preds = %22, %38
%39 = phi i64 [ %43, %38 ], [ 0, %22 ]
%40 = getelementptr inbounds i8, i8* %11, i64 %39
%41 = load i8, i8* %40
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %39
store i8 %41, i8* %42
%43 = add nuw nsw i64 %39, 1
%44 = tail call i32 @strlen(i8* %11)
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %43, %45
br i1 %46, label %38, label %27
47: ; preds = %22, %30, %27
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 15
store i8 0, i8* %48
%49 = call i32 @ok(i32 %13, i8* %4)
switch i32 %49, label %52 [
i32 1, label %53
i32 2, label %50
]
50: ; preds = %47
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
br label %57
52: ; preds = %47
br label %53
53: ; preds = %47, %52
%54 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0), %52 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0), %47 ]
%55 = call i32 @puts(i8* dereferenceable(1) %54)
%56 = call i32 @close(i32 %13)
br label %57
57: ; preds = %15, %50, %53, %25, %6
%58 = phi i32 [ -1, %6 ], [ -1, %15 ], [ -1, %25 ], [ 0, %53 ], [ 2, %50 ]
ret i32 %58
}