#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);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t cPid, cPid1;
  int childstatus, i;
  int Ccount = 2;
  cPid = fork();
  if (cPid == 0) {
    printf(" child: My pid = %d \n", getpid());
    exit(100);
  } else {
    cPid1 = fork();
    if (cPid1 == 0) {
      printf(" child: My pid = %d \n", getpid());
      exit(200);
    } else {
      for (i = 0; i < Ccount; i++)
        wait(NULL);
      printf("parent: end of parent \n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x24(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119d <main+0x4d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x64,%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d4 <main+0x84>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xc8,%edi
call   1050 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11fe <main+0xae>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11db <main+0x8b>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1211 <main+0xc1>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1197 <main+0x37>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11b8 <main+0x58>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe5b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe3a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xc8,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [22 x i8] c" child: My pid = %d \0A\00"
@str = [23 x i8] c"parent: end of parent \00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @exit(i32 100)
unreachable
7: ; preds = %0
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i32 @wait(i32* null)
%12 = tail call i32 @wait(i32* null)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
ret i32 0
14: ; preds = %7
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 @exit(i32 200)
unreachable
}