#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*/ charactatime(char *);
int /*<<< orphan*/ err_sys(char *);
scalar_t__ fork();
int main(int argc, char **argv) {
  pid_t pid;
  if ((pid = fork()) < 0) {
    err_sys("error on fork");
  } else if (pid == 0) {
    charactatime("output from child\n");
  } else {
    charactatime("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   1050 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    116c <main+0x3c>
lea    0xe9e(%rip),%rdi
call   1030 <err_sys@plt>
jmp    1199 <main+0x69>
cmpq   $0x0,-0x18(%rbp)
jne    1188 <main+0x58>
lea    0xe90(%rip),%rdi
call   1040 <charactatime@plt>
jmp    1194 <main+0x64>
lea    0xe92(%rip),%rdi
call   1040 <charactatime@plt>
jmp    1199 <main+0x69>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
js     1148 <main+0x18>
je     1156 <main+0x26>
lea    0xedb(%rip),%rdi
jmp    115d <main+0x2d>
lea    0xeb1(%rip),%rdi
call   1030 <err_sys@plt>
jmp    1162 <main+0x32>
lea    0xeb1(%rip),%rdi
call   1040 <charactatime@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"error on fork\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 i64 (...) @fork()
store i64 %7, i64* %6
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %19
11: ; preds = %2
%12 = load i64, i64* %6
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @charactatime(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %18
16: ; preds = %11
%17 = call i32 @charactatime(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
br label %19
19: ; preds = %18, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"error on fork\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 i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %13
7: ; preds = %2
%8 = icmp eq i64 %3, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @charactatime(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %13
11: ; preds = %7
%12 = tail call i32 @charactatime(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %9, %11, %5
ret i32 0
}