#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 */

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ dup2(int, int);
int execv(char *, char *const *);
int /*<<< orphan*/ exit(int);
int fork();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int start_process(char *path, char *arg) {
  char *const argv[] = {path, arg, NULL};
  int pid;
  int null_fd;
  pid = fork();
  if (pid == 0) {
    null_fd = open("/dev/null", O_WRONLY);
    chdir("/home/root/");
    dup2(null_fd, 1);
    if (execv(path, argv) == -1) {
      perror("execv");
      exit(1);
    }
  }
  return pid;
}


x86 assembly (clang, -O0):
<start_process>:
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   1090 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    120e <start_process+0x9e>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    0xe44(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x38(%rbp)
lea    0xe3f(%rip),%rdi
call   1030 <chdir@plt>
mov    -0x38(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <execv@plt>
cmp    $0xffffffff,%eax
jne    1209 <start_process+0x99>
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    120e <start_process+0x9e>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    %rdi,(%rsp)
mov    %rsi,0x8(%rsp)
movq   $0x0,0x10(%rsp)
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11db <start_process+0x6b>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r14d
lea    0xe51(%rip),%rdi
call   1030 <chdir@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1080 <execv@plt>
cmp    $0xffffffff,%eax
je     11e6 <start_process+0x76>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe29(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.1 = [12 x i8] c"/home/root/\00"
@.str.2 = [6 x i8] c"execv\00"
define i32 @start_process(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8*]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%9 = load i8*, i8** %3
store i8* %9, i8** %8
%10 = getelementptr inbounds i8*, i8** %8, i64 1
%11 = load i8*, i8** %4
store i8* %11, i8** %10
%12 = getelementptr inbounds i8*, i8** %10, i64 1
store i8* null, i8** %12
%13 = call i32 (...) @fork()
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %2
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %7
%19 = call i32 @chdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* %7
%21 = call i32 @dup2(i32 %20, i32 1)
%22 = load i8*, i8** %3
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%24 = call i32 @execv(i8* %22, i8** %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %16
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %16
br label %30
30: ; preds = %29, %2
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.1 = [12 x i8] c"/home/root/\00"
@.str.2 = [6 x i8] c"execv\00"
define i32 @start_process(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 i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %2
%11 = load i32, i32* @O_WRONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @chdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @dup2(i32 %12, i32 1)
%15 = call i32 @execv(i8* %0, i8** %5)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %10, %2
ret i32 %8
}