#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int __sub_do(void (*fn)(int r), int r) {
  int i;
  if ((i = fork()) == 0) {
    fn(r);
    exit(0);
  } else if (i == -1)
    do {
      write(2, "can't fork away...\n", sizeof("can't fork away...\n") - 1);
      exit(2);
    } while (0);
  waitpid(i, &i, 0);
  return i;
}


x86 assembly (clang, -O0):
<__sub_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    1172 <__sub_do+0x32>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%edi
call   *%rax
xor    %edi,%edi
call   1050 <exit@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    11a1 <__sub_do+0x61>
jmp    1181 <__sub_do+0x41>
mov    $0x2,%edi
lea    0xe73(%rip),%rsi
mov    $0x13,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
jmp    11a6 <__sub_do+0x66>
mov    -0x10(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__sub_do>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
je     1175 <__sub_do+0x35>
test   %eax,%eax
je     1195 <__sub_do+0x55>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe84(%rip),%rsi
mov    $0x2,%edi
mov    $0x13,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    %ebp,%edi
call   *%rbx
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"can't fork away...\0A\00"
define i32 @__sub_do(void (i32)* %0, i32 %1) {
%3 = alloca void (i32)*
%4 = alloca i32
%5 = alloca i32
store void (i32)* %0, void (i32)** %3
store i32 %1, i32* %4
%6 = call i32 (...) @fork()
store i32 %6, i32* %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load void (i32)*, void (i32)** %3
%10 = load i32, i32* %4
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %12
br label %16
16: ; preds = %15
%17 = call i32 @write(i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 19)
%18 = call i32 @exit(i32 2)
unreachable
19: ; No predecessors!
br label %20
20: ; preds = %19, %12
br label %21
21: ; preds = %20
%22 = load i32, i32* %5
%23 = call i32 @waitpid(i32 %22, i32* %5, i32 0)
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
@.str = [20 x i8] c"can't fork away...\0A\00"
define i32 @__sub_do(void (i32)* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @fork()
store i32 %5, i32* %3
switch i32 %5, label %11 [
i32 0, label %6
i32 -1, label %8
]
6: ; preds = %2
tail call void %0(i32 %1)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 19)
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %2
%12 = call i32 @waitpid(i32 %5, i32* %3, i32 0)
%13 = load i32, i32* %3
ret i32 %13
}