#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 /*<<< orphan*/ execl(char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void forkprocess(char *process) {
  pid_t pid = fork();
  if (pid == 0) {
    execl("test-spawn", "");
  } else if (pid < 0) {
    printf("failed to fork()");
    exit(1);
  } else {
    int status;
    waitpid(pid, &status, 0);
  }
}


x86 assembly (clang, -O0):
<forkprocess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118a <forkprocess+0x3a>
lea    0xe87(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <execl@plt>
jmp    11bf <forkprocess+0x6f>
cmpq   $0x0,-0x10(%rbp)
jge    11ab <forkprocess+0x5b>
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
jmp    11bf <forkprocess+0x6f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forkprocess>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1170 <forkprocess+0x20>
js     1184 <forkprocess+0x34>
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <waitpid@plt>
pop    %rax
ret
lea    0xe89(%rip),%rdi
lea    0xe9d(%rip),%rsi
pop    %rax
jmp    1060 <execl@plt>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"test-spawn\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [17 x i8] c"failed to fork()\00"
define void @forkprocess(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i64 (...) @fork()
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %20
10: ; preds = %1
%11 = load i64, i64* %3
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %10
%17 = load i64, i64* %3
%18 = call i32 @waitpid(i64 %17, i32* %4, i32 0)
br label %19
19: ; preds = %16
br label %20
20: ; preds = %19, %8
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"test-spawn\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [17 x i8] c"failed to fork()\00"
define void @forkprocess(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = icmp slt i64 %3, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %7
%13 = bitcast i32* %2 to i8*
%14 = call i32 @waitpid(i64 %3, i32* %2, i32 0)
br label %15
15: ; preds = %12, %5
ret void
}