#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 execv(char *, char **);
scalar_t__ fork();
scalar_t__ getpid();
int setpgid(scalar_t__ const, scalar_t__ const);
int /*<<< orphan*/ throw(char *);
pid_t start_process(char *argv[]) {
  const pid_t parent_pid = getpid();
  const pid_t pid = fork();
  if (pid == 0) {
    if (setpgid(pid, parent_pid) == -1) {
      throw("Could not set group id for child process");
    }
    if (execv(argv[0], argv) == -1) {
      throw("Error opening child process");
    }
  }
  return pid;
}


x86 assembly (clang, -O0):
<start_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <start_process+0x79>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <setpgid@plt>
cmp    $0xffffffff,%eax
jne    119f <start_process+0x4f>
lea    0xe66(%rip),%rdi
call   1040 <throw@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <execv@plt>
cmp    $0xffffffff,%eax
jne    11c4 <start_process+0x74>
lea    0xe6a(%rip),%rdi
call   1040 <throw@plt>
jmp    11c9 <start_process+0x79>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_process>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a8 <start_process+0x58>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <setpgid@plt>
cmp    $0xffffffff,%eax
jne    118c <start_process+0x3c>
lea    0xe79(%rip),%rdi
call   1040 <throw@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1060 <execv@plt>
cmp    $0xffffffff,%eax
jne    11a8 <start_process+0x58>
lea    0xe86(%rip),%rdi
call   1040 <throw@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Could not set group id for child process\00"
@.str.1 = [28 x i8] c"Error opening child process\00"
define i64 @start_process(i8** %0) {
%2 = alloca i8**
%3 = alloca i64
%4 = alloca i64
store i8** %0, i8*** %2
%5 = call i64 (...) @getpid()
store i64 %5, i64* %3
%6 = call i64 (...) @fork()
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %1
%10 = load i64, i64* %4
%11 = load i64, i64* %3
%12 = call i32 @setpgid(i64 %10, i64 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @throw(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = load i8**, i8*** %2
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %2
%21 = call i32 @execv(i8* %19, i8** %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @throw(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
br label %26
26: ; preds = %25, %1
%27 = load i64, i64* %4
ret i64 %27
}

LLVM IR (-O2):
@.str = [41 x i8] c"Could not set group id for child process\00"
@.str.1 = [28 x i8] c"Error opening child process\00"
define i64 @start_process(i8** %0) {
%2 = tail call i64 (...) @getpid()
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = tail call i32 @setpgid(i64 0, i64 %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @throw(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = load i8*, i8** %0
%12 = tail call i32 @execv(i8* %11, i8** %0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @throw(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %10, %14, %1
ret i64 %3
}