#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 /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ wait(int *);
void dotest(void (*f)()) {
  pid_t pid = fork();
  if (pid == 0) {
    f();
    _exit(0);
  } else if (pid == -1) {
    fprintf(stderr, "Can't fork (%s)\n", strerror(errno));
  } else {
    int status;
    wait(&status);
  }
}


x86 assembly (clang, -O0):
<dotest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    117c <dotest+0x2c>
mov    $0x0,%al
call   *-0x8(%rbp)
xor    %edi,%edi
call   1030 <_exit@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b7 <dotest+0x67>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe53(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11c0 <dotest+0x70>
lea    -0x10(%rbp),%rdi
call   1060 <wait@plt>
jmp    11c5 <dotest+0x75>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dotest>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
cmp    $0xffffffff,%eax
je     1178 <dotest+0x28>
test   %eax,%eax
je     11a5 <dotest+0x55>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e61(%rip),%rax
mov    (%rax),%ebx
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe6a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x10,%rsp
pop    %rbx
jmp    1040 <fprintf@plt>
xor    %eax,%eax
call   *%rbx
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Can't fork (%s)\0A\00"
@errno = global i32 0
define void @dotest(void (...)* %0) {
%2 = alloca void (...)*
%3 = alloca i32
%4 = alloca i32
store void (...)* %0, void (...)** %2
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load void (...)*, void (...)** %2
%10 = call i32 @_exit(i32 0)
unreachable
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %21
19: ; preds = %11
%20 = call i32 @wait(i32* %4)
br label %21
21: ; preds = %19, %14
br label %22
22: ; preds = %21
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Can't fork (%s)\0A\00"
@errno = global i32 0
define void @dotest(void (...)* nocapture %0) {
%2 = alloca i32
%3 = tail call i32 (...) @fork()
switch i32 %3, label %11 [
i32 0, label %4
i32 -1, label %6
]
4: ; preds = %1
tail call void (...) %0()
%5 = tail call i32 @_exit(i32 0)
unreachable
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %14
11: ; preds = %1
%12 = bitcast i32* %2 to i8*
%13 = call i32 @wait(i32* %2)
br label %14
14: ; preds = %6, %11
ret void
}