#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;
  int status1, status2;
  if ((pid1 = fork()) == 0)
    printf("Soy el primer hijo (%d, hijo de %d)\n", getpid(), getppid());
  else {
    if ((pid2 = fork()) == 0) {
      printf("Soy el segundo hijo (%d, hijo de %d)\n", getpid(), getppid());
    } else {
      waitpid(pid1, &status1, 0);
      waitpid(pid2, &status2, 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    $0x30,%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,-0x24(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
jmp    121d <main+0xcd>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11da <main+0x8a>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
jmp    1218 <main+0xc8>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
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    0xe38(%rip),%rdi
call   1040 <printf@plt>
jmp    121d <main+0xcd>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11a0 <main+0x50>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11b9 <main+0x69>
mov    %eax,%ebp
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %rsp,%rsi
mov    %ebp,%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    0xead(%rip),%rdi
jmp    11d0 <main+0x80>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe49(%rip),%rdi
jmp    11d0 <main+0x80>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe55(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
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 = [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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @fork()
store i32 %10, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 (...) @getpid()
%14 = call i32 (...) @getppid()
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
br label %32
16: ; preds = %2
%17 = call i32 (...) @fork()
store i32 %17, i32* %7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%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 %31
23: ; preds = %16
%24 = load i32, i32* %6
%25 = call i32 @waitpid(i32 %24, i32* %8, i32 0)
%26 = load i32, i32* %7
%27 = call i32 @waitpid(i32 %26, i32* %9, i32 0)
%28 = call i32 (...) @getpid()
%29 = call i32 (...) @getppid()
%30 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29)
br label %31
31: ; preds = %23, %19
br label %32
32: ; preds = %31, %12
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 = [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 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (...) @getppid()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
br label %26
13: ; preds = %2
%14 = tail call i32 (...) @fork()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = tail call i32 (...) @getpid()
%18 = tail call i32 (...) @getppid()
%19 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
br label %26
20: ; preds = %13
%21 = call i32 @waitpid(i32 %7, i32* %3, i32 0)
%22 = call i32 @waitpid(i32 %14, i32* %4, i32 0)
%23 = call i32 (...) @getpid()
%24 = call i32 (...) @getppid()
%25 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24)
br label %26
26: ; preds = %16, %20, %9
ret i32 0
}