#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, scalar_t__);
void do_fork(pid_t *pid) {
  *pid = fork();
  if (*pid < 0) {
    printf("Can't create a fork. pid=%d\n", *pid);
    exit(EXIT_FAILURE);
  }
  if (*pid > 0) {
    printf("fork created with pid %d\n", *pid);
    exit(EXIT_SUCCESS);
  }
}


x86 assembly (clang, -O0):
<do_fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    117c <do_fork+0x4c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jle    11ab <do_fork+0x7b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_fork>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <fork@plt>
mov    %rax,(%rbx)
test   %rax,%rax
js     1147 <do_fork+0x17>
jne    1164 <do_fork+0x34>
pop    %rbx
ret
lea    0xeb2(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
lea    0xeb2(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Can't create a fork. pid=%d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [26 x i8] c"fork created with pid %d\0A\00"
@EXIT_SUCCESS = global i32 0
define void @do_fork(i64* %0) {
%2 = alloca i64*
store i64* %0, i64** %2
%3 = call i64 (...) @fork()
%4 = load i64*, i64** %2
store i64 %3, i64* %4
%5 = load i64*, i64** %2
%6 = load i64, i64* %5
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i64*, i64** %2
%10 = load i64, i64* %9
%11 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = load i64*, i64** %2
%16 = load i64, i64* %15
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i64*, i64** %2
%20 = load i64, i64* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %20)
%22 = load i32, i32* @EXIT_SUCCESS
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Can't create a fork. pid=%d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [26 x i8] c"fork created with pid %d\0A\00"
@EXIT_SUCCESS = global i32 0
define void @do_fork(i64* nocapture writeonly %0) {
%2 = tail call i64 (...) @fork()
store i64 %2, i64* %0
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %2)
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = icmp eq i64 %2, 0
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %2)
%12 = load i32, i32* @EXIT_SUCCESS
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %8
ret void
}