#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 checkCommandExists(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileNotFound();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ formatWriteString(char *, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ getFilePath(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ promptUserValue(char *, char *, int);
void learnCommand() {
  char directory[100];
  getFilePath(directory, false);
  FILE *commandFile;
  commandFile = fopen(directory, "a+");
  if (commandFile == NULL) {
    fileNotFound();
  }
  char command[100];
  promptUserValue(command, "What command would you like me to learn?", true);
  if (checkCommandExists(command) == true) {
    printf("That command already exists\n");
    exit(1);
  } else {
    char action[100];
    promptUserValue(action,
                    "What's the terminal command that you want it to execute?",
                    false);
    char writeString[100];
    formatWriteString(writeString, command, action);
    fprintf(commandFile, "%s", writeString);
    fclose(commandFile);
    printf("Learned command\n");
  }
}


x86 assembly (clang, -O0):
<learnCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
call   1030 <getFilePath@plt>
lea    -0x70(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11dc <learnCommand+0x3c>
mov    $0x0,%al
call   10b0 <fileNotFound@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe19(%rip),%rsi
mov    $0x1,%edx
call   1070 <promptUserValue@plt>
lea    -0xe0(%rbp),%rdi
call   10c0 <checkCommandExists@plt>
cmp    $0x1,%eax
jne    121f <learnCommand+0x7f>
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x150(%rbp),%rdi
lea    0xe1c(%rip),%rsi
xor    %edx,%edx
call   1070 <promptUserValue@plt>
lea    -0x1c0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
lea    -0x150(%rbp),%rdx
call   1090 <formatWriteString@plt>
mov    -0x78(%rbp),%rdi
lea    -0x1c0(%rbp),%rdx
lea    0xe22(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x78(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<learnCommand>:
push   %r15
push   %r14
push   %rbx
sub    $0x1c0,%rsp
lea    0x150(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <getFilePath@plt>
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11dc <learnCommand+0x3c>
xor    %eax,%eax
call   10b0 <fileNotFound@plt>
lea    0xe20(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%edx
call   1070 <promptUserValue@plt>
mov    %r14,%rdi
call   10c0 <checkCommandExists@plt>
cmp    $0x1,%eax
je     1258 <learnCommand+0xb8>
lea    0xe25(%rip),%rsi
lea    0xe0(%rsp),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1070 <promptUserValue@plt>
lea    0x70(%rsp),%r15
mov    %rsp,%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1090 <formatWriteString@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe1f(%rip),%rdi
call   1040 <puts@plt>
add    $0x1c0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"a+\00"
@.str.1 = [41 x i8] c"What command would you like me to learn?\00"
@.str.2 = [29 x i8] c"That command already exists\0A\00"
@.str.3 = [57 x i8] c"What's the terminal command that you want it to execute?\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [17 x i8] c"Learned command\0A\00"
define void @learnCommand() {
%1 = alloca [100 x i8]
%2 = alloca i32*
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%7 = call i32 @getFilePath(i8* %6, i32 0)
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (...) @fileNotFound()
br label %14
14: ; preds = %12, %0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = call i32 @promptUserValue(i8* %15, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 1)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = call i32 @checkCommandExists(i8* %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%25 = call i32 @promptUserValue(i8* %24, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 0)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%29 = call i32 @formatWriteString(i8* %26, i8* %27, i8* %28)
%30 = load i32*, i32** %2
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%32 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = load i32*, i32** %2
%34 = call i32 @fclose(i32* %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"a+\00"
@.str.1 = [41 x i8] c"What command would you like me to learn?\00"
@.str.3 = [57 x i8] c"What's the terminal command that you want it to execute?\00"
@str = [16 x i8] c"Learned command\00"
@str.6 = [28 x i8] c"That command already exists\00"
define void @learnCommand() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = call i32 @getFilePath(i8* %5, i32 0)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (...) @fileNotFound()
br label %11
11: ; preds = %9, %0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = call i32 @promptUserValue(i8* %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 1)
%14 = call i32 @checkCommandExists(i8* %12)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.6, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%21 = call i32 @promptUserValue(i8* %20, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 0)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%23 = call i32 @formatWriteString(i8* %22, i8* %12, i8* %20)
%24 = call i32 @fputs(i8* %22, i32* %7)
%25 = call i32 @fclose(i32* %7)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
ret void
}