#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
scalar_t__ pipe(int *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int n, fd[2];
  pid_t pid;
  char buffer[1024];
  if (pipe(fd) < 0) {
    fprintf(stderr, "Err.: %d pipe() - %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Err.: %d fork() - %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  } else if (pid > 0) {
    close(fd[0]);
    write(fd[1], "IPC - messaggio inviato mediante pipe\n", 38);
  } else {
    close(fd[1]);
    if ((n = read(fd[0], buffer, 1024)) < 0) {
      fprintf(stderr, "Err.: %d read() - %s\n", errno, strerror(errno));
      exit(EXIT_FAILURE);
    }
    if (write(STDOUT_FILENO, buffer, n) < 0) {
      fprintf(stderr, "Err.: %d write() - %s\n", errno, strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
jge    1201 <main+0x81>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x438(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x434(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x438(%rbp),%edi
mov    -0x434(%rbp),%edx
mov    %rax,%rcx
lea    0xe12(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    126b <main+0xeb>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x440(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x43c(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x440(%rbp),%edi
mov    -0x43c(%rbp),%edx
mov    %rax,%rcx
lea    0xdbe(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jle    1297 <main+0x117>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
lea    0xda4(%rip),%rsi
mov    $0x26,%edx
call   1030 <write@plt>
jmp    1390 <main+0x210>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1314 <main+0x194>
mov    0x2d12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x448(%rbp)
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x444(%rbp)
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x448(%rbp),%edi
mov    -0x444(%rbp),%edx
mov    %rax,%rcx
lea    0xd52(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    138b <main+0x20b>
mov    0x2c9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x450(%rbp)
mov    0x2c84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44c(%rbp)
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x450(%rbp),%edi
mov    -0x44c(%rbp),%edx
mov    %rax,%rcx
lea    0xcf1(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1390 <main+0x210>
jmp    1395 <main+0x215>
mov    0x2c24(%rip),%rax
mov    (%rax),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
test   %rax,%rax
js     1217 <main+0x97>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1239 <main+0xb9>
je     11ca <main+0x4a>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
lea    0xe6e(%rip),%rsi
mov    $0x26,%edx
call   1030 <write@plt>
jmp    1204 <main+0x84>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
js     125b <main+0xdb>
mov    0x2dff(%rip),%rcx
mov    (%rcx),%edi
lea    0x10(%rsp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     127d <main+0xfd>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
add    $0x418,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dba(%rip),%rax
mov    (%rax),%ebx
mov    0x2da9(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdc9(%rip),%rsi
jmp    129d <main+0x11d>
mov    0x2d98(%rip),%rax
mov    (%rax),%ebx
mov    0x2d87(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdbd(%rip),%rsi
jmp    129d <main+0x11d>
mov    0x2d76(%rip),%rax
mov    (%rax),%ebx
mov    0x2d65(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdd8(%rip),%rsi
jmp    129d <main+0x11d>
mov    0x2d54(%rip),%rax
mov    (%rax),%ebx
mov    0x2d43(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdcc(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Err.: %d pipe() - %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Err.: %d fork() - %s\0A\00"
@.str.2 = [39 x i8] c"IPC - messaggio inviato mediante pipe\0A\00"
@.str.3 = [22 x i8] c"Err.: %d read() - %s\0A\00"
@STDOUT_FILENO = global i32 0
@.str.4 = [23 x i8] c"Err.: %d write() - %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i64
%9 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%11 = call i64 @pipe(i32* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = call i64 (...) @fork()
store i64 %22, i64* %8
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %26, i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %21
%33 = load i64, i64* %8
%34 = icmp sgt i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i64 @write(i32 %40, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 38)
br label %74
42: ; preds = %32
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%44 = load i32, i32* %43
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%47 = load i32, i32* %46
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 1024)
store i32 %49, i32* %6
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %59
51: ; preds = %42
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %53, i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %42
%60 = load i32, i32* @STDOUT_FILENO
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%62 = load i32, i32* %6
%63 = call i64 @write(i32 %60, i8* %61, i32 %62)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %73
65: ; preds = %59
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %67, i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %59
br label %74
74: ; preds = %73, %35
br label %75
75: ; preds = %74
%76 = load i32, i32* @EXIT_SUCCESS
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Err.: %d pipe() - %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Err.: %d fork() - %s\0A\00"
@.str.2 = [39 x i8] c"IPC - messaggio inviato mediante pipe\0A\00"
@.str.3 = [22 x i8] c"Err.: %d read() - %s\0A\00"
@STDOUT_FILENO = global i32 0
@.str.4 = [23 x i8] c"Err.: %d write() - %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [1024 x i8]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = call i64 (...) @fork()
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %17
%28 = icmp eq i64 %18, 0
br i1 %28, label %35, label %29
29: ; preds = %27
%30 = load i32, i32* %7
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i64 @write(i32 %33, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 38)
br label %60
35: ; preds = %27
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* %7
%40 = call i32 @read(i32 %39, i8* %6, i32 1024)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %44, i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %35
%50 = load i32, i32* @STDOUT_FILENO
%51 = call i64 @write(i32 %50, i8* %6, i32 %40)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %55, i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %29, %49
%61 = load i32, i32* @EXIT_SUCCESS
ret i32 %61
}