#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*/ WIFEXITED(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[], char *env[]) {
  char *cadena;
  int estadoChild;
  int id;
  cadena = malloc(20 * sizeof(int));
  switch (id = fork()) {
  case -1:
    printf("Fallo al crear el hijo\n");
    exit(-1);
  case 0:
    printf("Introduzca texto: \n");
    fgets(cadena, 20, stdin);
    exit(0);
  default:
    wait(&estadoChild);
    if (WIFEXITED(estadoChild) == 0) {
      printf("El proceso hijo a terminado anormalmente\n");
      exit(-1);
    } else
      printf("El contenido de la cadena es %s \n", cadena);
  }
  free(cadena);
  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)
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %eax,-0x28(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     11d5 <main+0x55>
jmp    11c5 <main+0x45>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     11ed <main+0x6d>
jmp    1219 <main+0x99>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1050 <fgets@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    -0x24(%rbp),%rdi
call   1090 <wait@plt>
mov    -0x24(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    124b <main+0xcb>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1262 <main+0xe2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x50,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     11bb <main+0x2b>
cmp    $0xffffffff,%eax
jne    11e4 <main+0x54>
lea    0xe7c(%rip),%rdi
jmp    1202 <main+0x72>
lea    0xe60(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <fgets@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xc(%rsp),%rdi
call   10a0 <wait@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %eax,%eax
jne    1211 <main+0x81>
lea    0xe4a(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xde8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@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 = [20 x i8] c"Introduzca texto: \0A\00"
@stdin = global i32 0
@.str.2 = [42 x i8] c"El proceso hijo a terminado anormalmente\0A\00"
@.str.3 = [34 x i8] c"El contenido de la cadena es %s \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 i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = call i8* @malloc(i32 80)
store i8* %11, i8** %8
%12 = call i32 (...) @fork()
store i32 %12, i32* %10
switch i32 %12, label %22 [
i32 -1, label %13
i32 0, label %16
]
13: ; preds = %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8*, i8** %8
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 20, i32 %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %3
%23 = call i32 @wait(i32* %9)
%24 = load i32, i32* %9
%25 = call i32 @WIFEXITED(i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %22
%31 = load i8*, i8** %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30
br label %34
34: ; preds = %33
%35 = load i8*, i8** %8
%36 = call i32 @free(i8* %35)
%37 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.3 = [34 x i8] c"El contenido de la cadena es %s \0A\00"
@str = [19 x i8] c"Introduzca texto: \00"
@str.4 = [23 x i8] c"Fallo al crear el hijo\00"
@str.5 = [41 x i8] c"El proceso hijo a terminado anormalmente\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 dereferenceable_or_null(80) i8* @malloc(i32 80)
%7 = tail call i32 (...) @fork()
switch i32 %7, label %16 [
i32 -1, label %8
i32 0, label %11
]
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = tail call i32 @fgets(i8* %6, i32 20, i32 %13)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %3
%17 = call i32 @wait(i32* %4)
%18 = load i32, i32* %4
%19 = call i32 @WIFEXITED(i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.5, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %16
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%26 = call i32 @free(i8* %6)
%27 = call i32 @exit(i32 0)
unreachable
}