#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int write(int, char *, int);
main() {
  int err, fifo_d;
  char buff[80];
  int leido;
  unlink("/tmp/MI_FIFO");
  err = mkfifo("/tmp/MI_FIFO", 0777);
  if (err == -1) {
    write(0, "\nError al crear FIFO, la FIFO ya existe",
          sizeof("\nError al crear FIFO, la FIFO ya existe"));
  } else {
    write(0, "\nFIFO creado correctamente\n",
          sizeof("\nFIFO creado correctamente\n"));
  }
  switch (fork()) {
  case -1:
    write(0, "\nError al crear hijo", sizeof("\nError al crear hijo"));
    return -1;
    break;
  case 0:
    write(0, "\nEntrando proceso HIJO", sizeof("\nEntrando proceso HIJO"));
    sleep(5);
    write(0, "\nSaliendo proceso HIJO\n", sizeof("\nSaliendo proceso HIJO\n"));
    exit(0);
    break;
  default:
    write(0, "\nEntrando proceso PADRE", sizeof("\nEntrando proceso PADRE"));
    fifo_d = open("/tmp/MI_FIFO", O_WRONLY, 0);
    if (fifo_d == -1) {
      write(0, "\nPADRE: Error al abrir FIFO ",
            sizeof("\nPADRE: Error al abrir FIFO "));
      return -1;
    } else {
      write(0, "\nPADRE: FIFO abierto correctamente",
            sizeof("\nPADRE: FIFO abierto correctamente"));
    }
    err = write(fifo_d, "HOLA PROCESO HIJO", sizeof("HOLA PROCESO HIJO"));
    if (err == -1) {
      write(0, "\nPADRE: Error al escribir en FIFO",
            sizeof("\nPADRE: Error al escribir en FIFO"));
    } else {
      write(0, "\nPADRE: Escritos MENSAJE en FIFO",
            sizeof("\nPADRE: Escritos MENSAJE en FIFO"));
    }
    close(fifo_d);
    wait(NULL);
    write(0, "\nSaliendo proceso PADRE\n",
          sizeof("\nSaliendo proceso PADRE\n"));
    break;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
call   1030 <unlink@plt>
lea    0xe4e(%rip),%rdi
mov    $0x1ff,%esi
call   1060 <mkfifo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e1 <main+0x51>
xor    %edi,%edi
lea    0xe3b(%rip),%rsi
mov    $0x28,%edx
call   1040 <write@plt>
jmp    11f4 <main+0x64>
xor    %edi,%edi
lea    0xe4b(%rip),%rsi
mov    $0x1c,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x68(%rbp)
sub    $0xffffffff,%eax
je     121e <main+0x8e>
jmp    120e <main+0x7e>
mov    -0x68(%rbp),%eax
test   %eax,%eax
je     123d <main+0xad>
jmp    1274 <main+0xe4>
xor    %edi,%edi
lea    0xe2a(%rip),%rsi
mov    $0x15,%edx
call   1040 <write@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1354 <main+0x1c4>
xor    %edi,%edi
lea    0xe20(%rip),%rsi
mov    $0x17,%edx
call   1040 <write@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
xor    %edi,%edi
lea    0xe1a(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>
xor    %edi,%edi
lea    0xe18(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
lea    0xd69(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    12ca <main+0x13a>
xor    %edi,%edi
lea    0xdf9(%rip),%rsi
mov    $0x1d,%edx
call   1040 <write@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1354 <main+0x1c4>
xor    %edi,%edi
lea    0xdf7(%rip),%rsi
mov    $0x23,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe06(%rip),%rsi
mov    $0x12,%edx
call   1040 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1316 <main+0x186>
xor    %edi,%edi
lea    0xdf8(%rip),%rsi
mov    $0x22,%edx
call   1040 <write@plt>
jmp    1329 <main+0x199>
xor    %edi,%edi
lea    0xe02(%rip),%rsi
mov    $0x21,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
xor    %edi,%edi
lea    0xdff(%rip),%rsi
mov    $0x19,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe68(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1060 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     11c2 <main+0x32>
lea    0xe7c(%rip),%rsi
xor    %edi,%edi
mov    $0x1c,%edx
jmp    11d0 <main+0x40>
lea    0xe44(%rip),%rsi
xor    %edi,%edi
mov    $0x28,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     1224 <main+0x94>
test   %eax,%eax
je     123e <main+0xae>
lea    0xea9(%rip),%rsi
xor    %edi,%edi
mov    $0x18,%edx
call   1040 <write@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    0xdf8(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    126b <main+0xdb>
lea    0xe92(%rip),%rsi
xor    %edi,%edi
mov    $0x1d,%edx
jmp    1232 <main+0xa2>
lea    0xe26(%rip),%rsi
xor    %edi,%edi
mov    $0x15,%edx
call   1040 <write@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
lea    0xe21(%rip),%rsi
xor    %edi,%edi
mov    $0x17,%edx
call   1040 <write@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
lea    0xe1b(%rip),%rsi
xor    %edi,%edi
mov    $0x18,%edx
jmp    12d3 <main+0x143>
mov    %eax,%ebx
lea    0xe56(%rip),%rsi
xor    %edi,%edi
mov    $0x23,%edx
call   1040 <write@plt>
lea    0xe66(%rip),%rsi
mov    %ebx,%edi
mov    $0x12,%edx
call   1040 <write@plt>
xor    %edx,%edx
cmp    $0xffffffff,%eax
sete   %dl
lea    0xe5d(%rip),%rax
lea    0xe78(%rip),%rsi
cmove  %rax,%rsi
add    $0x21,%edx
xor    %edi,%edi
call   1040 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
lea    0xe76(%rip),%rsi
xor    %edi,%edi
mov    $0x19,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/MI_FIFO\00"
@.str.1 = [40 x i8] c"\0AError al crear FIFO, la FIFO ya existe\00"
@.str.2 = [28 x i8] c"\0AFIFO creado correctamente\0A\00"
@.str.3 = [21 x i8] c"\0AError al crear hijo\00"
@.str.4 = [23 x i8] c"\0AEntrando proceso HIJO\00"
@.str.5 = [24 x i8] c"\0ASaliendo proceso HIJO\0A\00"
@.str.6 = [24 x i8] c"\0AEntrando proceso PADRE\00"
@O_WRONLY = global i32 0
@.str.7 = [29 x i8] c"\0APADRE: Error al abrir FIFO \00"
@.str.8 = [35 x i8] c"\0APADRE: FIFO abierto correctamente\00"
@.str.9 = [18 x i8] c"HOLA PROCESO HIJO\00"
@.str.10 = [34 x i8] c"\0APADRE: Error al escribir en FIFO\00"
@.str.11 = [33 x i8] c"\0APADRE: Escritos MENSAJE en FIFO\00"
@.str.12 = [25 x i8] c"\0ASaliendo proceso PADRE\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [80 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 511)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @write(i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 40)
br label %14
12: ; preds = %0
%13 = call i32 @write(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 28)
br label %14
14: ; preds = %12, %10
%15 = call i32 (...) @fork()
switch i32 %15, label %23 [
i32 -1, label %16
i32 0, label %18
]
16: ; preds = %14
%17 = call i32 @write(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 21)
store i32 -1, i32* %1
br label %49
18: ; preds = %14
%19 = call i32 @write(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 23)
%20 = call i32 @sleep(i32 5)
%21 = call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 24)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %14
%24 = call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 24)
%25 = load i32, i32* @O_WRONLY
%26 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %25, i32 0)
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @write(i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 29)
store i32 -1, i32* %1
br label %49
31: ; preds = %23
%32 = call i32 @write(i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i32 35)
br label %33
33: ; preds = %31
%34 = load i32, i32* %3
%35 = call i32 @write(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i32 18)
store i32 %35, i32* %2
%36 = load i32, i32* %2
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @write(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 34)
br label %42
40: ; preds = %33
%41 = call i32 @write(i32 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i32 33)
br label %42
42: ; preds = %40, %38
%43 = load i32, i32* %3
%44 = call i32 @close(i32 %43)
%45 = call i32 @wait(i32* null)
%46 = call i32 @write(i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 25)
br label %47
47: ; preds = %42
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %29, %16
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/MI_FIFO\00"
@.str.1 = [40 x i8] c"\0AError al crear FIFO, la FIFO ya existe\00"
@.str.2 = [28 x i8] c"\0AFIFO creado correctamente\0A\00"
@.str.3 = [21 x i8] c"\0AError al crear hijo\00"
@.str.4 = [23 x i8] c"\0AEntrando proceso HIJO\00"
@.str.5 = [24 x i8] c"\0ASaliendo proceso HIJO\0A\00"
@.str.6 = [24 x i8] c"\0AEntrando proceso PADRE\00"
@O_WRONLY = global i32 0
@.str.7 = [29 x i8] c"\0APADRE: Error al abrir FIFO \00"
@.str.8 = [35 x i8] c"\0APADRE: FIFO abierto correctamente\00"
@.str.9 = [18 x i8] c"HOLA PROCESO HIJO\00"
@.str.10 = [34 x i8] c"\0APADRE: Error al escribir en FIFO\00"
@.str.11 = [33 x i8] c"\0APADRE: Escritos MENSAJE en FIFO\00"
@.str.12 = [25 x i8] c"\0ASaliendo proceso PADRE\0A\00"
define i32 @main() {
%1 = tail call i32 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 511)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 40)
br label %8
6: ; preds = %0
%7 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 28)
br label %8
8: ; preds = %6, %4
%9 = tail call i32 (...) @fork()
switch i32 %9, label %17 [
i32 -1, label %10
i32 0, label %12
]
10: ; preds = %8
%11 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 21)
br label %35
12: ; preds = %8
%13 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 23)
%14 = tail call i32 @sleep(i32 5)
%15 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 24)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %8
%18 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 24)
%19 = load i32, i32* @O_WRONLY
%20 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %19, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 29)
br label %35
24: ; preds = %17
%25 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i32 35)
%26 = tail call i32 @write(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i32 18)
%27 = icmp eq i32 %26, -1
%28 = select i1 %27, i32 34, i32 33
%29 = select i1 %27, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0)
%30 = tail call i32 @write(i32 0, i8* %29, i32 %28)
%31 = tail call i32 @close(i32 %20)
%32 = tail call i32 @wait(i32* null)
%33 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 25)
%34 = tail call i32 @exit(i32 0)
unreachable
35: ; preds = %22, %10
ret i32 -1
}