#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 */
scalar_t__ file_exists(char const *);
int /*<<< orphan*/ print_word_stats(char const *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int i = 0;
  for (; i < argc; i++) {
    char const *option = argv[i];
    if (option[0] == '-') {
      switch (option[1]) {
      case 'h':
        printf("This program finds all the unique words a file (whose path is "
               "passed as an argument), prints them in lexicographical order "
               "along with the total number of times each word appears "
               "(case-insensitive) and a count of different case-sensitive "
               "versions of the word. \n\nUse the following interface: "
               "\n\nwordstat <argument>\n\nwhere <argument> is either the name "
               "of the file that wordstat should process, or -h, which prints "
               "this menu. \n\n");
        return 0;
        break;
      default:
        printf("flag not recognized %s", option);
        return 1;
        break;
      }
    } else if (i == 1) {
      if (file_exists(option)) {
        print_word_stats(option);
      } else {
        printf("This file, %s, does not exist.\n", option);
        return 1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122b <main+0xfb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11c5 <main+0x95>
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%al
sub    $0x68,%al
jne    11a7 <main+0x77>
jmp    118d <main+0x5d>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1232 <main+0x102>
mov    -0x20(%rbp),%rsi
lea    0xff7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1232 <main+0x102>
cmpl   $0x1,-0x14(%rbp)
jne    1213 <main+0xe3>
mov    -0x20(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%rax
je     11f0 <main+0xc0>
mov    -0x20(%rbp),%rdi
call   1050 <print_word_stats@plt>
jmp    120e <main+0xde>
mov    -0x20(%rbp),%rsi
lea    0xfc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1232 <main+0x102>
jmp    1213 <main+0xe3>
jmp    1218 <main+0xe8>
jmp    121d <main+0xed>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <main+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11a5 <main+0x65>
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebx,%ebx
jmp    1169 <main+0x29>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     11a5 <main+0x65>
mov    (%r14,%rbx,8),%r12
cmpb   $0x2d,(%r12)
je     1191 <main+0x51>
cmp    $0x1,%rbx
jne    1160 <main+0x20>
mov    %r12,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
je     11b2 <main+0x72>
mov    %r12,%rdi
call   1060 <print_word_stats@plt>
jmp    1160 <main+0x20>
cmpb   $0x68,0x1(%r12)
jne    11a9 <main+0x69>
lea    0xe97(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    11c8 <main+0x88>
lea    0xe50(%rip),%rdi
jmp    11b9 <main+0x79>
lea    0xe5e(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [425 x i8] c"This program finds all the unique words a file (whose path is passed as an argument), prints them in lexicographical order along with the total number of times each word appears (case-insensitive) and a count of different case-sensitive versions of the word. \0A\0AUse the following interface: \0A\0Awordstat <argument>\0A\0Awhere <argument> is either the name of the file that wordstat should process, or -h, which prints this menu. \0A\0A\00"
@.str.1 = [23 x i8] c"flag not recognized %s\00"
@.str.2 = [32 x i8] c"This file, %s, does not exist.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %8
8: ; preds = %49, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %52
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 45
br i1 %22, label %23, label %33
23: ; preds = %12
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %30 [
i32 104, label %28
]
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([425 x i8], [425 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %53
30: ; preds = %23
%31 = load i8*, i8** %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %31)
store i32 1, i32* %3
br label %53
33: ; preds = %12
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %47
36: ; preds = %33
%37 = load i8*, i8** %7
%38 = call i64 @file_exists(i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i8*, i8** %7
%42 = call i32 @print_word_stats(i8* %41)
br label %46
43: ; preds = %36
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %44)
store i32 1, i32* %3
br label %53
46: ; preds = %40
br label %47
47: ; preds = %46, %33
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %8
52: ; preds = %8
store i32 0, i32* %3
br label %53
53: ; preds = %52, %43, %30, %28
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"flag not recognized %s\00"
@.str.2 = [32 x i8] c"This file, %s, does not exist.\0A\00"
@str = [424 x i8] c"This program finds all the unique words a file (whose path is passed as an argument), prints them in lexicographical order along with the total number of times each word appears (case-insensitive) and a count of different case-sensitive versions of the word. \0A\0AUse the following interface: \0A\0Awordstat <argument>\0A\0Awhere <argument> is either the name of the file that wordstat should process, or -h, which prints this menu. \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %32
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %29
%7 = phi i64 [ 0, %4 ], [ %30, %29 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 45
br i1 %11, label %12, label %20
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 104
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([424 x i8], [424 x i8]* @str, i64 0, i64 0))
br label %32
18: ; preds = %12
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %32
20: ; preds = %6
%21 = icmp eq i64 %7, 1
br i1 %21, label %22, label %29
22: ; preds = %20
%23 = tail call i64 @file_exists(i8* %9)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @print_word_stats(i8* %9)
br label %29
27: ; preds = %22
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %32
29: ; preds = %20, %25
%30 = add nuw nsw i64 %7, 1
%31 = icmp eq i64 %30, %5
br i1 %31, label %32, label %6
32: ; preds = %29, %2, %27, %18, %16
%33 = phi i32 [ 1, %27 ], [ 1, %18 ], [ 0, %16 ], [ 0, %2 ], [ 0, %29 ]
ret i32 %33
}