#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*/ execve(char *const, char *const *, char *const *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
pid_t start_process(char *const argv[]) {
  pid_t pid = fork();
  if (pid < 0) {
    fprintf(stderr, "ERROR: Cannot fork\n");
    return pid;
  }
  if (pid == 0) {
    char *const envp[] = {"HOME=/home/root", NULL};
    execve(argv[0], argv, envp);
    fprintf(stderr, "WARNING: execve() failed\n");
    exit(2);
  } else {
    return pid;
  }
}


x86 assembly (clang, -O0):
<start_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1184 <start_process+0x44>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e0 <start_process+0xa0>
cmpq   $0x0,-0x18(%rbp)
jne    11d8 <start_process+0x98>
mov    0x2c6a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c67(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <execve@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_process>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1193 <start_process+0x53>
jne    11a8 <start_process+0x68>
movaps 0x2c9e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    (%r14),%rdi
mov    %rsp,%rdx
mov    %r14,%rsi
call   1030 <execve@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"ERROR: Cannot fork\0A\00"
@.str.1 = [16 x i8] c"HOME=/home/root\00"
@__const.start_process.envp = [2 x i8*] [i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [26 x i8] c"WARNING: execve() failed\0A\00"
define i64 @start_process(i8** %0) {
%2 = alloca i64
%3 = alloca i8**
%4 = alloca i64
%5 = alloca [2 x i8*]
store i8** %0, i8*** %3
%6 = call i64 (...) @fork()
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = load i64, i64* %4
store i64 %12, i64* %2
br label %29
13: ; preds = %1
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = bitcast [2 x i8*]* %5 to i8*
%18 = load i8**, i8*** %3
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %3
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%23 = call i32 @execve(i8* %20, i8** %21, i8** %22)
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 2)
unreachable
27: ; preds = %13
%28 = load i64, i64* %4
store i64 %28, i64* %2
br label %29
29: ; preds = %27, %9
%30 = load i64, i64* %2
ret i64 %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"ERROR: Cannot fork\0A\00"
@.str.1 = [16 x i8] c"HOME=/home/root\00"
@__const.start_process.envp = [2 x i8*] [i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [26 x i8] c"WARNING: execve() failed\0A\00"
define i64 @start_process(i8** %0) {
%2 = alloca [2 x i8*]
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %18
8: ; preds = %1
%9 = icmp eq i64 %3, 0
br i1 %9, label %10, label %18
10: ; preds = %8
%11 = bitcast [2 x i8*]* %2 to i8*
%12 = load i8*, i8** %0
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%14 = call i32 @execve(i8* %12, i8** %0, i8** %13)
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %8, %5
ret i64 %3
}