#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 execv(char *, char *const *);
int fork();
pid_t start_test(char *test) {
  pid_t child_pid;
  char *sh = "/bin/sh";
  char *const argv[] = {sh, test, NULL};
  switch ((child_pid = fork())) {
  case -1:
    return -1;
  case 0:
    return execv(sh, argv);
  default:
    return child_pid;
  }
}


x86 assembly (clang, -O0):
<start_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xecd(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
xor    %eax,%eax
call   1040 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
sub    $0xffffffff,%eax
je     117c <start_test+0x5c>
jmp    116c <start_test+0x4c>
mov    -0x44(%rbp),%eax
test   %eax,%eax
je     1188 <start_test+0x68>
jmp    119d <start_test+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <start_test+0x83>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <execv@plt>
mov    %eax,-0x4(%rbp)
jmp    11a3 <start_test+0x83>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_test>:
sub    $0x18,%rsp
lea    0xed5(%rip),%rax
mov    %rax,(%rsp)
mov    %rdi,0x8(%rsp)
movq   $0x0,0x10(%rsp)
xor    %eax,%eax
call   1040 <fork@plt>
test   %eax,%eax
je     114d <start_test+0x2d>
add    $0x18,%rsp
ret
lea    0xeac(%rip),%rdi
mov    %rsp,%rsi
call   1030 <execv@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
define i32 @start_test(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [3 x i8*]
store i8* %0, i8** %3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %5
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%8 = load i8*, i8** %5
store i8* %8, i8** %7
%9 = getelementptr inbounds i8*, i8** %7, i64 1
%10 = load i8*, i8** %3
store i8* %10, i8** %9
%11 = getelementptr inbounds i8*, i8** %9, i64 1
store i8* null, i8** %11
%12 = call i32 (...) @fork()
store i32 %12, i32* %4
switch i32 %12, label %18 [
i32 -1, label %13
i32 0, label %14
]
13: ; preds = %1
store i32 -1, i32* %2
br label %20
14: ; preds = %1
%15 = load i8*, i8** %5
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%17 = call i32 @execv(i8* %15, i8** %16)
store i32 %17, i32* %2
br label %20
18: ; preds = %1
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %14, %13
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
define i32 @start_test(i8* %0) {
%2 = alloca [3 x i8*]
%3 = bitcast [3 x i8*]* %2 to i8*
%4 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 1
store i8* %0, i8** %5
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 2
store i8* null, i8** %6
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %4)
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ %10, %9 ], [ %7, %1 ]
ret i32 %12
}