#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*/ TELL_CHILD(scalar_t__);
int /*<<< orphan*/ TELL_WAIT();
int /*<<< orphan*/ WAIT_PARENT();
int /*<<< orphan*/ charatatime(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char const *argv[]) {
  pid_t pid;
  TELL_WAIT();
  if ((pid = fork()) < 0) {
    fprintf(stderr, "fork error\n");
    exit(1);
  } else if (pid == 0) {
    WAIT_PARENT();
    charatatime("output from child\n");
  } else {
    charatatime("output from parent\n");
    TELL_CHILD(pid);
  }
  return 0;
}


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   1050 <TELL_WAIT@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11c1 <main+0x51>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <main+0x74>
mov    $0x0,%al
call   1080 <WAIT_PARENT@plt>
lea    0xe32(%rip),%rdi
call   1030 <charatatime@plt>
jmp    11f9 <main+0x89>
lea    0xe34(%rip),%rdi
call   1030 <charatatime@plt>
mov    -0x18(%rbp),%rdi
call   1040 <TELL_CHILD@plt>
jmp    11fe <main+0x8e>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <TELL_WAIT@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11b6 <main+0x46>
je     119f <main+0x2f>
mov    %rax,%rbx
lea    0xe8f(%rip),%rdi
call   1030 <charatatime@plt>
mov    %rbx,%rdi
call   1040 <TELL_CHILD@plt>
jmp    11b2 <main+0x42>
xor    %eax,%eax
call   1080 <WAIT_PARENT@plt>
lea    0xe5f(%rip),%rdi
call   1030 <charatatime@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"fork error\0A\00"
@.str.1 = [19 x i8] c"output from child\0A\00"
@.str.2 = [20 x i8] c"output from parent\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @TELL_WAIT()
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i64, i64* %6
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 (...) @WAIT_PARENT()
%19 = call i32 @charatatime(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %14
%21 = call i32 @charatatime(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%22 = load i64, i64* %6
%23 = call i32 @TELL_CHILD(i64 %22)
br label %24
24: ; preds = %20, %17
br label %25
25: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"fork error\0A\00"
@.str.1 = [19 x i8] c"output from child\0A\00"
@.str.2 = [20 x i8] c"output from parent\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @TELL_WAIT()
%4 = tail call i64 (...) @fork()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = icmp eq i64 %4, 0
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = tail call i32 (...) @WAIT_PARENT()
%14 = tail call i32 @charatatime(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %18
15: ; preds = %10
%16 = tail call i32 @charatatime(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @TELL_CHILD(i64 %4)
br label %18
18: ; preds = %12, %15
ret i32 0
}