#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_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long, ...);
scalar_t__ getpid();
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int fifo_parent(const char *fifo_name) {
  char buf[256];
  int fd, rval;
  fprintf(stderr, "[%ld]: (processo padre) apertura FIFO %s...\n",
          (long)getpid(), fifo_name);
  while ((fd = open(fifo_name, O_RDONLY)) == -1) {
    fprintf(stderr, "[%ld]Err: open() FIFO lettura %s: %s\n", (long)getpid(),
            fifo_name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  fprintf(stderr, "[%ld]: lettura...\n", (long)getpid());
  if ((rval = read(fd, buf, 256)) == -1) {
    fprintf(stderr, "[%ld ]Err: lettura dalla pipe\n", (long)getpid());
    exit(EXIT_FAILURE);
  }
  fprintf(stderr, "[%ld]: lettura %.*s\n", (long)getpid(), rval, buf);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<fifo_parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x11c(%rbp),%edi
mov    %rax,%rdx
mov    -0x8(%rbp),%rcx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x114(%rbp)
cmp    $0xffffffff,%eax
jne    122a <fifo_parent+0xca>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x130(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x134(%rbp),%edi
mov    -0x130(%rbp),%rdx
mov    -0x128(%rbp),%rcx
mov    %eax,%r8d
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x138(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x138(%rbp),%edi
mov    %rax,%rdx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,-0x118(%rbp)
cmp    $0xffffffff,%eax
jne    12b8 <fifo_parent+0x158>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x13c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x13c(%rbp),%edi
mov    %rax,%rdx
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x140(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x140(%rbp),%edi
mov    %rax,%rdx
mov    -0x118(%rbp),%ecx
lea    -0x110(%rbp),%r8
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fifo_parent>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
mov    0x2e5f(%rip),%r12
mov    (%r12),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe75(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    (%r12),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%r15
cmp    $0xffffffff,%ebp
je     1226 <fifo_parent+0xc6>
lea    0xe8c(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    (%r12),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    $0xffffffff,%ebp
je     1250 <fifo_parent+0xf0>
lea    0xe89(%rip),%rsi
mov    %rsp,%r8
mov    %ebx,%edi
mov    %rax,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdf2(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1263 <fifo_parent+0x103>
lea    0xe0f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"[%ld]: (processo padre) apertura FIFO %s...\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"[%ld]Err: open() FIFO lettura %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [19 x i8] c"[%ld]: lettura...\0A\00"
@.str.3 = [31 x i8] c"[%ld ]Err: lettura dalla pipe\0A\00"
@.str.4 = [21 x i8] c"[%ld]: lettura %.*s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @fifo_parent(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i32, i32* @stderr
%7 = call i64 (...) @getpid()
%8 = load i8*, i8** %2
%9 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i64 %7, i8* %8)
br label %10
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i64 (...) @getpid()
%18 = load i8*, i8** %2
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %17, i8* %18, i32 %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %10
%25 = load i32, i32* @stderr
%26 = call i64 (...) @getpid()
%27 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = load i32, i32* %4
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 256)
store i32 %30, i32* %5
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %24
%33 = load i32, i32* @stderr
%34 = call i64 (...) @getpid()
%35 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %24
%39 = load i32, i32* @stderr
%40 = call i64 (...) @getpid()
%41 = load i32, i32* %5
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%43 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %40, i32 %41, i8* %42)
%44 = load i32, i32* @EXIT_SUCCESS
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"[%ld]: (processo padre) apertura FIFO %s...\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"[%ld]Err: open() FIFO lettura %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [19 x i8] c"[%ld]: lettura...\0A\00"
@.str.3 = [31 x i8] c"[%ld ]Err: lettura dalla pipe\0A\00"
@.str.4 = [21 x i8] c"[%ld]: lettura %.*s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @fifo_parent(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @stderr
%5 = tail call i64 (...) @getpid()
%6 = tail call i32 (i32, i8*, i64, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i64 %5, i8* %0)
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
%10 = load i32, i32* @stderr
%11 = tail call i64 (...) @getpid()
br i1 %9, label %12, label %18
12: ; preds = %1
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 (i32, i8*, i64, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %11, i8* %0, i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
%19 = tail call i32 (i32, i8*, i64, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %11)
%20 = call i32 @read(i32 %8, i8* %3, i32 256)
%21 = icmp eq i32 %20, -1
%22 = load i32, i32* @stderr
%23 = tail call i64 (...) @getpid()
br i1 %21, label %24, label %28
24: ; preds = %18
%25 = tail call i32 (i32, i8*, i64, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %23)
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %18
%29 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %23, i32 %20, i8* %3)
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
}