#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int execl(char *, char *, int /*<<< orphan*/ *);
int execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
void main(int argc, char *argv[]) {
  pid_t pid = 0;
  printf("El padre esta ejecutando . . . \n");
  pid = fork();
  if (pid < 0) {
    perror("Fork Failed");
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    pid = fork();
    if (pid < 0) {
      perror("Fork Failed");
      exit(EXIT_FAILURE);
    } else if (pid == 0) {
      int ret2 = execlp("./fecha", "fecha", NULL);
      if (ret2 == -1) {
        perror("execl: fecha");
      }
    } else {
      wait(NULL);
      int ret = execl("/bin/ls", "ls", NULL);
      if (ret == -1) {
        perror("execl: ls");
      }
    }
  } else {
    wait(NULL);
    printf("Mis hijos han terminado, adios\n");
    exit(EXIT_SUCCESS);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11c3 <main+0x53>
lea    0xe71(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1286 <main+0x116>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11fe <main+0x8e>
lea    0xe36(%rip),%rdi
call   1040 <perror@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    123e <main+0xce>
lea    0xe1d(%rip),%rdi
lea    0xe25(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execlp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1239 <main+0xc9>
lea    0xe01(%rip),%rdi
call   1040 <perror@plt>
jmp    127c <main+0x10c>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
lea    0xdf4(%rip),%rdi
lea    0xdfc(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1277 <main+0x107>
lea    0xdd8(%rip),%rdi
call   1040 <perror@plt>
jmp    127c <main+0x10c>
jmp    1281 <main+0x111>
jmp    12a9 <main+0x139>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
lea    0xdbe(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    12ae <main+0x13e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11f0 <main+0x80>
jne    120a <main+0x9a>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11f0 <main+0x80>
je     11c7 <main+0x57>
xor    %edi,%edi
call   1080 <wait@plt>
lea    0xe7a(%rip),%rdi
lea    0xe82(%rip),%rsi
xor    %edx,%edx
call   1070 <execl@plt>
cmp    $0xffffffff,%eax
jne    11e1 <main+0x71>
lea    0xe68(%rip),%rdi
pop    %rax
jmp    1040 <perror@plt>
lea    0xe3e(%rip),%rdi
lea    0xe46(%rip),%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
cmp    $0xffffffff,%eax
je     11e3 <main+0x73>
pop    %rax
ret
lea    0xe2a(%rip),%rdi
pop    %rax
jmp    1040 <perror@plt>
lea    0xe09(%rip),%rdi
call   1040 <perror@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
xor    %edi,%edi
call   1080 <wait@plt>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"El padre esta ejecutando . . . \0A\00"
@.str.1 = [12 x i8] c"Fork Failed\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"./fecha\00"
@.str.3 = [6 x i8] c"fecha\00"
@.str.4 = [13 x i8] c"execl: fecha\00"
@.str.5 = [8 x i8] c"/bin/ls\00"
@.str.6 = [3 x i8] c"ls\00"
@.str.7 = [10 x i8] c"execl: ls\00"
@.str.8 = [32 x i8] c"Mis hijos han terminado, adios\0A\00"
@EXIT_SUCCESS = global i32 0
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i64 0, i64* %5
%8 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%9 = call i64 (...) @fork()
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i64, i64* %5
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %47
19: ; preds = %16
%20 = call i64 (...) @fork()
store i64 %20, i64* %5
%21 = load i64, i64* %5
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = load i64, i64* %5
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
br label %45
37: ; preds = %27
%38 = call i32 @wait(i32* null)
%39 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* null)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %44
44: ; preds = %42, %37
br label %45
45: ; preds = %44, %36
br label %46
46: ; preds = %45
br label %52
47: ; preds = %16
%48 = call i32 @wait(i32* null)
%49 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
%50 = load i32, i32* @EXIT_SUCCESS
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %46
br label %53
53: ; preds = %52
ret void
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"Fork Failed\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"./fecha\00"
@.str.3 = [6 x i8] c"fecha\00"
@.str.4 = [13 x i8] c"execl: fecha\00"
@.str.5 = [8 x i8] c"/bin/ls\00"
@.str.6 = [3 x i8] c"ls\00"
@.str.7 = [10 x i8] c"execl: ls\00"
@EXIT_SUCCESS = global i32 0
@str = [32 x i8] c"El padre esta ejecutando . . . \00"
@str.9 = [31 x i8] c"Mis hijos han terminado, adios\00"
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%4 = tail call i64 (...) @fork()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = icmp eq i64 %4, 0
br i1 %11, label %12, label %28
12: ; preds = %10
%13 = tail call i64 (...) @fork()
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %12
%20 = icmp eq i64 %13, 0
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = tail call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
%23 = icmp eq i32 %22, -1
br i1 %23, label %33, label %36
24: ; preds = %19
%25 = tail call i32 @wait(i32* null)
%26 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* null)
%27 = icmp eq i32 %26, -1
br i1 %27, label %33, label %36
28: ; preds = %10
%29 = tail call i32 @wait(i32* null)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%31 = load i32, i32* @EXIT_SUCCESS
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %24, %21
%34 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %21 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), %24 ]
%35 = tail call i32 @perror(i8* %34)
br label %36
36: ; preds = %33, %24, %21
ret void
}