#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 fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int pid;
  fork();
  fork();
  fork();
  pid = fork();
  if (pid == -1)
    printf("problemas ao criar o filho!\n");
  else if (pid == 0)
    printf("Eu sou o filho: %d\n", getpid());
  else
    printf("Eu sou o pai e criei: %d\n", pid);
  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)
mov    $0x0,%al
call   1050 <fork@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1182 <main+0x52>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11be <main+0x8e>
cmpl   $0x0,-0x14(%rbp)
jne    11a8 <main+0x78>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b9 <main+0x89>
mov    -0x14(%rbp),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11be <main+0x8e>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
xor    %eax,%eax
call   1060 <fork@plt>
xor    %eax,%eax
call   1060 <fork@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1174 <main+0x34>
cmp    $0xffffffff,%eax
jne    1184 <main+0x44>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
jmp    1194 <main+0x54>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe7e(%rip),%rdi
jmp    118b <main+0x4b>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"problemas ao criar o filho!\0A\00"
@.str.1 = [20 x i8] c"Eu sou o filho: %d\0A\00"
@.str.2 = [26 x i8] c"Eu sou o pai e criei: %d\0A\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
%7 = call i32 (...) @fork()
%8 = call i32 (...) @fork()
%9 = call i32 (...) @fork()
%10 = call i32 (...) @fork()
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %25
15: ; preds = %2
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 (...) @getpid()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %24
21: ; preds = %15
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24, %13
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"Eu sou o filho: %d\0A\00"
@.str.2 = [26 x i8] c"Eu sou o pai e criei: %d\0A\00"
@str = [28 x i8] c"problemas ao criar o filho!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = tail call i32 (...) @fork()
%5 = tail call i32 (...) @fork()
%6 = tail call i32 (...) @fork()
switch i32 %6, label %12 [
i32 -1, label %7
i32 0, label %9
]
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %14
9: ; preds = %2
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %14
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br label %14
14: ; preds = %9, %12, %7
ret i32 0
}