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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stdout;
scalar_t__ unlink(char *);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  char message[] = "Hello World on a FIFO";
  int fd;
  pid_t pid;
  if (mkfifo("/tmp/myfifo", 0666) < 0) {
    perror("/tmp/myfifo");
    exit(errno);
  };
  printf("FIFO created: %s\n", "/tmp/myfifo");
  fflush(stdout);
  pid = fork();
  if (pid == 0) {
    fd = open("/tmp/myfifo", O_WRONLY);
    printf("The child is sending: %s ***\n", message);
    if (write(fd, message, sizeof(message)) < 0) {
      perror("write error from child to fifo");
      exit(errno);
    };
    close(fd);
    exit(EXIT_SUCCESS);
  }
  if (pid > 0) {
    fd = open("/tmp/myfifo", O_RDONLY);
    if (read(fd, message, sizeof(message)) < 0) {
      perror("read error in parent from fifo");
      exit(errno);
    };
    printf("The parent received: %s ***\n", message);
    close(fd);
    if (unlink("/tmp/myfifo")) {
      perror("Had trouble removing fifo");
      exit(errno);
    };
    exit(EXIT_SUCCESS);
  }
  {
    perror("fork");
    exit(errno);
  };
}


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)
mov    0xe33(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe30(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe2e(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe28(%rip),%ax
mov    %ax,-0x1c(%rbp)
lea    0xe1f(%rip),%rdi
mov    $0x1b6,%esi
call   1080 <mkfifo@plt>
cmp    $0x0,%rax
jge    1225 <main+0x75>
lea    0xe04(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xdf6(%rip),%rdi
lea    0xde3(%rip),%rsi
call   1050 <printf@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12cf <main+0x11f>
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
lea    0xdaa(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xdb5(%rip),%rdi
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x16,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    12b9 <main+0x109>
lea    0xdac(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
jle    137d <main+0x1cd>
mov    0x2d07(%rip),%rax
mov    (%rax),%esi
lea    0xd2c(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x16,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jge    1327 <main+0x177>
lea    0xd5d(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x30(%rbp),%rsi
lea    0xd5e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
lea    0xcd0(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     136f <main+0x1bf>
lea    0xd51(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xd43(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xe42(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x4f464946206120,%rax
mov    %rax,0xe(%rsp)
lea    0xe3e(%rip),%rdi
mov    $0x1b6,%esi
call   1080 <mkfifo@plt>
test   %rax,%rax
jns    1201 <main+0x51>
lea    0xe28(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xe1a(%rip),%rdi
lea    0xe07(%rip),%rsi
call   1050 <printf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
jne    1277 <main+0xc7>
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
lea    0xdd8(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
lea    0xde8(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x16,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    12b0 <main+0x100>
lea    0xde0(%rip),%rdi
jmp    11ee <main+0x3e>
jle    12c5 <main+0x115>
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
lea    0xd8d(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x16,%edx
call   1070 <read@plt>
test   %rax,%rax
jns    12d1 <main+0x121>
lea    0xdc6(%rip),%rdi
jmp    11ee <main+0x3e>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xdfb(%rip),%rdi
jmp    11ee <main+0x3e>
lea    0xdb8(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xd28(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     12b7 <main+0x107>
lea    0xdae(%rip),%rdi
jmp    11ee <main+0x3e>

LLVM IR (-O0):
@__const.main.message = [22 x i8] c"Hello World on a FIFO\00"
@.str = [12 x i8] c"/tmp/myfifo\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"FIFO created: %s\0A\00"
@stdout = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [30 x i8] c"The child is sending: %s ***\0A\00"
@.str.3 = [31 x i8] c"write error from child to fifo\00"
@EXIT_SUCCESS = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [31 x i8] c"read error in parent from fifo\00"
@.str.5 = [29 x i8] c"The parent received: %s ***\0A\00"
@.str.6 = [26 x i8] c"Had trouble removing fifo\00"
@.str.7 = [5 x i8] c"fork\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [22 x i8]
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [22 x i8]* %6 to i8*
%10 = call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 438)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @errno
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stdout
%19 = call i32 @fflush(i32 %18)
%20 = call i64 (...) @fork()
store i64 %20, i64* %8
%21 = load i64, i64* %8
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %41
23: ; preds = %16
%24 = load i32, i32* @O_WRONLY
%25 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %24)
store i32 %25, i32* %7
%26 = getelementptr inbounds [22 x i8], [22 x i8]* %6, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %7
%29 = getelementptr inbounds [22 x i8], [22 x i8]* %6, i64 0, i64 0
%30 = call i64 @write(i32 %28, i8* %29, i32 22)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %23
%33 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @errno
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %23
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* @EXIT_SUCCESS
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %16
%42 = load i64, i64* %8
%43 = icmp sgt i64 %42, 0
br i1 %43, label %44, label %69
44: ; preds = %41
%45 = load i32, i32* @O_RDONLY
%46 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %45)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = getelementptr inbounds [22 x i8], [22 x i8]* %6, i64 0, i64 0
%49 = call i64 @read(i32 %47, i8* %48, i32 22)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %44
%52 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* @errno
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %44
%56 = getelementptr inbounds [22 x i8], [22 x i8]* %6, i64 0, i64 0
%57 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = load i32, i32* %7
%59 = call i32 @close(i32 %58)
%60 = call i64 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%64 = load i32, i32* @errno
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %55
%67 = load i32, i32* @EXIT_SUCCESS
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %41
%70 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%71 = load i32, i32* @errno
%72 = call i32 @exit(i32 %71)
unreachable
}

LLVM IR (-O2):
@__const.main.message = [22 x i8] c"Hello World on a FIFO\00"
@.str = [12 x i8] c"/tmp/myfifo\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"FIFO created: %s\0A\00"
@stdout = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [30 x i8] c"The child is sending: %s ***\0A\00"
@.str.3 = [31 x i8] c"write error from child to fifo\00"
@EXIT_SUCCESS = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [31 x i8] c"read error in parent from fifo\00"
@.str.5 = [29 x i8] c"The parent received: %s ***\0A\00"
@.str.6 = [26 x i8] c"Had trouble removing fifo\00"
@.str.7 = [5 x i8] c"fork\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [22 x i8]
%4 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 438)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @errno
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = tail call i32 @fflush(i32 %13)
%15 = tail call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %11
%18 = load i32, i32* @O_WRONLY
%19 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%21 = call i64 @write(i32 %19, i8* %4, i32 22)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* @errno
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %17
%28 = call i32 @close(i32 %19)
%29 = load i32, i32* @EXIT_SUCCESS
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %11
%32 = icmp sgt i64 %15, 0
br i1 %32, label %33, label %54
33: ; preds = %31
%34 = load i32, i32* @O_RDONLY
%35 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = call i64 @read(i32 %35, i8* %4, i32 22)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* @errno
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %33
%43 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%44 = call i32 @close(i32 %35)
%45 = call i64 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %42
%48 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%49 = load i32, i32* @errno
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %42
%52 = load i32, i32* @EXIT_SUCCESS
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %31
%55 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%56 = load i32, i32* @errno
%57 = tail call i32 @exit(i32 %56)
unreachable
}