#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 /*<<< orphan*/ in;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ unlink(char *);
int main() {
  char *fn = (char *)"temp.fifo";
  char in[20];
  int rfd;
  if ((rfd = open(fn, O_RDONLY)) < 0)
    perror("open() error for read end");
  else {
    if (read(rfd, in, sizeof(in)) == -1)
      perror("read() error");
    else {
      printf("read '%s' from the FIFO\n", in);
      close(rfd);
    }
  }
  unlink(fn);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11a9 <main+0x49>
lea    0xe6b(%rip),%rdi
call   1080 <perror@plt>
jmp    11f1 <main+0x91>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    11d4 <main+0x74>
lea    0xe5a(%rip),%rdi
call   1080 <perror@plt>
jmp    11ec <main+0x8c>
lea    -0x30(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
jmp    11f1 <main+0x91>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11be <main+0x5e>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x14,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     11cc <main+0x6c>
lea    0xe96(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xe4f(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe45(%rip),%rdi
call   1080 <perror@plt>
jmp    11aa <main+0x4a>
lea    0xe51(%rip),%rdi
call   1080 <perror@plt>
jmp    11aa <main+0x4a>

LLVM IR (-O0):
@.str = [10 x i8] c"temp.fifo\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"open() error for read end\00"
@.str.2 = [13 x i8] c"read() error\00"
@.str.3 = [25 x i8] c"read '%s' from the FIFO\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %24
11: ; preds = %0
%12 = load i32, i32* %4
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 20)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %23
18: ; preds = %11
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %4
%22 = call i32 @close(i32 %21)
br label %23
23: ; preds = %18, %16
br label %24
24: ; preds = %23, %9
%25 = load i8*, i8** %2
%26 = call i32 @unlink(i8* %25)
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [10 x i8] c"temp.fifo\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"open() error for read end\00"
@.str.2 = [13 x i8] c"read() error\00"
@.str.3 = [25 x i8] c"read '%s' from the FIFO\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %16
8: ; preds = %0
%9 = call i32 @read(i32 %4, i8* %2, i32 20)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %16
13: ; preds = %8
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%15 = call i32 @close(i32 %4)
br label %16
16: ; preds = %11, %13, %6
%17 = call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
ret i32 0
}