#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 */
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(scalar_t__ *);
int main() {
  pid_t a_pid, b_pid;
  if ((a_pid = fork()) < 0)
    printf("error!\n");
  else if (a_pid == 0) {
    printf("the first child pid = %d\n", getpid());
    printf("a\n");
  } else {
    printf("the parent pid = %d\n", getpid());
    printf("a\n");
  }
  if ((b_pid = fork()) < 0)
    printf("error!\n");
  else if (b_pid == 0) {
    printf("c\n");
  } else {
    printf("e\n");
  }
  wait(&a_pid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    1177 <main+0x37>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d6 <main+0x96>
cmpq   $0x0,-0x10(%rbp)
jne    11ac <main+0x6c>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d1 <main+0x91>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d6 <main+0x96>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11fe <main+0xbe>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122f <main+0xef>
cmpq   $0x0,-0x18(%rbp)
jne    121c <main+0xdc>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122a <main+0xea>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122f <main+0xef>
lea    -0x10(%rbp),%rdi
call   1050 <wait@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,0x8(%rsp)
lea    0xec9(%rip),%r15
mov    %r15,%r14
test   %rax,%rax
js     11a3 <main+0x53>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
test   %rbx,%rbx
lea    0xe78(%rip),%rcx
lea    0xe8b(%rip),%rdi
cmove  %rcx,%rdi
lea    0xe99(%rip),%r14
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
lea    0xe75(%rip),%rax
lea    0xe6c(%rip),%rdi
cmove  %rax,%rdi
cmovs  %r15,%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1060 <wait@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"error!\0A\00"
@.str.1 = [26 x i8] c"the first child pid = %d\0A\00"
@.str.2 = [3 x i8] c"a\0A\00"
@.str.3 = [21 x i8] c"the parent pid = %d\0A\00"
@.str.4 = [3 x i8] c"c\0A\00"
@.str.5 = [3 x i8] c"e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 (...) @getpid()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %19
15: ; preds = %8
%16 = call i32 (...) @getpid()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %15, %11
br label %20
20: ; preds = %19, %6
%21 = call i64 (...) @fork()
store i64 %21, i64* %3
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %33
25: ; preds = %20
%26 = load i64, i64* %3
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %32
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
br label %33
33: ; preds = %32, %23
%34 = call i32 @wait(i64* %2)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"the first child pid = %d\0A\00"
@.str.3 = [21 x i8] c"the parent pid = %d\0A\00"
@str.6 = [2 x i8] c"e\00"
@str.7 = [2 x i8] c"c\00"
@str.9 = [2 x i8] c"a\00"
@str.10 = [7 x i8] c"error!\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i64 (...) @fork()
store i64 %3, i64* %1
%4 = icmp slt i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %0
%6 = icmp eq i64 %3, 0
%7 = tail call i32 (...) @getpid()
%8 = select i1 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0)
%9 = select i1 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %8, i32 %7)
br label %11
11: ; preds = %5, %0
%12 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.10, i64 0, i64 0), %0 ], [ %9, %5 ]
%13 = tail call i32 @puts(i8* dereferenceable(1) %12)
%14 = tail call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
%16 = icmp eq i64 %14, 0
%17 = select i1 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0)
%18 = select i1 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.10, i64 0, i64 0), i8* %17
%19 = tail call i32 @puts(i8* dereferenceable(1) %18)
%20 = call i32 @wait(i64* %1)
ret i32 0
}