#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*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int i;
  printf("Raiz: PID=%d PPID=%d\n", getpid(), getppid());
  for (i = 0; i < 5; i++) {
    switch (fork()) {
    case 0:
      printf("Proceso hijo(GEN %d): PID=%d PPID=%d\n", i + 1, getpid(),
             getppid());
      break;
    case -1:
      printf("Error en la funcion fork()\n");
      break;
    default:
      printf("Proceso padre(GEN %d): PID=%d\n", i + 1, getpid());
      break;
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1243 <main+0xf3>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     11fa <main+0xaa>
jmp    11b5 <main+0x65>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
jne    120d <main+0xbd>
jmp    11c5 <main+0x75>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1230 <main+0xe0>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1230 <main+0xe0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1235 <main+0xe5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1191 <main+0x41>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe88(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11bc <main+0x5c>
test   %eax,%eax
jne    11ca <main+0x6a>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe6c(%rip),%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11e6 <main+0x86>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
jmp    11e6 <main+0x86>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe64(%rip),%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1204 <main+0xa4>
cmp    $0xffffffff,%eax
jne    122d <main+0xcd>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
jmp    1249 <main+0xe9>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xdfb(%rip),%rdi
mov    $0x2,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1249 <main+0xe9>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe01(%rip),%rdi
mov    $0x2,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1267 <main+0x107>
cmp    $0xffffffff,%eax
jne    1290 <main+0x130>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
jmp    12ac <main+0x14c>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xd98(%rip),%rdi
mov    $0x3,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12ac <main+0x14c>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd9e(%rip),%rdi
mov    $0x3,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     12ca <main+0x16a>
cmp    $0xffffffff,%eax
jne    12f3 <main+0x193>
lea    0xd98(%rip),%rdi
call   1030 <puts@plt>
jmp    130f <main+0x1af>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xd35(%rip),%rdi
mov    $0x4,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    130f <main+0x1af>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd3b(%rip),%rdi
mov    $0x4,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1332 <main+0x1d2>
cmp    $0xffffffff,%eax
jne    1360 <main+0x200>
lea    0xd35(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xccd(%rip),%rdi
mov    $0x5,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xcce(%rip),%rdi
mov    $0x5,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Raiz: PID=%d PPID=%d\0A\00"
@.str.1 = [38 x i8] c"Proceso hijo(GEN %d): PID=%d PPID=%d\0A\00"
@.str.2 = [28 x i8] c"Error en la funcion fork()\0A\00"
@.str.3 = [31 x i8] c"Proceso padre(GEN %d): PID=%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 (...) @getpid()
%8 = call i32 (...) @getppid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
store i32 0, i32* %6
br label %10
10: ; preds = %29, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %32
13: ; preds = %10
%14 = call i32 (...) @fork()
switch i32 %14, label %23 [
i32 0, label %15
i32 -1, label %21
]
15: ; preds = %13
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
%18 = call i32 (...) @getpid()
%19 = call i32 (...) @getppid()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i32 %19)
br label %28
21: ; preds = %13
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %28
23: ; preds = %13
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
%26 = call i32 (...) @getpid()
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %23, %21, %15
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %10
32: ; preds = %10
%33 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [22 x i8] c"Raiz: PID=%d PPID=%d\0A\00"
@.str.1 = [38 x i8] c"Proceso hijo(GEN %d): PID=%d PPID=%d\0A\00"
@.str.3 = [31 x i8] c"Proceso padre(GEN %d): PID=%d\0A\00"
@str = [27 x i8] c"Error en la funcion fork()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (...) @getppid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%6 = tail call i32 (...) @fork()
switch i32 %6, label %13 [
i32 0, label %7
i32 -1, label %11
]
7: ; preds = %2
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 (...) @getppid()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %8, i32 %9)
br label %16
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %16
13: ; preds = %2
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %14)
br label %16
16: ; preds = %7, %11, %13
%17 = tail call i32 (...) @fork()
switch i32 %17, label %24 [
i32 0, label %20
i32 -1, label %18
]
18: ; preds = %16
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %27
20: ; preds = %16
%21 = tail call i32 (...) @getpid()
%22 = tail call i32 (...) @getppid()
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %21, i32 %22)
br label %27
24: ; preds = %16
%25 = tail call i32 (...) @getpid()
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 %25)
br label %27
27: ; preds = %24, %20, %18
%28 = tail call i32 (...) @fork()
switch i32 %28, label %35 [
i32 0, label %31
i32 -1, label %29
]
29: ; preds = %27
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %38
31: ; preds = %27
%32 = tail call i32 (...) @getpid()
%33 = tail call i32 (...) @getppid()
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %32, i32 %33)
br label %38
35: ; preds = %27
%36 = tail call i32 (...) @getpid()
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 3, i32 %36)
br label %38
38: ; preds = %35, %31, %29
%39 = tail call i32 (...) @fork()
switch i32 %39, label %46 [
i32 0, label %42
i32 -1, label %40
]
40: ; preds = %38
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %49
42: ; preds = %38
%43 = tail call i32 (...) @getpid()
%44 = tail call i32 (...) @getppid()
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %43, i32 %44)
br label %49
46: ; preds = %38
%47 = tail call i32 (...) @getpid()
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 4, i32 %47)
br label %49
49: ; preds = %46, %42, %40
%50 = tail call i32 (...) @fork()
switch i32 %50, label %57 [
i32 0, label %53
i32 -1, label %51
]
51: ; preds = %49
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %60
53: ; preds = %49
%54 = tail call i32 (...) @getpid()
%55 = tail call i32 (...) @getppid()
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 %54, i32 %55)
br label %60
57: ; preds = %49
%58 = tail call i32 (...) @getpid()
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 5, i32 %58)
br label %60
60: ; preds = %57, %53, %51
%61 = tail call i32 @exit(i32 0)
unreachable
}