#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*/ child();
unsigned long fork();
int /*<<< orphan*/ parent();
int /*<<< orphan*/ printf(char *, ...);
int umain() {
  printf("test fork:\n");
  unsigned long i = fork();
  if (i == 0) {
    printf("this is child: %ld\n", i);
    child();
  } else {
    printf("this is parent: %ld\n", i);
    parent();
  }
  printf("test finished\n");
  for (;;)
    ;
}


x86 assembly (clang, -O0):
<umain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118a <umain+0x4a>
mov    -0x8(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <child@plt>
jmp    11a3 <umain+0x63>
mov    -0x8(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <parent@plt>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b1 <umain+0x71>

x86 assembly (clang, -O2):
<umain>:
push   %rax
lea    0xed1(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1183 <umain+0x33>
lea    0xea4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <parent@plt>
jmp    119a <umain+0x4a>
lea    0xe76(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1030 <child@plt>
lea    0xe93(%rip),%rdi
call   1050 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
jmp    11b0 <umain+0x60>

LLVM IR (-O0):
@.str = [12 x i8] c"test fork:\0A\00"
@.str.1 = [20 x i8] c"this is child: %ld\0A\00"
@.str.2 = [21 x i8] c"this is parent: %ld\0A\00"
@.str.3 = [15 x i8] c"test finished\0A\00"
define i32 @umain() {
%1 = alloca i64
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = call i64 (...) @fork()
store i64 %3, i64* %1
%4 = load i64, i64* %1
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i64, i64* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%9 = call i32 (...) @child()
br label %14
10: ; preds = %0
%11 = load i64, i64* %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %11)
%13 = call i32 (...) @parent()
br label %14
14: ; preds = %10, %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %16, %14
br label %16
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"this is child: %ld\0A\00"
@.str.2 = [21 x i8] c"this is parent: %ld\0A\00"
@str = [11 x i8] c"test fork:\00"
@str.4 = [14 x i8] c"test finished\00"
define i32 @umain() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 0)
%6 = tail call i32 (...) @child()
br label %10
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %2)
%9 = tail call i32 (...) @parent()
br label %10
10: ; preds = %7, %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0))
br label %12
12: ; preds = %12, %10
br label %12
}