#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 */
scalar_t__ EEXIST;
int EXIT_FAILURE;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ O_RDONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[1024];
  int real_read;
  int fd;
  if (access("myfifo", F_OK) == -1) {
    if ((mkfifo("myfifo", 0666) < 0) && (errno != EEXIST)) {
      perror("mkfifo");
      exit(EXIT_FAILURE);
    }
  }
  if ((fd = open("myfifo", O_RDONLY)) == -1) {
    perror("open");
    exit(1);
  }
  while (1) {
    memset(buffer, 0, 1024);
    if ((real_read = read(fd, buffer, 1024)) > 0) {
      printf("Read from pipe: '%s'.\n", buffer);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    120b <main+0x8b>
lea    0xe42(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <mkfifo@plt>
cmp    $0x0,%rax
jge    1206 <main+0x86>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%rax
je     1206 <main+0x86>
lea    0xe14(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    120b <main+0x8b>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xde5(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x418(%rbp)
cmp    $0xffffffff,%eax
jne    1245 <main+0xc5>
lea    0xdd8(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    124a <main+0xca>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jle    1296 <main+0x116>
lea    -0x410(%rbp),%rsi
lea    0xd82(%rip),%rdi
call   1030 <printf@plt>
jmp    124a <main+0xca>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    11d1 <main+0x51>
lea    0xe54(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <mkfifo@plt>
test   %rax,%rax
jns    11d1 <main+0x51>
mov    0x2e0e(%rip),%rax
mov    (%rax),%rax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%rax
jne    1245 <main+0xc5>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe1f(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     122f <main+0xaf>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xe1c(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1200 <main+0x80>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
jmp    1200 <main+0x80>
lea    0xdd8(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdbb(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [7 x i8] c"mkfifo\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [23 x i8] c"Read from pipe: '%s'.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @F_OK
%10 = call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %24
12: ; preds = %2
%13 = call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 438)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i64, i64* @errno
%17 = load i64, i64* @EEXIST
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %15, %12
br label %24
24: ; preds = %23, %2
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 %26, i32* %8
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24
br label %32
32: ; preds = %31, %42
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 1024)
%35 = load i32, i32* %8
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%37 = call i32 @read(i32 %35, i8* %36, i32 1024)
store i32 %37, i32* %7
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %32
br label %32
}

LLVM IR (-O2):
@.str = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [7 x i8] c"mkfifo\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [23 x i8] c"Read from pipe: '%s'.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @F_OK
%6 = tail call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = tail call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 438)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i64, i64* @errno
%13 = load i64, i64* @EEXIST
%14 = icmp eq i64 %12, %13
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %8, %11, %2
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %19, %32
%27 = call i32 @memset(i8* %4, i32 0, i32 1024)
%28 = call i32 @read(i32 %21, i8* %4, i32 1024)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %32
32: ; preds = %30, %26
br label %26
}