#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*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ charatatime(char *);
int fork();
int /*<<< orphan*/ printf(char *);
int main() {
  int pid;
  if ((pid = fork()) < 0)
    printf("fork error\n");
  else if (pid == 0)
    charatatime("output from child\n");
  else
    charatatime("output from parent\n");
  _exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1173 <main+0x33>
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
jmp    119f <main+0x5f>
cmpl   $0x0,-0x8(%rbp)
jne    118e <main+0x4e>
lea    0xe88(%rip),%rdi
call   1040 <charatatime@plt>
jmp    119a <main+0x5a>
lea    0xe8a(%rip),%rdi
call   1040 <charatatime@plt>
jmp    119f <main+0x5f>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jns    115f <main+0x1f>
lea    0xed4(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
jne    116a <main+0x2a>
lea    0xe98(%rip),%rdi
jmp    1171 <main+0x31>
lea    0xea2(%rip),%rdi
call   1050 <charatatime@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.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() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %0
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @charatatime(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %7
%13 = call i32 @charatatime(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
br label %15
15: ; preds = %14, %5
%16 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"output from child\0A\00"
@.str.2 = [20 x i8] c"output from parent\0A\00"
@str = [11 x i8] c"fork error\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %11
5: ; preds = %0
%6 = icmp eq i32 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @charatatime(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %5
%10 = tail call i32 @charatatime(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %7, %9, %3
%12 = tail call i32 @_exit(i32 0)
unreachable
}