#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*/ EXIT_SUCCESS;
char *bestmatch(char *, char **, int);
int /*<<< orphan*/ exitapp(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *);
char **readconfigfile(char *, int *);
int /*<<< orphan*/ setinterupthandlers();
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  setinterupthandlers();
  char *argone = argv[1];
  FILE *outfile = stdout;
  int showversion = 0;
  int showhelp = 0;
  if (argone[0] == '-') {
    if (argone[1] == 'v') {
      showversion = 1;
    } else if ((argone[1] == 'h') || (argone[1] == '?')) {
      showhelp = 1;
    }
  }
  if (showversion == 1) {
    printf("spell"
           " "
           "0.1"
           "\n");
    printf("Copyright 2017, Christopher Stoll"
           "\n");
    printf("https://github.com/stollcri/spell"
           "\n");
    exitapp(EXIT_SUCCESS);
  }
  if (showhelp == 1) {
    printf("spell [-h][-v] word"
           "\n");
    exitapp(EXIT_SUCCESS);
  }
  int possibilitycount = 0;
  char **possibilities = NULL;
  if (getenv("SPELL_FILE")) {
    possibilities = readconfigfile(getenv("SPELL_FILE"), &possibilitycount);
  } else {
    possibilities = readconfigfile(".spell", &possibilitycount);
  }
  char *recomendedstring = NULL;
  recomendedstring = bestmatch(argone, possibilities, possibilitycount);
  fputs(recomendedstring, outfile);
  fputs("\n", outfile);
  fclose(outfile);
  exitapp(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <setinterupthandlers@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1225 <main+0xa5>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x76,%eax
jne    11f2 <main+0x72>
movl   $0x1,-0x24(%rbp)
jmp    1220 <main+0xa0>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x68,%eax
je     1214 <main+0x94>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3f,%eax
jne    121b <main+0x9b>
movl   $0x1,-0x28(%rbp)
jmp    1220 <main+0xa0>
jmp    1225 <main+0xa5>
cmpl   $0x1,-0x24(%rbp)
jne    1261 <main+0xe1>
lea    0xdca(%rip),%rdi
call   1080 <printf@plt>
lea    0xdc9(%rip),%rdi
call   1080 <printf@plt>
lea    0xde0(%rip),%rdi
call   1080 <printf@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exitapp@plt>
cmpl   $0x1,-0x28(%rbp)
jne    1285 <main+0x105>
lea    0xddf(%rip),%rdi
call   1080 <printf@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exitapp@plt>
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xdcb(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     12cb <main+0x14b>
lea    0xdb5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <readconfigfile@plt>
mov    %rax,-0x38(%rbp)
jmp    12df <main+0x15f>
lea    0xd9f(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <readconfigfile@plt>
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1060 <bestmatch@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xcf6(%rip),%rdi
call   1090 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1070 <fclose@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exitapp@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
call   1060 <setinterupthandlers@plt>
mov    0x8(%rbx),%rbx
mov    0x2e37(%rip),%rax
mov    (%rax),%r14
cmpb   $0x2d,(%rbx)
jne    11f9 <main+0x69>
mov    0x1(%rbx),%al
lea    0xe57(%rip),%rdi
cmp    $0x3f,%al
je     11e6 <main+0x56>
cmp    $0x68,%al
je     11e6 <main+0x56>
cmp    $0x76,%al
jne    11f9 <main+0x69>
lea    0xe58(%rip),%rdi
call   1050 <puts@plt>
lea    0xe56(%rip),%rdi
call   1050 <puts@plt>
lea    0xe6c(%rip),%rdi
call   1050 <puts@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   10b0 <exitapp@plt>
movl   $0x0,0x4(%rsp)
lea    0xdf8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     121c <main+0x8c>
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
jmp    1228 <main+0x98>
lea    0xde8(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <readconfigfile@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <bestmatch@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1090 <fputs@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   10a0 <fputc@plt>
mov    %r14,%rdi
call   1080 <fclose@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   10b0 <exitapp@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32* null
@.str = [11 x i8] c"spell 0.1\0A\00"
@.str.1 = [35 x i8] c"Copyright 2017, Christopher Stoll\0A\00"
@.str.2 = [35 x i8] c"https://github.com/stollcri/spell\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.3 = [21 x i8] c"spell [-h][-v] word\0A\00"
@.str.4 = [11 x i8] c"SPELL_FILE\00"
@.str.5 = [7 x i8] c".spell\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (...) @setinterupthandlers()
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i32*, i32** @stdout
store i32* %17, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
%18 = load i8*, i8** %6
%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 %45
23: ; preds = %2
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 118
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %8
br label %44
30: ; preds = %23
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 104
br i1 %35, label %42, label %36
36: ; preds = %30
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 63
br i1 %41, label %42, label %43
42: ; preds = %36, %30
store i32 1, i32* %9
br label %43
43: ; preds = %42, %36
br label %44
44: ; preds = %43, %29
br label %45
45: ; preds = %44, %2
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%50 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%52 = load i32, i32* @EXIT_SUCCESS
%53 = call i32 @exitapp(i32 %52)
br label %54
54: ; preds = %48, %45
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %61
57: ; preds = %54
%58 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* @EXIT_SUCCESS
%60 = call i32 @exitapp(i32 %59)
br label %61
61: ; preds = %57, %54
store i32 0, i32* %10
store i8** null, i8*** %11
%62 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%66 = call i8** @readconfigfile(i8* %65, i32* %10)
store i8** %66, i8*** %11
br label %69
67: ; preds = %61
%68 = call i8** @readconfigfile(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %10)
store i8** %68, i8*** %11
br label %69
69: ; preds = %67, %64
store i8* null, i8** %12
%70 = load i8*, i8** %6
%71 = load i8**, i8*** %11
%72 = load i32, i32* %10
%73 = call i8* @bestmatch(i8* %70, i8** %71, i32 %72)
store i8* %73, i8** %12
%74 = load i8*, i8** %12
%75 = load i32*, i32** %7
%76 = call i32 @fputs(i8* %74, i32* %75)
%77 = load i32*, i32** %7
%78 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32* %77)
%79 = load i32*, i32** %7
%80 = call i32 @fclose(i32* %79)
%81 = load i32, i32* @EXIT_SUCCESS
%82 = call i32 @exitapp(i32 %81)
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@stdout = global i32* null
@EXIT_SUCCESS = global i32 0
@.str.4 = [11 x i8] c"SPELL_FILE\00"
@.str.5 = [7 x i8] c".spell\00"
@str = [20 x i8] c"spell [-h][-v] word\00"
@str.7 = [10 x i8] c"spell 0.1\00"
@str.8 = [34 x i8] c"Copyright 2017, Christopher Stoll\00"
@str.9 = [34 x i8] c"https://github.com/stollcri/spell\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = tail call i32 (...) @setinterupthandlers()
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32*, i32** @stdout
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 45
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = load i8, i8* %11
switch i8 %12, label %21 [
i8 118, label %13
i8 104, label %16
i8 63, label %16
]
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.7, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.8, i64 0, i64 0))
br label %16
16: ; preds = %10, %10, %13
%17 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.9, i64 0, i64 0), %13 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %10 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %10 ]
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
%19 = load i32, i32* @EXIT_SUCCESS
%20 = tail call i32 @exitapp(i32 %19)
br label %21
21: ; preds = %16, %10, %2
%22 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%23 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i8** @readconfigfile(i8* %23, i32* %3)
br label %29
27: ; preds = %21
%28 = call i8** @readconfigfile(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %3)
br label %29
29: ; preds = %27, %25
%30 = phi i8** [ %26, %25 ], [ %28, %27 ]
%31 = load i32, i32* %3
%32 = call i8* @bestmatch(i8* %6, i8** %30, i32 %31)
%33 = call i32 @fputs(i8* %32, i32* %7)
%34 = call i32 @fputc(i32 10, i32* %7)
%35 = call i32 @fclose(i32* %7)
%36 = load i32, i32* @EXIT_SUCCESS
%37 = call i32 @exitapp(i32 %36)
ret i32 0
}