#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*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  static char *cmd[] = {"ps", "ls", "date", "goof"};
  int i;
  printf("0=ps, 1=ls, 2=date 3=goof : ");
  scanf("%d", &i);
  execlp(cmd[i], cmd[i], NULL);
  printf("command not found\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
movslq -0x4(%rbp),%rcx
lea    0x2ee1(%rip),%rax
mov    (%rax,%rcx,8),%rdi
movslq -0x4(%rbp),%rcx
lea    0x2ed2(%rip),%rax
mov    (%rax,%rcx,8),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execlp@plt>
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
movslq 0x4(%rsp),%rax
lea    0x2c96(%rip),%rcx
mov    (%rcx,%rax,8),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
pop    %rax
ret

LLVM IR (-O0):
@main.cmd = internal global [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0)]
@.str = [3 x i8] c"ps\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [5 x i8] c"date\00"
@.str.3 = [5 x i8] c"goof\00"
@.str.4 = [29 x i8] c"0=ps, 1=ls, 2=date 3=goof : \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [19 x i8] c"command not found\0A\00"
define void @main() {
%1 = alloca i32
%2 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [4 x i8*], [4 x i8*]* @main.cmd, i64 0, i64 %5
%7 = load i8*, i8** %6
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [4 x i8*], [4 x i8*]* @main.cmd, i64 0, i64 %9
%11 = load i8*, i8** %10
%12 = call i32 @execlp(i8* %7, i8* %11, i32* null)
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@main.cmd = internal unnamed_addr constant [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0)]
@.str = [3 x i8] c"ps\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [5 x i8] c"date\00"
@.str.3 = [5 x i8] c"goof\00"
@.str.4 = [29 x i8] c"0=ps, 1=ls, 2=date 3=goof : \00"
@.str.5 = [3 x i8] c"%d\00"
@str = [18 x i8] c"command not found\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [4 x i8*], [4 x i8*]* @main.cmd, i64 0, i64 %6
%8 = load i8*, i8** %7
%9 = call i32 @execlp(i8* %8, i8* %8, i32* null)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
ret void
}