#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t pid;
  pid = fork();
  if (pid == -1) {
    printf("error\n");
    exit(0);
  } else if (pid == 0) {
    while (1) {
      printf("son\n");
      sleep(5);
    }
  } else {
    while (1) {
      printf("father\n");
      sleep(5);
    }
  }
  return 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)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1176 <main+0x36>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11a0 <main+0x60>
jmp    1185 <main+0x45>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
jmp    1185 <main+0x45>
jmp    11a5 <main+0x65>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
jmp    11a5 <main+0x65>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1174 <main+0x34>
cmp    $0xffffffff,%eax
je     1194 <main+0x54>
lea    0xea8(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
jmp    1160 <main+0x20>
lea    0xe8c(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
jmp    1180 <main+0x40>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"error\0A\00"
@.str.1 = [5 x i8] c"son\0A\00"
@.str.2 = [8 x i8] c"father\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 = load i32, i32* %2
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
br label %13
13: ; preds = %12, %13
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @sleep(i32 5)
br label %13
16: ; preds = %9
br label %17
17: ; preds = %16, %17
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @sleep(i32 5)
br label %17
}

LLVM IR (-O2):
@str = [7 x i8] c"father\00"
@str.3 = [4 x i8] c"son\00"
@str.4 = [6 x i8] c"error\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %8 [
i32 -1, label %2
i32 0, label %5
]
2: ; preds = %0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.4, i64 0, i64 0))
%4 = tail call i32 @exit(i32 0)
unreachable
5: ; preds = %0, %5
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.3, i64 0, i64 0))
%7 = tail call i32 @sleep(i32 5)
br label %5
8: ; preds = %0, %8
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @sleep(i32 5)
br label %8
}