#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*/ *gets(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ system(char *);
int main() {
  char cmd[20];
  while (gets(cmd) != NULL) {
    if (strcmp(cmd, "exit") == 0) {
      break;
    } else if (strcmp(cmd, "cmd1") == 0) {
      system("./cmd1");
    } else if (strcmp(cmd, "cmd2") == 0) {
      system("./cmd2");
    } else if (strcmp(cmd, "cmd3") == 0) {
      system("./cmd3");
    } else {
      printf("Command not found\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <gets@plt>
cmp    $0x0,%rax
je     1222 <main+0xe2>
lea    -0x20(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1181 <main+0x41>
jmp    1222 <main+0xe2>
lea    -0x20(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ac <main+0x6c>
lea    0xe63(%rip),%rdi
call   1030 <system@plt>
jmp    1218 <main+0xd8>
lea    -0x20(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d7 <main+0x97>
lea    0xe3f(%rip),%rdi
call   1030 <system@plt>
jmp    1213 <main+0xd3>
lea    -0x20(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1202 <main+0xc2>
lea    0xe1b(%rip),%rdi
call   1030 <system@plt>
jmp    120e <main+0xce>
lea    0xe11(%rip),%rdi
call   1040 <printf@plt>
jmp    1213 <main+0xd3>
jmp    1218 <main+0xd8>
jmp    121d <main+0xdd>
jmp    114f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     1212 <main+0xd2>
lea    0xe9a(%rip),%r14
mov    %rsp,%rbx
lea    0xe97(%rip),%r15
lea    0xe8e(%rip),%r12
lea    0xe90(%rip),%r13
lea    0xe90(%rip),%rbp
jmp    11a5 <main+0x65>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     1212 <main+0xd2>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1212 <main+0xd2>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1190 <main+0x50>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0xc0>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1209 <main+0xc9>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
jmp    1198 <main+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe05(%rip),%rdi
jmp    1193 <main+0x53>
lea    0xe03(%rip),%rdi
jmp    1193 <main+0x53>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"exit\00"
@.str.1 = [5 x i8] c"cmd1\00"
@.str.2 = [7 x i8] c"./cmd1\00"
@.str.3 = [5 x i8] c"cmd2\00"
@.str.4 = [7 x i8] c"./cmd2\00"
@.str.5 = [5 x i8] c"cmd3\00"
@.str.6 = [7 x i8] c"./cmd3\00"
@.str.7 = [19 x i8] c"Command not found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
store i32 0, i32* %1
br label %3
3: ; preds = %35, %0
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = call i32* @gets(i8* %4)
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %36
7: ; preds = %3
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7
br label %36
12: ; preds = %7
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %34
18: ; preds = %12
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %33
24: ; preds = %18
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %32
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
br label %33
33: ; preds = %32, %22
br label %34
34: ; preds = %33, %16
br label %35
35: ; preds = %34
br label %3
36: ; preds = %11, %3
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"exit\00"
@.str.1 = [5 x i8] c"cmd1\00"
@.str.2 = [7 x i8] c"./cmd1\00"
@.str.3 = [5 x i8] c"cmd2\00"
@.str.4 = [7 x i8] c"./cmd2\00"
@.str.5 = [5 x i8] c"cmd3\00"
@.str.6 = [7 x i8] c"./cmd3\00"
@str = [18 x i8] c"Command not found\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = call i32* @gets(i8* %2)
%4 = icmp eq i32* %3, null
br i1 %4, label %28, label %5
5: ; preds = %0, %25
%6 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %5
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %25
13: ; preds = %8
%14 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %25
18: ; preds = %13
%19 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %25
23: ; preds = %18
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %11, %21, %23, %16
%26 = call i32* @gets(i8* %2)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %5
28: ; preds = %25, %5, %0
ret i32 0
}