#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*/ waitpid(int, int *, int /*<<< orphan*/);
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:
    waitpid(id, &estadoChild, 0);
    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   1090 <exit@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1080 <getppid@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x1c(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%eax
je     1249 <main+0xc9>
mov    -0x1c(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1257 <main+0xd7>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125c <main+0xdc>
xor    %edi,%edi
call   1090 <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   10a0 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <getppid@plt>
lea    0xe2e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %eax,%eax
jne    1215 <main+0x85>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
lea    0xdfc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <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 = load i32, i32* %9
%21 = call i32 @waitpid(i32 %20, i32* %8, i32 0)
%22 = load i32, i32* %8
%23 = call i32 @WIFEXITED(i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* %8
%27 = call i32 @WEXITSTATUS(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %31
29: ; preds = %19
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
br label %32
32: ; preds = %31
%33 = 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 @waitpid(i32 %6, i32* %4, i32 0)
%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
}