#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_WRONLY;
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 snprintf(char *, int, char *, long, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char *);
int write(int, char *, int);
int fifo_child(const char *fifo_name, const char *id_str) {
  char buf[256];
  int fd, rval;
  ssize_t str_size;
  fprintf(stderr, "[%ld]: (processo figlio) apertura FIFO %s...\n",
          (long)getpid(), fifo_name);
  while ((fd = open(fifo_name, O_WRONLY)) == -1) {
    fprintf(stderr, "[%ld]Err: open() FIFO scrittura %s: %s\n", (long)getpid(),
            fifo_name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  rval = snprintf(buf, 256, "[%ld]:%s\n", (long)getpid(), id_str);
  if (rval < 0) {
    fprintf(stderr, "[%ld ]Err: scrittura stringa\n", (long)getpid());
    exit(EXIT_FAILURE);
  }
  str_size = strlen(buf) + 1;
  fprintf(stderr, "[%ld]: scrittura...\n", (long)getpid());
  if ((rval = write(fd, buf, str_size)) != str_size) {
    fprintf(stderr, "[%ld]Err: scrittura pipe\n", (long)getpid());
    exit(EXIT_FAILURE);
  }
  fprintf(stderr, "[%ld]: conclusione...\n", (long)getpid());
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<fifo_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x120(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x120(%rbp),%edi
mov    %rax,%rdx
mov    -0x8(%rbp),%rcx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x114(%rbp)
cmp    $0xffffffff,%eax
jne    124e <fifo_child+0xce>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x130(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x134(%rbp),%edi
mov    -0x130(%rbp),%rdx
mov    -0x128(%rbp),%rcx
mov    %eax,%r8d
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x140(%rbp),%rdi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xdd9(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0x0,-0x118(%rbp)
jge    12d0 <fifo_child+0x150>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x144(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x144(%rbp),%edi
mov    %rax,%rdx
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x11c(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x148(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x148(%rbp),%edi
mov    %rax,%rdx
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x11c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x118(%rbp)
cmp    -0x11c(%rbp),%eax
je     1377 <fifo_child+0x1f7>
mov    0x2c9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x14c(%rbp),%edi
mov    %rax,%rdx
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2c62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x150(%rbp),%edi
mov    %rax,%rdx
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c1d(%rip),%rax
mov    (%rax),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fifo_child>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e44(%rip),%r12
mov    (%r12),%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe52(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     127c <fifo_child+0xfc>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6e(%rip),%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
test   %eax,%eax
js     12b4 <fifo_child+0x134>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
add    $0x1,%ebx
mov    (%r12),%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe59(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    (%r12),%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
cmp    %ebx,%ebp
jne    12ca <fifo_child+0x14a>
lea    0xe57(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbp
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd8f(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12de <fifo_child+0x15e>
mov    (%r12),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd9a(%rip),%rsi
mov    %ebx,%edi
jmp    12d4 <fifo_child+0x154>
lea    0xdc2(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"[%ld]: (processo figlio) apertura FIFO %s...\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [40 x i8] c"[%ld]Err: open() FIFO scrittura %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [10 x i8] c"[%ld]:%s\0A\00"
@.str.3 = [30 x i8] c"[%ld ]Err: scrittura stringa\0A\00"
@.str.4 = [21 x i8] c"[%ld]: scrittura...\0A\00"
@.str.5 = [26 x i8] c"[%ld]Err: scrittura pipe\0A\00"
@.str.6 = [23 x i8] c"[%ld]: conclusione...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @fifo_child(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i32, i32* @stderr
%10 = call i64 (...) @getpid()
%11 = load i8*, i8** %3
%12 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %10, i8* %11)
br label %13
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i64 (...) @getpid()
%21 = load i8*, i8** %3
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %20, i8* %21, i32 %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %13
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = call i64 (...) @getpid()
%30 = load i8*, i8** %4
%31 = call i32 @snprintf(i8* %28, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %29, i8* %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = call i64 (...) @getpid()
%37 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %27
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
%44 = load i32, i32* @stderr
%45 = call i64 (...) @getpid()
%46 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %45)
%47 = load i32, i32* %6
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%49 = load i32, i32* %8
%50 = call i32 @write(i32 %47, i8* %48, i32 %49)
store i32 %50, i32* %7
%51 = load i32, i32* %8
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %59
53: ; preds = %40
%54 = load i32, i32* @stderr
%55 = call i64 (...) @getpid()
%56 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i64 %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %40
%60 = load i32, i32* @stderr
%61 = call i64 (...) @getpid()
%62 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i64 %61)
%63 = load i32, i32* @EXIT_SUCCESS
ret i32 %63
}

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