#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*/ charatatime(char *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int main(void) {
  int pid;
  if ((pid = fork()) < 0) {
    perror("Fork error");
    exit(1);
  } else if (pid == 0) {
    charatatime("Output from Process Q\n");
  } else {
    charatatime("Output from Process P\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    1178 <main+0x38>
lea    0xe97(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1193 <main+0x53>
lea    0xe82(%rip),%rdi
call   1030 <charatatime@plt>
jmp    119f <main+0x5f>
lea    0xe88(%rip),%rdi
call   1030 <charatatime@plt>
jmp    11a4 <main+0x64>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jns    1162 <main+0x22>
lea    0xead(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xea2(%rip),%rax
lea    0xeb2(%rip),%rdi
cmove  %rax,%rdi
call   1030 <charatatime@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"Fork error\00"
@.str.1 = [23 x i8] c"Output from Process Q\0A\00"
@.str.2 = [23 x i8] c"Output from Process P\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 %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @charatatime(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %15
13: ; preds = %8
%14 = call i32 @charatatime(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
br label %16
16: ; preds = %15
%17 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"Fork error\00"
@.str.1 = [23 x i8] c"Output from Process Q\0A\00"
@.str.2 = [23 x i8] c"Output from Process P\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = icmp eq i32 %1, 0
%8 = select i1 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0)
%9 = tail call i32 @charatatime(i8* %8)
%10 = tail call i32 @exit(i32 0)
unreachable
}