#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__ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__, int);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  pid_t pid;
  int estado;
  if ((pid = fork()) < 0) {
    perror("\nError en el fork");
    exit(-1);
  } else if (pid == 0) {
    if ((execl("/usr/bin/ldd", "ldd", "./tarea5") < 0)) {
      perror("\nError en el execl");
      exit(-1);
    }
  }
  wait(&estado);
  printf("\nMi hijo %d ha finalizado con el estado %d\n", pid, estado);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11a1 <main+0x41>
lea    0xe6e(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11eb <main+0x8b>
lea    0xe5f(%rip),%rdi
lea    0xe61(%rip),%rsi
lea    0xe5e(%rip),%rdx
call   1060 <execl@plt>
cmp    $0x0,%rax
jge    11e6 <main+0x86>
lea    0xe51(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
jmp    11eb <main+0x8b>
jmp    11f0 <main+0x90>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jns    117a <main+0x1a>
lea    0xe88(%rip),%rdi
jmp    11a5 <main+0x45>
mov    %rax,%rbx
jne    11b4 <main+0x54>
lea    0xe8c(%rip),%rdi
lea    0xe8e(%rip),%rsi
lea    0xe8b(%rip),%rdx
call   1060 <execl@plt>
test   %rax,%rax
jns    11b4 <main+0x54>
lea    0xe83(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
mov    0xc(%rsp),%edx
lea    0xe72(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"\0AError en el fork\00"
@.str.1 = [13 x i8] c"/usr/bin/ldd\00"
@.str.2 = [4 x i8] c"ldd\00"
@.str.3 = [9 x i8] c"./tarea5\00"
@.str.4 = [19 x i8] c"\0AError en el execl\00"
@.str.5 = [44 x i8] c"\0AMi hijo %d ha finalizado con el estado %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = load i64, i64* %6
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = call i64 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %16
br label %23
23: ; preds = %22, %13
br label %24
24: ; preds = %23
%25 = call i32 @wait(i32* %7)
%26 = load i64, i64* %6
%27 = load i32, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i64 %26, i32 %27)
%29 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [18 x i8] c"\0AError en el fork\00"
@.str.1 = [13 x i8] c"/usr/bin/ldd\00"
@.str.2 = [4 x i8] c"ldd\00"
@.str.3 = [9 x i8] c"./tarea5\00"
@.str.4 = [19 x i8] c"\0AError en el execl\00"
@.str.5 = [44 x i8] c"\0AMi hijo %d ha finalizado con el estado %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = icmp eq i64 %5, 0
br i1 %11, label %12, label %18
12: ; preds = %10
%13 = tail call i64 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %10, %12
%19 = call i32 @wait(i32* %3)
%20 = load i32, i32* %3
%21 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i64 %5, i32 %20)
%22 = call i32 @exit(i32 0)
unreachable
}