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

/* Variables and functions */
scalar_t__ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ sleep(int);
main() {
  pid_t pid;
  int j;
  for (j = 0; j < 10; j++) {
    pid = fork();
    if (pid != 0)
      break;
  }
  printf("El padre del proceso %d es %d, j = %d\n", getpid(), getppid(), j);
  sleep(3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    119e <main+0x4e>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118b <main+0x3b>
jmp    119e <main+0x4e>
jmp    1190 <main+0x40>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <main+0x16>
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
mov    -0x14(%rbp),%ecx
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x2,%ebx
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x3,%ebx
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x4,%ebx
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x5,%ebx
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x6,%ebx
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x7,%ebx
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x8,%ebx
test   %rax,%rax
jne    1204 <main+0xb4>
xor    %eax,%eax
call   1070 <fork@plt>
cmp    $0x1,%rax
mov    $0x9,%ebx
adc    $0x0,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xde5(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %ebx,%ecx
call   1040 <printf@plt>
mov    $0x3,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"El padre del proceso %d es %d, j = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %13, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = call i64 (...) @fork()
store i64 %8, i64* %2
%9 = load i64, i64* %2
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7
br label %16
12: ; preds = %7
br label %13
13: ; preds = %12
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %4
16: ; preds = %11, %4
%17 = call i32 (...) @getpid()
%18 = call i32 (...) @getppid()
%19 = load i32, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i32 %19)
%21 = call i32 @sleep(i32 3)
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [39 x i8] c"El padre del proceso %d es %d, j = %d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %31
3: ; preds = %0
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %31
6: ; preds = %3
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = tail call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = tail call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = tail call i64 (...) @fork()
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = tail call i64 (...) @fork()
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = tail call i64 (...) @fork()
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = tail call i64 (...) @fork()
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i32 10, i32 9
br label %31
31: ; preds = %27, %24, %21, %18, %15, %12, %9, %6, %3, %0
%32 = phi i32 [ 0, %0 ], [ 1, %3 ], [ 2, %6 ], [ 3, %9 ], [ 4, %12 ], [ 5, %15 ], [ 6, %18 ], [ 7, %21 ], [ 8, %24 ], [ %30, %27 ]
%33 = tail call i32 (...) @getpid()
%34 = tail call i32 (...) @getppid()
%35 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34, i32 %32)
%36 = tail call i32 @sleep(i32 3)
ret i32 0
}