#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 int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid1, pid2, pid3;
  int status1, status2, status3;
  if ((pid1 = fork()) == 0)
    printf("Soy el primer hijo (%d, hijo de %d)\n", getpid(), getppid());
  else {
    waitpid(pid1, &status1, 0);
    if ((pid2 = fork()) == 0) {
      printf("Soy el segundo hijo (%d, hijo de %d)\n", getpid(), getppid());
    } else {
      waitpid(pid2, &status2, 0);
      if ((pid3 = fork()) == 0) {
        printf("Soy el tercer hijo (%d, hijo de %d)\n", getpid(), getppid());
      } else {
        waitpid(pid1, &status1, 0);
        waitpid(pid2, &status2, 0);
        waitpid(pid3, &status3, 0);
        printf("Soy el padre (%d, hijo de %d)\n", getpid(), getppid());
      }
    }
  }
  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)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11a0 <main+0x50>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x136>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11e8 <main+0x98>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x30(%rbp),%esi
mov    %eax,%edx
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
jmp    1281 <main+0x131>
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1230 <main+0xe0>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x34(%rbp),%esi
mov    %eax,%edx
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
jmp    127c <main+0x12c>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x38(%rbp),%esi
mov    %eax,%edx
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
jmp    1281 <main+0x131>
jmp    1286 <main+0x136>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11e0 <main+0x90>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11f9 <main+0xa9>
mov    %eax,%ebp
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1212 <main+0xc2>
mov    %eax,%r14d
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe92(%rip),%rdi
jmp    1229 <main+0xd9>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe09(%rip),%rdi
jmp    1229 <main+0xd9>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe15(%rip),%rdi
jmp    1229 <main+0xd9>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe22(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [37 x i8] c"Soy el primer hijo (%d, hijo de %d)\0A\00"
@.str.1 = [38 x i8] c"Soy el segundo hijo (%d, hijo de %d)\0A\00"
@.str.2 = [37 x i8] c"Soy el tercer hijo (%d, hijo de %d)\0A\00"
@.str.3 = [31 x i8] c"Soy el padre (%d, hijo de %d)\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 (...) @getppid()
%14 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
br label %38
15: ; preds = %2
%16 = call i32 @waitpid(i32 %9, i32* %3, i32 0)
%17 = call i32 (...) @fork()
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = call i32 (...) @getpid()
%21 = call i32 (...) @getppid()
%22 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21)
br label %38
23: ; preds = %15
%24 = call i32 @waitpid(i32 %17, i32* %4, i32 0)
%25 = call i32 (...) @fork()
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = call i32 (...) @getpid()
%29 = call i32 (...) @getppid()
%30 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29)
br label %38
31: ; preds = %23
%32 = call i32 @waitpid(i32 %9, i32* %3, i32 0)
%33 = call i32 @waitpid(i32 %17, i32* %4, i32 0)
%34 = call i32 @waitpid(i32 %25, i32* %5, i32 0)
%35 = call i32 (...) @getpid()
%36 = call i32 (...) @getppid()
%37 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36)
br label %38
38: ; preds = %19, %31, %27, %11
ret i32 0
}