#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 */

/* Variables and functions */
int /*<<< orphan*/ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  int i;
  for (i = 0; i < 2; i++) {
    if (!fork()) {
      printf("* ppid = %d, pid = %d, i = %d * ", getppid(), getpid(), i);
    } else {
      printf("# ppid = %d, pid = %d, i = %d # ", getppid(), getpid(), i);
      sleep(5);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    11f3 <main+0xa3>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%eax
jne    11b1 <main+0x61>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
jmp    11e0 <main+0x90>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    11e5 <main+0x95>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
test   %ebp,%ebp
je     118e <main+0x3e>
lea    0xeaa(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <printf@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    11a0 <main+0x50>
lea    0xe6b(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
test   %ebp,%ebp
je     11de <main+0x8e>
lea    0xe5d(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    $0x1,%ecx
call   1040 <printf@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    11f3 <main+0xa3>
lea    0xe1b(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    $0x1,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"* ppid = %d, pid = %d, i = %d * \00"
@.str.1 = [33 x i8] c"# ppid = %d, pid = %d, i = %d # \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %7
7: ; preds = %25, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = call i32 (...) @fork()
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = call i32 (...) @getppid()
%15 = call i32 (...) @getpid()
%16 = load i32, i32* %6
%17 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15, i32 %16)
br label %24
18: ; preds = %10
%19 = call i32 (...) @getppid()
%20 = call i32 (...) @getpid()
%21 = load i32, i32* %6
%22 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20, i32 %21)
%23 = call i32 @sleep(i32 5)
br label %24
24: ; preds = %18, %13
br label %25
25: ; preds = %24
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %7
28: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"* ppid = %d, pid = %d, i = %d * \00"
@.str.1 = [33 x i8] c"# ppid = %d, pid = %d, i = %d # \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
%5 = tail call i32 (...) @getppid()
%6 = tail call i32 (...) @getpid()
br i1 %4, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 0)
br label %12
9: ; preds = %2
%10 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %6, i32 0)
%11 = tail call i32 @sleep(i32 5)
br label %12
12: ; preds = %7, %9
%13 = tail call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
%15 = tail call i32 (...) @getppid()
%16 = tail call i32 (...) @getpid()
br i1 %14, label %20, label %17
17: ; preds = %12
%18 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16, i32 1)
%19 = tail call i32 @sleep(i32 5)
br label %22
20: ; preds = %12
%21 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16, i32 1)
br label %22
22: ; preds = %20, %17
ret i32 0
}