#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 */
struct cmd {
  int dummy;
};

/* Variables and functions */
int EINVAL;
int execute_cmd(struct cmd *, int, char **);
struct cmd *find_cmd(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int run_cmd(int argc, char *argv[]) {
  struct cmd *p_cmd = find_cmd(argv[0]);
  if (!p_cmd) {
    fprintf(stderr, "Command \"%s\" was not found", argv[0]);
    return -EINVAL;
  }
  return execute_cmd(p_cmd, argc, argv);
}


x86 assembly (clang, -O0):
<run_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <find_cmd@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <run_cmd+0x59>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe8f(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    0x2e59(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <run_cmd+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1050 <execute_cmd@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_cmd>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rdi
call   1040 <find_cmd@plt>
test   %rax,%rax
je     1158 <run_cmd+0x28>
mov    %rax,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <execute_cmd@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe95(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e61(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.cmd = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"Command \22%s\22 was not found\00"
@EINVAL = global i32 0
define i32 @run_cmd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.cmd*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = call %struct.cmd* @find_cmd(i8* %9)
store %struct.cmd* %10, %struct.cmd** %6
%11 = load %struct.cmd*, %struct.cmd** %6
%12 = icmp ne %struct.cmd* %11, null
br i1 %12, label %21, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EINVAL
%20 = sub nsw i32 0, %19
store i32 %20, i32* %3
br label %26
21: ; preds = %2
%22 = load %struct.cmd*, %struct.cmd** %6
%23 = load i32, i32* %4
%24 = load i8**, i8*** %5
%25 = call i32 @execute_cmd(%struct.cmd* %22, i32 %23, i8** %24)
store i32 %25, i32* %3
br label %26
26: ; preds = %21, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.cmd = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"Command \22%s\22 was not found\00"
@EINVAL = global i32 0
define i32 @run_cmd(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call %struct.cmd* @find_cmd(i8* %3)
%5 = icmp eq %struct.cmd* %4, null
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EINVAL
%11 = sub nsw i32 0, %10
br label %14
12: ; preds = %2
%13 = tail call i32 @execute_cmd(%struct.cmd* %4, i32 %0, i8** %1)
br label %14
14: ; preds = %12, %6
%15 = phi i32 [ %13, %12 ], [ %11, %6 ]
ret i32 %15
}