#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 */

/* Variables and functions */
int WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[], char *env[]) {
  int estadoChild;
  int id;
  switch (id = fork()) {
  case -1:
    printf("Fallo al crear el hijo\n");
    exit(-1);
  case 0:
    printf("Soy hijo con PID=%d con PPID=%d\n", getpid(), getppid());
    exit(5);
  default:
    wait(&estadoChild);
    if (WIFEXITED(estadoChild) != 0) {
      printf("Yo soy su padre mi hijo ha devuelto: %d \n",
             WEXITSTATUS(estadoChild));
    } else
      printf("Yo soy su padre y mi hijo a muerto\n");
    break;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %eax,-0x20(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
sub    $0xffffffff,%eax
je     11c7 <main+0x47>
jmp    11b7 <main+0x37>
mov    -0x24(%rbp),%eax
test   %eax,%eax
je     11df <main+0x5f>
jmp    120d <main+0x8d>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%edi
call   1080 <exit@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <wait@plt>
mov    -0x1c(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%eax
je     1244 <main+0xc4>
mov    -0x1c(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1252 <main+0xd2>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1257 <main+0xd7>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     11bb <main+0x2b>
cmp    $0xffffffff,%eax
jne    11e7 <main+0x57>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <getppid@plt>
lea    0xe2e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
lea    0xc(%rsp),%rdi
call   10a0 <wait@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %eax,%eax
jne    1211 <main+0x81>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe00(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Fallo al crear el hijo\0A\00"
@.str.1 = [33 x i8] c"Soy hijo con PID=%d con PPID=%d\0A\00"
@.str.2 = [42 x i8] c"Yo soy su padre mi hijo ha devuelto: %d \0A\00"
@.str.3 = [36 x i8] c"Yo soy su padre y mi hijo a muerto\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = call i32 (...) @fork()
store i32 %10, i32* %9
switch i32 %10, label %19 [
i32 -1, label %11
i32 0, label %14
]
11: ; preds = %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = call i32 (...) @getpid()
%16 = call i32 (...) @getppid()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
%18 = call i32 @exit(i32 5)
unreachable
19: ; preds = %3
%20 = call i32 @wait(i32* %8)
%21 = load i32, i32* %8
%22 = call i32 @WIFEXITED(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* %8
%26 = call i32 @WEXITSTATUS(i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %30
28: ; preds = %19
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
br label %31
31: ; preds = %30
%32 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [33 x i8] c"Soy hijo con PID=%d con PPID=%d\0A\00"
@.str.2 = [42 x i8] c"Yo soy su padre mi hijo ha devuelto: %d \0A\00"
@str = [23 x i8] c"Fallo al crear el hijo\00"
@str.4 = [35 x i8] c"Yo soy su padre y mi hijo a muerto\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 (...) @fork()
switch i32 %6, label %15 [
i32 -1, label %7
i32 0, label %10
]
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %3
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 (...) @getppid()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = tail call i32 @exit(i32 5)
unreachable
15: ; preds = %3
%16 = call i32 @wait(i32* %4)
%17 = load i32, i32* %4
%18 = call i32 @WIFEXITED(i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = load i32, i32* %4
%22 = call i32 @WEXITSTATUS(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %26
24: ; preds = %15
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0))
br label %26
26: ; preds = %20, %24
%27 = call i32 @exit(i32 0)
unreachable
}