#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 */
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int /*<<< orphan*/, 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);
    fifo_d = open("/tmp/MI_FIFO", O_RDONLY, 0);
    if (fifo_d == -1) {
      write(0, "\nHIJO: Error al abrir FIFO ",
            sizeof("\nHIJO: Error al abrir FIFO "));
      return -1;
    } else {
      write(0, "\nHIJO: FIFO abierto correctamente",
            sizeof("\nHIJO: FIFO abierto correctamente"));
    }
    leido = read(fifo_d, buff, sizeof(buff));
    if (leido == -1) {
      write(0, "\nHIJO: Error al leer en FIFO",
            sizeof("\nHIJO: Error al leer en FIFO"));
    } else {
      write(0, "\nHIJO: Leido del FIFO: ", sizeof("\nHIJO: Leido del FIFO: "));
      write(0, buff, leido - 1);
      write(0, "\n", sizeof("\n"));
    }
    close(fifo_d);
    write(0, "\nSaliendo proceso HIJO\n", sizeof("\nSaliendo proceso HIJO\n"));
    exit(0);
    break;
  default:
    write(0, "\nEntrando proceso PADRE", sizeof("\nEntrando proceso PADRE"));
    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    0xe4a(%rip),%rdi
call   1030 <unlink@plt>
lea    0xe3e(%rip),%rdi
mov    $0x1ff,%esi
call   1070 <mkfifo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11f1 <main+0x51>
xor    %edi,%edi
lea    0xe2b(%rip),%rsi
mov    $0x28,%edx
call   1040 <write@plt>
jmp    1204 <main+0x64>
xor    %edi,%edi
lea    0xe3b(%rip),%rsi
mov    $0x1c,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x68(%rbp)
sub    $0xffffffff,%eax
je     122e <main+0x8e>
jmp    121e <main+0x7e>
mov    -0x68(%rbp),%eax
test   %eax,%eax
je     124d <main+0xad>
jmp    134f <main+0x1af>
xor    %edi,%edi
lea    0xe1a(%rip),%rsi
mov    $0x15,%edx
call   1040 <write@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1385 <main+0x1e5>
xor    %edi,%edi
lea    0xe10(%rip),%rsi
mov    $0x17,%edx
call   1040 <write@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
lea    0xd86(%rip),%rdi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    12ad <main+0x10d>
xor    %edi,%edi
lea    0xde6(%rip),%rsi
mov    $0x1c,%edx
call   1040 <write@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1385 <main+0x1e5>
xor    %edi,%edi
lea    0xde3(%rip),%rsi
mov    $0x22,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1060 <read@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    12f6 <main+0x156>
xor    %edi,%edi
lea    0xdd4(%rip),%rsi
mov    $0x1d,%edx
call   1040 <write@plt>
jmp    132d <main+0x18d>
xor    %edi,%edi
lea    0xdd9(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
sub    $0x1,%edx
xor    %edi,%edi
call   1040 <write@plt>
xor    %edi,%edi
lea    0xe14(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
lea    0xdb2(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1090 <exit@plt>
xor    %edi,%edi
lea    0xdb0(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <wait@plt>
xor    %edi,%edi
lea    0xdac(%rip),%rsi
mov    $0x19,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
lea    0xe53(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1070 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     11d7 <main+0x37>
lea    0xe67(%rip),%rsi
xor    %edi,%edi
mov    $0x1c,%edx
jmp    11e5 <main+0x45>
lea    0xe2f(%rip),%rsi
xor    %edi,%edi
mov    $0x28,%edx
call   1040 <write@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     120a <main+0x6a>
cmp    $0xffffffff,%eax
jne    1262 <main+0xc2>
lea    0xe50(%rip),%rsi
xor    %edi,%edi
mov    $0x15,%edx
jmp    1251 <main+0xb1>
lea    0xe55(%rip),%rsi
xor    %edi,%edi
mov    $0x17,%edx
call   1040 <write@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
lea    0xdc9(%rip),%rdi
xor    %edx,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    128f <main+0xef>
lea    0xe33(%rip),%rsi
xor    %edi,%edi
mov    $0x1c,%edx
call   1040 <write@plt>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe9f(%rip),%rsi
xor    %edi,%edi
mov    $0x18,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
lea    0xe9d(%rip),%rsi
xor    %edi,%edi
mov    $0x19,%edx
jmp    1312 <main+0x172>
mov    %eax,%ebx
lea    0xe01(%rip),%rsi
xor    %edi,%edi
mov    $0x22,%edx
call   1040 <write@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x50,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    12c6 <main+0x126>
lea    0xdfc(%rip),%rsi
mov    $0x1d,%edx
jmp    12f6 <main+0x156>
mov    %eax,%ebp
lea    0xe09(%rip),%rsi
xor    %edi,%edi
mov    $0x18,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebp
mov    %rsp,%rsi
xor    %edi,%edi
mov    %ebp,%edx
call   1040 <write@plt>
lea    0xe46(%rip),%rsi
mov    $0x2,%edx
xor    %edi,%edi
call   1040 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xde5(%rip),%rsi
xor    %edi,%edi
mov    $0x18,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1090 <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"
@O_RDONLY = global i32 0
@.str.5 = [28 x i8] c"\0AHIJO: Error al abrir FIFO \00"
@.str.6 = [34 x i8] c"\0AHIJO: FIFO abierto correctamente\00"
@.str.7 = [29 x i8] c"\0AHIJO: Error al leer en FIFO\00"
@.str.8 = [24 x i8] c"\0AHIJO: Leido del FIFO: \00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [24 x i8] c"\0ASaliendo proceso HIJO\0A\00"
@.str.11 = [24 x i8] c"\0AEntrando proceso PADRE\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 %49 [
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 %55
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 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %21, i32 0)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @write(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 28)
store i32 -1, i32* %1
br label %55
27: ; preds = %18
%28 = call i32 @write(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 34)
br label %29
29: ; preds = %27
%30 = load i32, i32* %3
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 80)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @write(i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 29)
br label %44
37: ; preds = %29
%38 = call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 24)
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%40 = load i32, i32* %5
%41 = sub nsw i32 %40, 1
%42 = call i32 @write(i32 0, i8* %39, i32 %41)
%43 = call i32 @write(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 2)
br label %44
44: ; preds = %37, %35
%45 = load i32, i32* %3
%46 = call i32 @close(i32 %45)
%47 = call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i32 24)
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %14
%50 = call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i32 24)
%51 = call i32 @wait(i32* null)
%52 = call i32 @write(i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 25)
br label %53
53: ; preds = %49
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %25, %16
%56 = load i32, i32* %1
ret i32 %56
}

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"
@O_RDONLY = global i32 0
@.str.5 = [28 x i8] c"\0AHIJO: Error al abrir FIFO \00"
@.str.6 = [34 x i8] c"\0AHIJO: FIFO abierto correctamente\00"
@.str.7 = [29 x i8] c"\0AHIJO: Error al leer en FIFO\00"
@.str.8 = [24 x i8] c"\0AHIJO: Leido del FIFO: \00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [24 x i8] c"\0ASaliendo proceso HIJO\0A\00"
@.str.11 = [24 x i8] c"\0AEntrando proceso PADRE\00"
@.str.12 = [25 x i8] c"\0ASaliendo proceso PADRE\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @unlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 511)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = 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 %10
8: ; preds = %0
%9 = 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 %10
10: ; preds = %8, %6
%11 = tail call i32 (...) @fork()
switch i32 %11, label %37 [
i32 -1, label %12
i32 0, label %14
]
12: ; preds = %10
%13 = 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 %42
14: ; preds = %10
%15 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 23)
%16 = tail call i32 @sleep(i32 5)
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %17, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 28)
br label %42
22: ; preds = %14
%23 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 34)
%24 = call i32 @read(i32 %18, i8* %2, i32 80)
%25 = icmp eq i32 %24, -1
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 24)
%28 = add nsw i32 %24, -1
%29 = call i32 @write(i32 0, i8* %2, i32 %28)
br label %30
30: ; preds = %22, %26
%31 = phi i32 [ 2, %26 ], [ 29, %22 ]
%32 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), %26 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), %22 ]
%33 = tail call i32 @write(i32 0, i8* %32, i32 %31)
%34 = tail call i32 @close(i32 %18)
%35 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i32 24)
%36 = tail call i32 @exit(i32 0)
unreachable
37: ; preds = %10
%38 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i32 24)
%39 = tail call i32 @wait(i32* null)
%40 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 25)
%41 = tail call i32 @exit(i32 0)
unreachable
42: ; preds = %20, %12
ret i32 -1
}