#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*/ addToHistory(char *);
int /*<<< orphan*/ cdCommand(char *);
int /*<<< orphan*/ clearCommand();
int /*<<< orphan*/ exitCommand();
int /*<<< orphan*/ historyCommand();
int notImplementedCommand(char *);
int /*<<< orphan*/ parseShellCommandLine(char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
char *strtok_r(char *, char *, char **);
void parseLine(char *buffer) {
  addToHistory(buffer);
  char *separator = " ";
  char *token, *saveptr;
  token = strtok_r(buffer, separator, &saveptr);
  if (token == NULL) {
  } else if (strcmp(token, "cd") == 0) {
    token = strtok_r(NULL, separator, &saveptr);
    cdCommand(token);
  } else if (strcmp(token, "history") == 0) {
    historyCommand();
  } else if (strcmp(token, "clear") == 0) {
    clearCommand();
  } else if (strcmp(token, "exit") == 0) {
    exitCommand();
  } else if (notImplementedCommand(token) == 1) {
    printf("%s : not implemented\n", token);
  } else {
    parseShellCommandLine(token, saveptr, separator);
  }
}


x86 assembly (clang, -O0):
<parseLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <addToHistory@plt>
lea    0xe44(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e5 <parseLine+0x45>
jmp    12e5 <parseLine+0x145>
mov    -0x18(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1222 <parseLine+0x82>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <cdCommand@plt>
jmp    12e0 <parseLine+0x140>
mov    -0x18(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1248 <parseLine+0xa8>
mov    $0x0,%al
call   1060 <historyCommand@plt>
jmp    12db <parseLine+0x13b>
mov    -0x18(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    126e <parseLine+0xce>
mov    $0x0,%al
call   10b0 <clearCommand@plt>
jmp    12d6 <parseLine+0x136>
mov    -0x18(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1294 <parseLine+0xf4>
mov    $0x0,%al
call   10c0 <exitCommand@plt>
jmp    12d1 <parseLine+0x131>
mov    -0x18(%rbp),%rdi
call   1040 <notImplementedCommand@plt>
cmp    $0x1,%eax
jne    12bb <parseLine+0x11b>
mov    -0x18(%rbp),%rsi
lea    0xd67(%rip),%rdi
call   1050 <printf@plt>
jmp    12cc <parseLine+0x12c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1090 <parseShellCommandLine@plt>
jmp    12d1 <parseLine+0x131>
jmp    12d6 <parseLine+0x136>
jmp    12db <parseLine+0x13b>
jmp    12e0 <parseLine+0x140>
jmp    12e5 <parseLine+0x145>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseLine>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <addToHistory@plt>
lea    0xe4c(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <strtok_r@plt>
test   %rax,%rax
je     1287 <parseLine+0xe7>
mov    %rax,%rbx
lea    0xe2e(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     123b <parseLine+0x9b>
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1258 <parseLine+0xb8>
lea    0xe11(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1261 <parseLine+0xc1>
lea    0xe03(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     126a <parseLine+0xca>
mov    %rbx,%rdi
call   1040 <notImplementedCommand@plt>
cmp    $0x1,%eax
jne    1273 <parseLine+0xd3>
lea    0xde7(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    1287 <parseLine+0xe7>
lea    0xdbe(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1070 <strtok_r@plt>
mov    %rax,%rdi
call   10a0 <cdCommand@plt>
jmp    1287 <parseLine+0xe7>
xor    %eax,%eax
call   1060 <historyCommand@plt>
jmp    1287 <parseLine+0xe7>
xor    %eax,%eax
call   10b0 <clearCommand@plt>
jmp    1287 <parseLine+0xe7>
xor    %eax,%eax
call   10c0 <exitCommand@plt>
jmp    1287 <parseLine+0xe7>
mov    0x8(%rsp),%rsi
lea    0xd81(%rip),%rdx
mov    %rbx,%rdi
call   1090 <parseShellCommandLine@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [8 x i8] c"history\00"
@.str.3 = [6 x i8] c"clear\00"
@.str.4 = [5 x i8] c"exit\00"
@.str.5 = [22 x i8] c"%s : not implemented\0A\00"
define void @parseLine(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @addToHistory(i8* %6)
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
%8 = load i8*, i8** %2
%9 = load i8*, i8** %3
%10 = call i8* @strtok_r(i8* %8, i8* %9, i8** %5)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
br label %58
14: ; preds = %1
%15 = load i8*, i8** %4
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = call i8* @strtok_r(i8* null, i8* %19, i8** %5)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @cdCommand(i8* %21)
br label %57
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (...) @historyCommand()
br label %56
29: ; preds = %23
%30 = load i8*, i8** %4
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 (...) @clearCommand()
br label %55
35: ; preds = %29
%36 = load i8*, i8** %4
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (...) @exitCommand()
br label %54
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = call i32 @notImplementedCommand(i8* %42)
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i8*, i8** %4
%47 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %46)
br label %53
48: ; preds = %41
%49 = load i8*, i8** %4
%50 = load i8*, i8** %5
%51 = load i8*, i8** %3
%52 = call i32 @parseShellCommandLine(i8* %49, i8* %50, i8* %51)
br label %53
53: ; preds = %48, %45
br label %54
54: ; preds = %53, %39
br label %55
55: ; preds = %54, %33
br label %56
56: ; preds = %55, %27
br label %57
57: ; preds = %56, %18
br label %58
58: ; preds = %57, %13
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [8 x i8] c"history\00"
@.str.3 = [6 x i8] c"clear\00"
@.str.4 = [5 x i8] c"exit\00"
@.str.5 = [22 x i8] c"%s : not implemented\0A\00"
define void @parseLine(i8* %0) {
%2 = alloca i8*
%3 = tail call i32 @addToHistory(i8* %0)
%4 = bitcast i8** %2 to i8*
%5 = call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %36, label %7
7: ; preds = %1
%8 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%12 = call i32 @cdCommand(i8* %11)
br label %36
13: ; preds = %7
%14 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (...) @historyCommand()
br label %36
18: ; preds = %13
%19 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (...) @clearCommand()
br label %36
23: ; preds = %18
%24 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (...) @exitCommand()
br label %36
28: ; preds = %23
%29 = call i32 @notImplementedCommand(i8* %5)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %36
33: ; preds = %28
%34 = load i8*, i8** %2
%35 = call i32 @parseShellCommandLine(i8* %5, i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %10, %21, %31, %33, %26, %16, %1
ret void
}