#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 /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ execvp(char *, char **);
int getrawlist(char const *, int /*<<< orphan*/, char **, int,
               int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ prepare_child(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ strlen(char const *);
int vfork();
int start_command(const char *cmd, sigset_t *mask, int infd, int outfd,
                  const char *a0, const char *a1, const char *a2) {
  int pid;
  if ((pid = vfork()) < 0) {
    perror("fork");
    return -1;
  }
  if (pid == 0) {
    char *argv[100];
    int i = getrawlist(cmd, strlen(cmd), argv, sizeof argv / sizeof *argv, 0);
    if ((argv[i++] = (char *)a0) != NULL && (argv[i++] = (char *)a1) != NULL &&
        (argv[i++] = (char *)a2) != NULL)
      argv[i] = NULL;
    prepare_child(mask, infd, outfd);
    execvp(argv[0], argv);
    perror(argv[0]);
    _exit(1);
  }
  return pid;
}


x86 assembly (clang, -O0):
<start_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x370,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
call   1080 <vfork@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11be <start_command+0x4e>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <start_command+0x15e>
cmpl   $0x0,-0x34(%rbp)
jne    12c8 <start_command+0x158>
mov    -0x10(%rbp),%rax
mov    %rax,-0x370(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x370(%rbp),%rdi
mov    %eax,%esi
lea    -0x360(%rbp),%rdx
mov    $0x64,%ecx
xor    %r8d,%r8d
call   1030 <getrawlist@plt>
mov    %eax,-0x364(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x364(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x364(%rbp)
movslq %ecx,%rcx
mov    %rax,-0x360(%rbp,%rcx,8)
ff
cmp    $0x0,%rax
je     1290 <start_command+0x120>
mov    -0x30(%rbp),%rax
mov    -0x364(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x364(%rbp)
movslq %ecx,%rcx
mov    %rax,-0x360(%rbp,%rcx,8)
ff
cmp    $0x0,%rax
je     1290 <start_command+0x120>
mov    0x10(%rbp),%rax
mov    -0x364(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x364(%rbp)
movslq %ecx,%rcx
mov    %rax,-0x360(%rbp,%rcx,8)
ff
cmp    $0x0,%rax
je     1290 <start_command+0x120>
movslq -0x364(%rbp),%rax
movq   $0x0,-0x360(%rbp,%rax,8)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1060 <prepare_child@plt>
mov    -0x360(%rbp),%rdi
lea    -0x360(%rbp),%rsi
call   1090 <execvp@plt>
mov    -0x360(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x370,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x328,%rsp
mov    %r9,%r13
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbp
call   1080 <vfork@plt>
test   %eax,%eax
js     11b0 <start_command+0x40>
je     11c3 <start_command+0x53>
add    $0x328,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
jmp    119e <start_command+0x2e>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rsp,%rdx
mov    $0x64,%ecx
xor    %r8d,%r8d
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <getrawlist@plt>
cltq
mov    %rbx,(%rsp,%rax,8)
test   %rbx,%rbx
je     1210 <start_command+0xa0>
mov    %r13,0x8(%rsp,%rax,8)
test   %r13,%r13
je     1210 <start_command+0xa0>
mov    0x360(%rsp),%rcx
mov    %rcx,0x10(%rsp,%rax,8)
test   %rcx,%rcx
je     1210 <start_command+0xa0>
movq   $0x0,0x18(%rsp,%rax,8)
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1060 <prepare_child@plt>
mov    (%rsp),%rdi
mov    %rsp,%rsi
call   1090 <execvp@plt>
mov    (%rsp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
define i32 @start_command(i8* %0, i32* %1, i32 %2, i32 %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca [100 x i8*]
%18 = alloca i32
store i8* %0, i8** %9
store i32* %1, i32** %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i8* %6, i8** %15
%19 = call i32 @vfork()
store i32 %19, i32* %16
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %7
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %8
br label %71
23: ; preds = %7
%24 = load i32, i32* %16
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %69
26: ; preds = %23
%27 = load i8*, i8** %9
%28 = load i8*, i8** %9
%29 = call i32 @strlen(i8* %28)
%30 = getelementptr inbounds [100 x i8*], [100 x i8*]* %17, i64 0, i64 0
%31 = call i32 @getrawlist(i8* %27, i32 %29, i8** %30, i32 100, i32 0)
store i32 %31, i32* %18
%32 = load i8*, i8** %13
%33 = load i32, i32* %18
%34 = add nsw i32 %33, 1
store i32 %34, i32* %18
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds [100 x i8*], [100 x i8*]* %17, i64 0, i64 %35
store i8* %32, i8** %36
%37 = icmp ne i8* %32, null
br i1 %37, label %38, label %56
38: ; preds = %26
%39 = load i8*, i8** %14
%40 = load i32, i32* %18
%41 = add nsw i32 %40, 1
store i32 %41, i32* %18
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds [100 x i8*], [100 x i8*]* %17, i64 0, i64 %42
store i8* %39, i8** %43
%44 = icmp ne i8* %39, null
br i1 %44, label %45, label %56
45: ; preds = %38
%46 = load i8*, i8** %15
%47 = load i32, i32* %18
%48 = add nsw i32 %47, 1
store i32 %48, i32* %18
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds [100 x i8*], [100 x i8*]* %17, i64 0, i64 %49
store i8* %46, i8** %50
%51 = icmp ne i8* %46, null
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = load i32, i32* %18
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [100 x i8*], [100 x i8*]* %17, i64 0, i64 %54
store i8* null, i8** %55
br label %56
56: ; preds = %52, %45, %38, %26
%57 = load i32*, i32** %10
%58 = load i32, i32* %11
%59 = load i32, i32* %12
%60 = call i32 @prepare_child(i32* %57, i32 %58, i32 %59)
%61 = getelementptr inbounds [100 x i8*], [100 x i8*]* %17, i64 0, i64 0
%62 = load i8*, i8** %61
%63 = getelementptr inbounds [100 x i8*], [100 x i8*]* %17, i64 0, i64 0
%64 = call i32 @execvp(i8* %62, i8** %63)
%65 = getelementptr inbounds [100 x i8*], [100 x i8*]* %17, i64 0, i64 0
%66 = load i8*, i8** %65
%67 = call i32 @perror(i8* %66)
%68 = call i32 @_exit(i32 1)
unreachable
69: ; preds = %23
%70 = load i32, i32* %16
store i32 %70, i32* %8
br label %71
71: ; preds = %69, %21
%72 = load i32, i32* %8
ret i32 %72
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
define i32 @start_command(i8* %0, i32* %1, i32 %2, i32 %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca [100 x i8*]
%9 = call i32 @vfork()
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %44
13: ; preds = %7
%14 = icmp eq i32 %9, 0
br i1 %14, label %15, label %44
15: ; preds = %13
%16 = bitcast [100 x i8*]* %8 to i8*
%17 = call i32 @strlen(i8* %0)
%18 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 0
%19 = call i32 @getrawlist(i8* %0, i32 %17, i8** %18, i32 100, i32 0)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 %20
store i8* %4, i8** %21
%22 = icmp eq i8* %4, null
br i1 %22, label %37, label %23
23: ; preds = %15
%24 = add nsw i32 %19, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 %25
store i8* %5, i8** %26
%27 = icmp eq i8* %5, null
br i1 %27, label %37, label %28
28: ; preds = %23
%29 = add nsw i32 %19, 2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 %30
store i8* %6, i8** %31
%32 = icmp eq i8* %6, null
br i1 %32, label %37, label %33
33: ; preds = %28
%34 = add nsw i32 %19, 3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x i8*], [100 x i8*]* %8, i64 0, i64 %35
store i8* null, i8** %36
br label %37
37: ; preds = %33, %28, %23, %15
%38 = call i32 @prepare_child(i32* %1, i32 %2, i32 %3)
%39 = load i8*, i8** %18
%40 = call i32 @execvp(i8* %39, i8** %18)
%41 = load i8*, i8** %18
%42 = call i32 @perror(i8* %41)
%43 = call i32 @_exit(i32 1)
unreachable
44: ; preds = %13, %11
%45 = phi i32 [ -1, %11 ], [ %9, %13 ]
ret i32 %45
}