#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 fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  pid_t pid;
  pid = fork();
  if (pid == -1) {
    perror("failure");
  } else if (pid == 0) {
    printf("child process:%d\n", getpid());
  } else {
    printf("parent process:%d\n", getpid());
  }
  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    1174 <main+0x34>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
jmp    11b2 <main+0x72>
cmpl   $0x0,-0x8(%rbp)
jne    1198 <main+0x58>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
jmp    11ad <main+0x6d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
jmp    11b2 <main+0x72>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1161 <main+0x21>
cmp    $0xffffffff,%eax
je     117a <main+0x3a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xebb(%rip),%rdi
jmp    116f <main+0x2f>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe99(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
jmp    1176 <main+0x36>

LLVM IR (-O0):
@.str = [8 x i8] c"failure\00"
@.str.1 = [18 x i8] c"child process:%d\0A\00"
@.str.2 = [19 x i8] c"parent process:%d\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 %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %18
8: ; preds = %0
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 (...) @getpid()
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %17
14: ; preds = %8
%15 = call i32 (...) @getpid()
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %11
br label %18
18: ; preds = %17, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"failure\00"
@.str.1 = [18 x i8] c"child process:%d\0A\00"
@.str.2 = [19 x i8] c"parent process:%d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %7 [
i32 -1, label %2
i32 0, label %4
]
2: ; preds = %0
%3 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %10
4: ; preds = %0
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %10
7: ; preds = %0
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %4, %7, %2
ret i32 0
}