#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_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ run_something(int, char **);
int /*<<< orphan*/ wait_for_child(int);
int main(int argc, char *argv[]) {
  pid_t cpid;
  cpid = fork();
  if (cpid == -1) {
    perror("fork failed");
    exit(EXIT_FAILURE);
  }
  if (cpid == 0) {
    run_something(argc, argv);
  } else {
    wait_for_child(cpid);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1194 <main+0x44>
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11af <main+0x5f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <run_something@plt>
jmp    11b7 <main+0x67>
mov    -0x14(%rbp),%edi
call   1060 <wait_for_child@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1171 <main+0x21>
cmp    $0xffffffff,%eax
je     118b <main+0x3b>
mov    %eax,%edi
call   1060 <wait_for_child@plt>
jmp    117b <main+0x2b>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <run_something@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe6e(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"fork failed\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @run_something(i32 %18, i8** %19)
br label %24
21: ; preds = %14
%22 = load i32, i32* %6
%23 = call i32 @wait_for_child(i32 %22)
br label %24
24: ; preds = %21, %17
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}

LLVM IR (-O2):
@.str = [12 x i8] c"fork failed\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %10 [
i32 -1, label %4
i32 0, label %8
]
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = tail call i32 @run_something(i32 %0, i8** %1)
br label %12
10: ; preds = %2
%11 = tail call i32 @wait_for_child(i32 %3)
br label %12
12: ; preds = %10, %8
%13 = load i32, i32* @EXIT_SUCCESS
ret i32 %13
}