#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);
void main() {
  pid_t pid = 1;
  int i = 0;
  for (i; i < 4; i++) {
    if (pid > 0) {
      pid = fork();
      if (pid == 0) {
        printf("Processo filho %d\n", getpid());
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    119f <main+0x6f>
cmpq   $0x0,-0x8(%rbp)
jle    118c <main+0x5c>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1187 <main+0x57>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
jmp    118c <main+0x5c>
jmp    1191 <main+0x61>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1147 <main+0x17>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1169 <main+0x39>
jle    1167 <main+0x37>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1169 <main+0x39>
jle    1167 <main+0x37>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1169 <main+0x39>
jle    1167 <main+0x37>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1169 <main+0x39>
pop    %rax
ret
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
pop    %rax
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Processo filho %d\0A\00"
define void @main() {
%1 = alloca i64
%2 = alloca i32
store i64 1, i64* %1
store i32 0, i32* %2
%3 = load i32, i32* %2
br label %4
4: ; preds = %19, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 4
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = load i64, i64* %1
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = call i64 (...) @fork()
store i64 %11, i64* %1
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 (...) @getpid()
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %10
br label %18
18: ; preds = %17, %7
br label %19
19: ; preds = %18
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %4
22: ; preds = %4
ret void
}

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