#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 getppid();
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  for (size_t i = 0; i < 2; i++) {
    pid_t pid = fork();
    if (pid > 0) {
      wait(0);
    } else {
      printf("Processo %i filho de %i\n", getpid(), getppid());
      for (size_t i = 0; i < 2; i++) {
        pid_t pid0 = fork();
        if (pid0 == 0) {
          printf("Processo %i filho de %i\n", getpid(), getppid());
          break;
        }
      }
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x2,-0x18(%rbp)
jae    123e <main+0xee>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    119b <main+0x4b>
xor    %edi,%edi
call   1060 <wait@plt>
jmp    1228 <main+0xd8>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x34(%rbp),%esi
mov    %eax,%edx
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x2,-0x28(%rbp)
jae    1223 <main+0xd3>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    120d <main+0xbd>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x38(%rbp),%esi
mov    %eax,%edx
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
jmp    1223 <main+0xd3>
jmp    1212 <main+0xc2>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c5 <main+0x75>
jmp    123e <main+0xee>
jmp    122d <main+0xdd>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116e <main+0x1e>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jle    1179 <main+0x29>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jle    1179 <main+0x29>
xor    %edi,%edi
call   1060 <wait@plt>
jmp    11d1 <main+0x81>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe70(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11b1 <main+0x61>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    11d1 <main+0x81>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe38(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Processo %i filho de %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
br label %10
10: ; preds = %40, %2
%11 = load i64, i64* %6
%12 = icmp ult i64 %11, 2
br i1 %12, label %13, label %43
13: ; preds = %10
%14 = call i64 (...) @fork()
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @wait(i32 0)
br label %39
19: ; preds = %13
%20 = call i32 (...) @getpid()
%21 = call i32 (...) @getppid()
%22 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
store i64 0, i64* %8
br label %23
23: ; preds = %35, %19
%24 = load i64, i64* %8
%25 = icmp ult i64 %24, 2
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = call i64 (...) @fork()
store i64 %27, i64* %9
%28 = load i64, i64* %9
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = call i32 (...) @getpid()
%32 = call i32 (...) @getppid()
%33 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32)
br label %38
34: ; preds = %26
br label %35
35: ; preds = %34
%36 = load i64, i64* %8
%37 = add i64 %36, 1
store i64 %37, i64* %8
br label %23
38: ; preds = %30, %23
br label %43
39: ; preds = %17
br label %40
40: ; preds = %39
%41 = load i64, i64* %6
%42 = add i64 %41, 1
store i64 %42, i64* %6
br label %10
43: ; preds = %38, %10
ret i32 0
}

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