#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
void execute_command(char **arguments) {
  pid_t pid;
  char *command;
  pid = fork();
  if (pid < 0) {
    perror("Unable to fork");
    exit(EXIT_FAILURE);
  }
  if (pid == 0) {
    if (arguments[0] == NULL || strlen(arguments[0]) == 0) {
      exit(EXIT_FAILURE);
    }
    command = arguments[0];
    if (strrchr(arguments[0], '/') != NULL) {
      arguments[0] = strrchr(arguments[0], '/') + 1;
    }
    execvp(command, arguments);
    perror(command);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<execute_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    119c <execute_command+0x3c>
lea    0xe77(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1242 <execute_command+0xe2>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11cb <execute_command+0x6b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    11d9 <execute_command+0x79>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
cmp    $0x0,%rax
je     121e <execute_command+0xbe>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rcx
add    $0x1,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <execvp@plt>
mov    -0x18(%rbp),%rdi
call   1050 <perror@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_command>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     116d <execute_command+0x1d>
je     117b <execute_command+0x2b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe8c(%rip),%rdi
call   1040 <perror@plt>
jmp    1189 <execute_command+0x39>
mov    (%rbx),%r14
test   %r14,%r14
je     1189 <execute_command+0x39>
cmpb   $0x0,(%r14)
jne    1197 <execute_command+0x47>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     11b0 <execute_command+0x60>
add    $0x1,%rax
mov    %rax,(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
mov    %r14,%rdi
jmp    1174 <execute_command+0x24>

LLVM IR (-O0):
@.str = [15 x i8] c"Unable to fork\00"
@EXIT_FAILURE = global i32 0
define void @execute_command(i8** %0) {
%2 = alloca i8**
%3 = alloca i64
%4 = alloca i8*
store i8** %0, i8*** %2
%5 = call i64 (...) @fork()
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = load i64, i64* %3
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %54
15: ; preds = %12
%16 = load i8**, i8*** %2
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %26, label %20
20: ; preds = %15
%21 = load i8**, i8*** %2
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i64 @strlen(i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20, %15
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %20
%30 = load i8**, i8*** %2
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
store i8* %32, i8** %4
%33 = load i8**, i8*** %2
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i8* @strrchr(i8* %35, i8 signext 47)
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %46
38: ; preds = %29
%39 = load i8**, i8*** %2
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i8* @strrchr(i8* %41, i8 signext 47)
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8**, i8*** %2
%45 = getelementptr inbounds i8*, i8** %44, i64 0
store i8* %43, i8** %45
br label %46
46: ; preds = %38, %29
%47 = load i8*, i8** %4
%48 = load i8**, i8*** %2
%49 = call i32 @execvp(i8* %47, i8** %48)
%50 = load i8*, i8** %4
%51 = call i32 @perror(i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"Unable to fork\00"
@EXIT_FAILURE = global i32 0
define void @execute_command(i8** %0) {
%2 = tail call i64 (...) @fork()
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = icmp eq i64 %2, 0
br i1 %9, label %10, label %29
10: ; preds = %8
%11 = load i8*, i8** %0
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i8, i8* %11
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13, %10
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %13
%20 = tail call i8* @strrchr(i8* %11, i8 signext 47)
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %23, i8** %0
br label %24
24: ; preds = %22, %19
%25 = tail call i32 @execvp(i8* %11, i8** %0)
%26 = tail call i32 @perror(i8* %11)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %8
ret void
}