#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*/ errno;
int /*<<< orphan*/ execv(char const *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ print(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
void create_proc(const char *cmd, const char *arg1) {
  const char *argv[3];
  pid_t pid;
  argv[0] = cmd;
  argv[1] = arg1;
  argv[2] = NULL;
  pid = fork();
  if (pid == 0) {
    execv(cmd, (char **)argv);
    print("EXEC FAILED: %s\n", strerror(errno));
    exit(1);
  } else {
    waitpid(pid, 0, 0);
  }
}


x86 assembly (clang, -O0):
<create_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d1 <create_proc+0x71>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <execv@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe3e(%rip),%rdi
call   1030 <print@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x38(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <waitpid@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_proc>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    %rdi,(%rsp)
mov    %rsi,0x8(%rsp)
movq   $0x0,0x10(%rsp)
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1197 <create_proc+0x37>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
add    $0x20,%rsp
pop    %rbx
jmp    1040 <waitpid@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <execv@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe49(%rip),%rdi
mov    %eax,%esi
call   1030 <print@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"EXEC FAILED: %s\0A\00"
@errno = global i32 0
define void @create_proc(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8*]
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
store i8* %7, i8** %8
%9 = load i8*, i8** %4
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 1
store i8* %9, i8** %10
%11 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 2
store i8* null, i8** %11
%12 = call i64 (...) @fork()
store i64 %12, i64* %6
%13 = load i64, i64* %6
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%18 = call i32 @execv(i8* %16, i8** %17)
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @print(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i64, i64* %6
%25 = call i32 @waitpid(i64 %24, i32 0, i32 0)
br label %26
26: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"EXEC FAILED: %s\0A\00"
@errno = global i32 0
define void @create_proc(i8* %0, i8* %1) {
%3 = alloca [3 x i8*]
%4 = bitcast [3 x i8*]* %3 to i8*
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* %0, i8** %5
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* %1, i8** %6
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* null, i8** %7
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = call i32 @execv(i8* %0, i8** %5)
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @print(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i32 @waitpid(i64 %8, i32 0, i32 0)
ret void
}