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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fifo_child(char *, char *);
int fifo_parent(char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getpid();
int mkfifo(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid;
  if (argc != 2) {
    fprintf(stderr, "Uso: %s <nome della pipe>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (mkfifo(argv[1], (S_IRUSR | S_IWUSR)) == -1) {
    fprintf(stderr, "[%ld]Err: mkfifo() %s: %s\n", (long)getpid(), argv[1],
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((pid = fork()) == -1) {
    fprintf(stderr, "[%ld]Err: fork(): %s\n", (long)getpid(), strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (pid == 0)
    return fifo_child(argv[1], "\"MESSAGGIO DAL PROCESSO FIGLIO\"\n");
  else
    return fifo_parent(argv[1]);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cc <main+0x4c>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    0x2e04(%rip),%rax
or     (%rax),%esi
call   1060 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    124f <main+0xcf>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    %eax,%r8d
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12ac <main+0x12c>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %eax,%ecx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12d2 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd87(%rip),%rsi
call   1070 <fifo_child@plt>
mov    %eax,-0x4(%rbp)
jmp    12e2 <main+0x162>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <fifo_parent@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11dd <main+0x5d>
mov    0x8(%rbx),%rdi
mov    0x2e29(%rip),%rax
mov    0x2e4a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     11f9 <main+0x79>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11c9 <main+0x49>
cmp    $0xffffffff,%eax
je     123b <main+0xbb>
mov    0x8(%rbx),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fifo_parent@plt>
mov    0x8(%rbx),%rdi
lea    0xe78(%rip),%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <fifo_child@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe10(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1271 <main+0xf1>
mov    0x2dd8(%rip),%rax
mov    (%rax),%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbp
mov    0x8(%rbx),%rbx
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdf5(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1271 <main+0xf1>
mov    0x2d96(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbp
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdd3(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Uso: %s <nome della pipe>\0A\00"
@EXIT_FAILURE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [27 x i8] c"[%ld]Err: mkfifo() %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"[%ld]Err: fork(): %s\0A\00"
@.str.3 = [33 x i8] c"\22MESSAGGIO DAL PROCESSO FIGLIO\22\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @S_IRUSR
%22 = load i32, i32* @S_IWUSR
%23 = or i32 %21, %22
%24 = call i32 @mkfifo(i8* %20, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %37
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = call i64 (...) @getpid()
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %28, i8* %31, i32 %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %17
%38 = call i32 (...) @fork()
store i32 %38, i32* %6
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i64 (...) @getpid()
%43 = load i32, i32* @errno
%44 = call i32 @strerror(i32 %43)
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %42, i32 %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %37
%49 = load i32, i32* %6
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 @fifo_child(i8* %54, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 %55, i32* %3
br label %61
56: ; preds = %48
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 @fifo_parent(i8* %59)
store i32 %60, i32* %3
br label %61
61: ; preds = %56, %51
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Uso: %s <nome della pipe>\0A\00"
@EXIT_FAILURE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [27 x i8] c"[%ld]Err: mkfifo() %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"[%ld]Err: fork(): %s\0A\00"
@.str.3 = [33 x i8] c"\22MESSAGGIO DAL PROCESSO FIGLIO\22\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %14, %13
%16 = tail call i32 @mkfifo(i8* %12, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %27
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = tail call i64 (...) @getpid()
%21 = load i8*, i8** %11
%22 = load i32, i32* @errno
%23 = tail call i32 @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %20, i8* %21, i32 %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %10
%28 = tail call i32 (...) @fork()
switch i32 %28, label %40 [
i32 -1, label %29
i32 0, label %37
]
29: ; preds = %27
%30 = load i32, i32* @stderr
%31 = tail call i64 (...) @getpid()
%32 = load i32, i32* @errno
%33 = tail call i32 @strerror(i32 %32)
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %31, i32 %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %27
%38 = load i8*, i8** %11
%39 = tail call i32 @fifo_child(i8* %38, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %43
40: ; preds = %27
%41 = load i8*, i8** %11
%42 = tail call i32 @fifo_parent(i8* %41)
br label %43
43: ; preds = %40, %37
%44 = phi i32 [ %39, %37 ], [ %42, %40 ]
ret i32 %44
}