#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 /*<<< orphan*/ exit(int);
int fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main() {
  int pid, status;
  printf("Vamos a probar el creado de procesos con fork.\n");
  pid = fork();
  if (pid < 0) {
    printf("Error en la creación del fork.\n");
  }
  if (pid == 0) {
    printf("Este es el proceso hijo con pid=%d\n", pid);
    printf("Y esto arroja su getipd() = %d\n", getpid());
    exit(1);
  }
  waitpid(pid, &status, 0);
  printf("Este es el proceso padre donde pid=%d.\n", pid);
  printf("Y esto arroja su getipd() = %d\n", getpid());
  printf("El valor status es %d\n", status);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    118f <main+0x3f>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11cb <main+0x7b>
mov    -0x8(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x8(%rbp),%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xf17(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11b1 <main+0x51>
jne    11bd <main+0x5d>
lea    0xe79(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe86(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xefa(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
lea    0xe72(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe3b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Vamos a probar el creado de procesos con fork.\0A\00"
@.str.1 = [33 x i8] c"Error en la creaci\C3\B3n del fork.\0A\00"
@.str.2 = [36 x i8] c"Este es el proceso hijo con pid=%d\0A\00"
@.str.3 = [32 x i8] c"Y esto arroja su getipd() = %d\0A\00"
@.str.4 = [40 x i8] c"Este es el proceso padre donde pid=%d.\0A\00"
@.str.5 = [23 x i8] c"El valor status es %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 (...) @getpid()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = load i32, i32* %2
%21 = call i32 @waitpid(i32 %20, i32* %3, i32 0)
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @getpid()
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str.2 = [36 x i8] c"Este es el proceso hijo con pid=%d\0A\00"
@.str.3 = [32 x i8] c"Y esto arroja su getipd() = %d\0A\00"
@.str.4 = [40 x i8] c"Este es el proceso padre donde pid=%d.\0A\00"
@.str.5 = [23 x i8] c"El valor status es %d\0A\00"
@str = [47 x i8] c"Vamos a probar el creado de procesos con fork.\00"
@str.6 = [32 x i8] c"Error en la creaci\C3\B3n del fork.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @fork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
br label %15
8: ; preds = %0
%9 = icmp eq i32 %4, 0
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 0)
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %6, %8
%16 = call i32 @waitpid(i32 %4, i32* %1, i32 0)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %4)
%18 = call i32 (...) @getpid()
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %20)
ret i32 0
}