#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_PARENT(int /*<<< orphan*/);
int /*<<< orphan*/ TELL_WAIT();
int /*<<< orphan*/ WAIT_CHILD();
int /*<<< orphan*/ charatatime(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getppid();
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) {
    charatatime("output from child\n");
    TELL_PARENT(getppid());
  } else {
    WAIT_CHILD();
    charatatime("output from parent\n");
  }
  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   1060 <TELL_WAIT@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11d1 <main+0x51>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11fb <main+0x7b>
lea    0xe29(%rip),%rdi
call   1040 <charatatime@plt>
mov    $0x0,%al
call   1080 <getppid@plt>
mov    %eax,%edi
call   1050 <TELL_PARENT@plt>
jmp    120e <main+0x8e>
mov    $0x0,%al
call   1030 <WAIT_CHILD@plt>
lea    0xe16(%rip),%rdi
call   1040 <charatatime@plt>
jmp    1213 <main+0x93>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <TELL_WAIT@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     11c9 <main+0x49>
je     11ab <main+0x2b>
xor    %eax,%eax
call   1030 <WAIT_CHILD@plt>
lea    0xe7b(%rip),%rdi
call   1040 <charatatime@plt>
jmp    11c5 <main+0x45>
lea    0xe5a(%rip),%rdi
call   1040 <charatatime@plt>
xor    %eax,%eax
call   1080 <getppid@plt>
mov    %eax,%edi
call   1050 <TELL_PARENT@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <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 %21
17: ; preds = %14
%18 = call i32 @charatatime(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (...) @getppid()
%20 = call i32 @TELL_PARENT(i32 %19)
br label %24
21: ; preds = %14
%22 = call i32 (...) @WAIT_CHILD()
%23 = call i32 @charatatime(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %21, %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 %16
12: ; preds = %10
%13 = tail call i32 @charatatime(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 (...) @getppid()
%15 = tail call i32 @TELL_PARENT(i32 %14)
br label %19
16: ; preds = %10
%17 = tail call i32 (...) @WAIT_CHILD()
%18 = tail call i32 @charatatime(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %12, %16
ret i32 0
}