#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ R_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
int main() {
  int fd;
  char *myfifo = "/tmp/myfifo";
  char buf[1024];
  if (access(myfifo, R_OK) == -1) {
    fprintf(stderr, "%s does not exist or is not readable.\n", myfifo);
    return 1;
  }
  while (1) {
    fd = open(myfifo, O_RDONLY);
    memset(buf, 0, 1024);
    read(fd, buf, 1024);
    printf("Received: %s", buf);
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
jne    11cf <main+0x5f>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x410,%rsp
pop    %rbp
ret
jmp    11d4 <main+0x64>
mov    -0x10(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    -0x410(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
jmp    11d4 <main+0x64>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
je     1200 <main+0x90>
mov    0x2e48(%rip),%r12
lea    0xe59(%rip),%r14
mov    %rsp,%rbx
lea    0xe82(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12),%esi
mov    %r14,%rdi
call   1080 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11c0 <main+0x50>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
lea    0xde9(%rip),%rdx
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/myfifo\00"
@R_OK = global i32 0
@stderr = global i32 0
@.str.1 = [39 x i8] c"%s does not exist or is not readable.\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"Received: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @R_OK
%7 = call i32 @access(i8* %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %11)
ret i32 1
13: ; preds = %0
br label %14
14: ; preds = %13, %14
%15 = load i8*, i8** %3
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 1024)
%20 = load i32, i32* %2
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = call i32 @read(i32 %20, i8* %21, i32 1024)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
br label %14
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/myfifo\00"
@R_OK = global i32 0
@stderr = global i32 0
@.str.1 = [39 x i8] c"%s does not exist or is not readable.\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"Received: %s\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @R_OK
%4 = tail call i32 @access(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
ret i32 1
9: ; preds = %0, %9
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @memset(i8* %2, i32 0, i32 1024)
%13 = call i32 @read(i32 %11, i8* %2, i32 1024)
%14 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%15 = call i32 @close(i32 %11)
br label %9
}