#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 execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ list_dir(int, char **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
void execute(int n_args, char *args[]) {
  if (!strcmp(*args, "ls")) {
    list_dir(n_args, args);
  } else {
    if (execvp(*args, args) == -1) {
      fprintf(stderr, "-feshell: %s: ", *args);
      perror("");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe83(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    119c <execute+0x3c>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <list_dir@plt>
jmp    11ec <execute+0x8c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
jne    11e7 <execute+0x87>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe39(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11ec <execute+0x8c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    (%rsi),%rbx
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1194 <execute+0x34>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <execvp@plt>
cmp    $0xffffffff,%eax
je     11a2 <execute+0x42>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <list_dir@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe4e(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe50(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"-feshell: %s: \00"
@.str.2 = [1 x i8] zeroinitializer
define void @execute(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
store i32 %0, i32* %3
store i8** %1, i8*** %4
%5 = load i8**, i8*** %4
%6 = load i8*, i8** %5
%7 = call i32 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* %3
%11 = load i8**, i8*** %4
%12 = call i32 @list_dir(i32 %10, i8** %11)
br label %27
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %4
%17 = call i32 @execvp(i8* %15, i8** %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %4
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %13
br label %27
27: ; preds = %26, %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"-feshell: %s: \00"
@.str.2 = [1 x i8] zeroinitializer
define void @execute(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %3, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @list_dir(i32 %0, i8** %1)
br label %17
8: ; preds = %2
%9 = tail call i32 @execvp(i8* %3, i8** %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8, %6
ret void
}