#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 fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int recursive(pid_t pidf, int *end, int *n, int *t) {
  int i = 0;
  pid_t pid;
  if (*end == *n) {
    return 0;
  } else {
    *end += 1;
    printf("\nPadre: %d\n", pidf);
    if ((pid = fork()) > 0) {
      printf("F1: %d->%d\n", getpid(), pid);
      if ((pid = fork()) > 0) {
        printf("F2: %d->%d\n", getpid(), pid);
      } else {
        sleep(*t);
        recursive(getpid(), end, n, t);
        return 0;
      }
      return 0;
    } else {
      sleep(*t);
      recursive(getpid(), end, n, t);
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jne    118c <recursive+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    1270 <recursive+0x120>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jle    1244 <recursive+0xf4>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x28(%rbp),%edx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jle    1207 <recursive+0xb7>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x28(%rbp),%edx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1238 <recursive+0xe8>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <recursive@plt>
movl   $0x0,-0x4(%rbp)
jmp    1270 <recursive+0x120>
movl   $0x0,-0x4(%rbp)
jmp    1270 <recursive+0x120>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <recursive@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    (%rsi),%ecx
cmp    (%rdx),%ecx
je     11df <recursive+0x9f>
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%eax
lea    0xe99(%rip),%r12
lea    0xe9e(%rip),%r13
jmp    1186 <recursive+0x46>
mov    (%r14),%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    (%rbx),%ecx
cmp    (%r15),%ecx
je     11df <recursive+0x9f>
add    $0x1,%ecx
mov    %ecx,(%rbx)
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jle    1170 <recursive+0x30>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r13,%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jle    1170 <recursive+0x30>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe44(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"\0APadre: %d\0A\00"
@.str.1 = [12 x i8] c"F1: %d->%d\0A\00"
@.str.2 = [12 x i8] c"F2: %d->%d\0A\00"
define i32 @recursive(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 0, i32* %10
%12 = load i32*, i32** %7
%13 = load i32, i32* %12
%14 = load i32*, i32** %8
%15 = load i32, i32* %14
%16 = icmp eq i32 %13, %15
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 0, i32* %5
br label %55
18: ; preds = %4
%19 = load i32*, i32** %7
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %19
%22 = load i32, i32* %6
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @fork()
store i32 %24, i32* %11
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %46
26: ; preds = %18
%27 = call i32 (...) @getpid()
%28 = load i32, i32* %11
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28)
%30 = call i32 (...) @fork()
store i32 %30, i32* %11
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = call i32 (...) @getpid()
%34 = load i32, i32* %11
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %34)
br label %45
36: ; preds = %26
%37 = load i32*, i32** %9
%38 = load i32, i32* %37
%39 = call i32 @sleep(i32 %38)
%40 = call i32 (...) @getpid()
%41 = load i32*, i32** %7
%42 = load i32*, i32** %8
%43 = load i32*, i32** %9
%44 = call i32 @recursive(i32 %40, i32* %41, i32* %42, i32* %43)
store i32 0, i32* %5
br label %55
45: ; preds = %32
store i32 0, i32* %5
br label %55
46: ; preds = %18
%47 = load i32*, i32** %9
%48 = load i32, i32* %47
%49 = call i32 @sleep(i32 %48)
%50 = call i32 (...) @getpid()
%51 = load i32*, i32** %7
%52 = load i32*, i32** %8
%53 = load i32*, i32** %9
%54 = call i32 @recursive(i32 %50, i32* %51, i32* %52, i32* %53)
store i32 0, i32* %5
br label %55
55: ; preds = %46, %45, %36, %17
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
@.str = [12 x i8] c"\0APadre: %d\0A\00"
@.str.1 = [12 x i8] c"F1: %d->%d\0A\00"
@.str.2 = [12 x i8] c"F2: %d->%d\0A\00"
define i32 @recursive(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = icmp eq i32 %5, %6
br i1 %7, label %30, label %8
8: ; preds = %4, %23
%9 = phi i32 [ %27, %23 ], [ %5, %4 ]
%10 = phi i32 [ %26, %23 ], [ %0, %4 ]
%11 = add nsw i32 %9, 1
store i32 %11, i32* %1
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
%13 = tail call i32 (...) @fork()
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %8
%16 = tail call i32 (...) @getpid()
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %13)
%18 = tail call i32 (...) @fork()
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = tail call i32 (...) @getpid()
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %18)
br label %30
23: ; preds = %15, %8
%24 = load i32, i32* %3
%25 = tail call i32 @sleep(i32 %24)
%26 = tail call i32 (...) @getpid()
%27 = load i32, i32* %1
%28 = load i32, i32* %2
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %8
30: ; preds = %23, %4, %20
ret i32 0
}