#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(void) {
  pid_t pid;
  pid_t soy, papa, padre;
  int i = 0;
  padre = getpid();
  printf(" Soy%d\n", padre);
  printf(" y voy a ser padre en 10 segundos, así que prepara el ps -ef para "
         "ver a mis hijos\n");
  sleep(10);
  for (i = 0; i < 2; i++)
    pid = fork();
  soy = getpid();
  if (pid == -1) {
    fprintf(stderr, "can't fork, error %d\n", errno);
    exit(EXIT_FAILURE);
  }
  papa = getppid();
  if (pid == 0) {
    printf("\nSoy %d y acabo de nacer", soy);
    printf("\nComprueba que mi padre %d es mi padre\n\n", papa);
    sleep(1);
    int j;
    for (j = 0; j < 4; j++) {
      printf("Soy %d y estoy en la iteracion %d\n", soy, j);
      sleep(5);
    }
    _exit(0);
  } else {
    printf("\nSoy  %d", soy);
    printf("\nComprueba que mi padre %d es mi padre\n\n", papa);
    sleep(1);
    int j;
    for (j = 0; j < 4; j++) {
      printf("Soy %d y estoy en la iteracion %d\n", soy, j);
      sleep(5);
    }
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1090 <sleep@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    11f2 <main+0x72>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d0 <main+0x50>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1232 <main+0xb2>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
lea    0xe3d(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    12b6 <main+0x136>
mov    -0xc(%rbp),%esi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    12af <main+0x12f>
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1279 <main+0xf9>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    -0xc(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    131f <main+0x19f>
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12e9 <main+0x169>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getpid@plt>
cmp    $0xffffffff,%ebp
jne    1209 <main+0x79>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
lea    0xe12(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <getppid@plt>
mov    %eax,%r14d
test   %ebp,%ebp
jne    12bf <main+0x12f>
lea    0xdfa(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe03(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xe11(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    0xdbd(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd61(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xd6f(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c" Soy%d\0A\00"
@.str.1 = [84 x i8] c" y voy a ser padre en 10 segundos, as\C3\AD que prepara el ps -ef para ver a mis hijos\0A\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [25 x i8] c"\0ASoy %d y acabo de nacer\00"
@.str.4 = [41 x i8] c"\0AComprueba que mi padre %d es mi padre\0A\0A\00"
@.str.5 = [35 x i8] c"Soy %d y estoy en la iteracion %d\0A\00"
@.str.6 = [9 x i8] c"\0ASoy %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%9 = call i32 (...) @getpid()
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @sleep(i32 10)
store i32 0, i32* %6
br label %14
14: ; preds = %19, %0
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = call i32 (...) @fork()
store i32 %18, i32* %2
br label %19
19: ; preds = %17
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %14
22: ; preds = %14
%23 = call i32 (...) @getpid()
store i32 %23, i32* %3
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
%33 = call i32 (...) @getppid()
store i32 %33, i32* %4
%34 = load i32, i32* %2
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %55
36: ; preds = %32
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = call i32 @sleep(i32 1)
store i32 0, i32* %7
br label %42
42: ; preds = %50, %36
%43 = load i32, i32* %7
%44 = icmp slt i32 %43, 4
br i1 %44, label %45, label %53
45: ; preds = %42
%46 = load i32, i32* %3
%47 = load i32, i32* %7
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %46, i32 %47)
%49 = call i32 @sleep(i32 5)
br label %50
50: ; preds = %45
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %42
53: ; preds = %42
%54 = call i32 @_exit(i32 0)
unreachable
55: ; preds = %32
%56 = load i32, i32* %3
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %4
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = call i32 @sleep(i32 1)
store i32 0, i32* %8
br label %61
61: ; preds = %69, %55
%62 = load i32, i32* %8
%63 = icmp slt i32 %62, 4
br i1 %63, label %64, label %72
64: ; preds = %61
%65 = load i32, i32* %3
%66 = load i32, i32* %8
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %65, i32 %66)
%68 = call i32 @sleep(i32 5)
br label %69
69: ; preds = %64
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %61
72: ; preds = %61
%73 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c" Soy%d\0A\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [25 x i8] c"\0ASoy %d y acabo de nacer\00"
@.str.4 = [41 x i8] c"\0AComprueba que mi padre %d es mi padre\0A\0A\00"
@.str.5 = [35 x i8] c"Soy %d y estoy en la iteracion %d\0A\00"
@.str.6 = [9 x i8] c"\0ASoy %d\00"
@str = [83 x i8] c" y voy a ser padre en 10 segundos, as\C3\AD que prepara el ps -ef para ver a mis hijos\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @sleep(i32 10)
%5 = tail call i32 (...) @fork()
%6 = tail call i32 (...) @fork()
%7 = tail call i32 (...) @getpid()
%8 = icmp eq i32 %6, -1
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = tail call i32 (...) @getppid()
%17 = icmp eq i32 %6, 0
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%21 = tail call i32 @sleep(i32 1)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 0)
%23 = tail call i32 @sleep(i32 5)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 1)
%25 = tail call i32 @sleep(i32 5)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 2)
%27 = tail call i32 @sleep(i32 5)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 3)
%29 = tail call i32 @sleep(i32 5)
%30 = tail call i32 @_exit(i32 0)
unreachable
31: ; preds = %15
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %7)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%34 = tail call i32 @sleep(i32 1)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 0)
%36 = tail call i32 @sleep(i32 5)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 1)
%38 = tail call i32 @sleep(i32 5)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 2)
%40 = tail call i32 @sleep(i32 5)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 3)
%42 = tail call i32 @sleep(i32 5)
%43 = tail call i32 @exit(i32 0)
unreachable
}