#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*/ _exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ output(char *);
int /*<<< orphan*/ perror(char *);
int main(void) {
  pid_t a;
  if ((a = fork()) > 0) {
    output("string output from parent\n");
  } else if (a == 0) {
    output("message delivered by child\n");
  } else if (a < 0) {
    perror("fork failed");
  }
  _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    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jle    1175 <main+0x35>
lea    0xe95(%rip),%rdi
call   1040 <output@plt>
jmp    11b2 <main+0x72>
cmpq   $0x0,-0x10(%rbp)
jne    1191 <main+0x51>
lea    0xe94(%rip),%rdi
call   1040 <output@plt>
jmp    11ad <main+0x6d>
cmpq   $0x0,-0x10(%rbp)
jge    11a8 <main+0x68>
lea    0xe94(%rip),%rdi
call   1050 <perror@plt>
jmp    11ad <main+0x6d>
jmp    11b2 <main+0x72>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     1162 <main+0x22>
je     116b <main+0x2b>
lea    0xee1(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    0xe97(%rip),%rdi
jmp    1172 <main+0x32>
lea    0xea9(%rip),%rdi
call   1040 <output@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"string output from parent\0A\00"
@.str.1 = [28 x i8] c"message delivered by child\0A\00"
@.str.2 = [12 x i8] c"fork failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @output(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %19
7: ; preds = %0
%8 = load i64, i64* %2
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @output(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %18
12: ; preds = %7
%13 = load i64, i64* %2
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
br label %18
18: ; preds = %17, %10
br label %19
19: ; preds = %18, %5
%20 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [27 x i8] c"string output from parent\0A\00"
@.str.1 = [28 x i8] c"message delivered by child\0A\00"
@.str.2 = [12 x i8] c"fork failed\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp sgt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @output(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %11
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @output(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %7, %9, %3
%12 = tail call i32 @_exit(i32 0)
unreachable
}