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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execv(char *, char **);
int fork();
int /*<<< orphan*/ printf(char *, char *, ...);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int start_process(char **params) {
  pid_t pid = fork();
  if (pid == -1) {
    char *error = strerror(errno);
    printf("fork: %s\n", error);
    return 1;
  } else if (pid == 0) {
    execv(params[0], params);
    char *error = strerror(errno);
    printf("%s: %s\n", params[0], error);
    return 0;
  } else {
    int childStatus;
    waitpid(pid, &childStatus, 0);
    return 1;
  }
}


x86 assembly (clang, -O0):
<start_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a0 <start_process+0x50>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1206 <start_process+0xb6>
cmpl   $0x0,-0x14(%rbp)
jne    11f1 <start_process+0xa1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execv@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1206 <start_process+0xb6>
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_process>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1189 <start_process+0x39>
cmp    $0xffffffff,%eax
jne    11b8 <start_process+0x68>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe83(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c6 <start_process+0x76>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1060 <execv@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    (%rbx),%rsi
lea    0xe5e(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11cb <start_process+0x7b>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [10 x i8] c"fork: %s\0A\00"
@.str.1 = [8 x i8] c"%s: %s\0A\00"
define i32 @start_process(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %3
%8 = call i32 (...) @fork()
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %2
br label %35
16: ; preds = %1
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i8**, i8*** %3
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %3
%24 = call i32 @execv(i8* %22, i8** %23)
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
store i8* %26, i8** %6
%27 = load i8**, i8*** %3
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i8*, i8** %6
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30)
store i32 0, i32* %2
br label %35
32: ; preds = %16
%33 = load i32, i32* %4
%34 = call i32 @waitpid(i32 %33, i32* %7, i32 0)
store i32 1, i32* %2
br label %35
35: ; preds = %32, %19, %11
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [10 x i8] c"fork: %s\0A\00"
@.str.1 = [8 x i8] c"%s: %s\0A\00"
define i32 @start_process(i8** %0) {
%2 = alloca i32
%3 = tail call i32 (...) @fork()
switch i32 %3, label %15 [
i32 -1, label %4
i32 0, label %8
]
4: ; preds = %1
%5 = load i32, i32* @errno
%6 = tail call i8* @strerror(i32 %5)
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %18
8: ; preds = %1
%9 = load i8*, i8** %0
%10 = tail call i32 @execv(i8* %9, i8** %0)
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = load i8*, i8** %0
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %12)
br label %18
15: ; preds = %1
%16 = bitcast i32* %2 to i8*
%17 = call i32 @waitpid(i32 %3, i32* %2, i32 0)
br label %18
18: ; preds = %15, %8, %4
%19 = phi i32 [ 1, %4 ], [ 0, %8 ], [ 1, %15 ]
ret i32 %19
}