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

/* Variables and functions */
int F_OK;
int /*<<< orphan*/ O_RDONLY;
int R_OK;
int W_OK;
scalar_t__ access(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  umask(0);
  mkfifo("myfifo", 0666);
  if (access("myfifo", F_OK | R_OK | W_OK)) {
    perror("myfifo");
    return 1;
  }
  int fd = open("myfifo", O_RDONLY);
  puts(fd == -1 ? "cannot open" : "opend");
  char buf[128];
  for (;;) {
    int n = read(fd, buf, sizeof(buf));
    if (n <= 0)
      break;
    write(1, buf, n);
    write(1, "\n", 1);
    if (n == 4 && strncmp(buf, "quit", 4) == 0)
      break;
  }
  close(fd);
  unlink("myfifo");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   10a0 <umask@plt>
lea    0xe30(%rip),%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    0x2de6(%rip),%rax
or     (%rax),%esi
mov    0x2ded(%rip),%rax
or     (%rax),%esi
lea    0xe04(%rip),%rdi
call   10c0 <access@plt>
cmp    $0x0,%rax
je     1223 <main+0x73>
lea    0xdee(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fb <main+0x14b>
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
lea    0xdcd(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
lea    0xdce(%rip),%rdi
lea    0xdbb(%rip),%rax
cmp    $0xffffffff,%ecx
cmove  %rax,%rdi
call   1050 <puts@plt>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1080 <read@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jg     1284 <main+0xd4>
jmp    12e7 <main+0x137>
lea    -0x90(%rbp),%rsi
mov    -0x94(%rbp),%edx
mov    $0x1,%edi
call   1060 <write@plt>
mov    $0x1,%edx
lea    0xd72(%rip),%rsi
mov    %edx,%edi
call   1060 <write@plt>
cmpl   $0x4,-0x94(%rbp)
jne    12e2 <main+0x132>
lea    -0x90(%rbp),%rdi
lea    0xd52(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12e2 <main+0x132>
jmp    12e7 <main+0x137>
jmp    1258 <main+0xa8>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
lea    0xd0a(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
xor    %edi,%edi
call   10a0 <umask@plt>
lea    0xe33(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
mov    0x2ddf(%rip),%rax
mov    0x2de8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ded(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   10c0 <access@plt>
test   %rax,%rax
jne    12e7 <main+0x137>
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    0xdea(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
lea    0xddf(%rip),%rax
lea    0xde4(%rip),%rdi
cmove  %rax,%rdi
call   1050 <puts@plt>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0x80,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    12c1 <main+0x111>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xdc1(%rip),%r14
lea    0xdbc(%rip),%r15
jmp    1286 <main+0xd6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    12c1 <main+0x111>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <write@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <write@plt>
cmp    $0x4,%ebp
jne    1270 <main+0xc0>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1270 <main+0xc0>
mov    %r12d,%edi
call   1070 <close@plt>
lea    0xd30(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd12(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%eax
jmp    12d7 <main+0x127>

LLVM IR (-O0):
@.str = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@R_OK = global i32 0
@W_OK = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"cannot open\00"
@.str.2 = [6 x i8] c"opend\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @umask(i32 0)
%6 = call i32 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 438)
%7 = load i32, i32* @F_OK
%8 = load i32, i32* @R_OK
%9 = or i32 %7, %8
%10 = load i32, i32* @W_OK
%11 = or i32 %9, %10
%12 = call i64 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %48
16: ; preds = %0
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, -1
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%23 = call i32 @puts(i8* %22)
br label %24
24: ; preds = %43, %16
%25 = load i32, i32* %2
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 128)
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp sle i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
br label %44
31: ; preds = %24
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%33 = load i32, i32* %4
%34 = call i32 @write(i32 1, i8* %32, i32 %33)
%35 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 4
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%40 = call i64 @strncmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
br label %44
43: ; preds = %38, %31
br label %24
44: ; preds = %42, %30
%45 = load i32, i32* %2
%46 = call i32 @close(i32 %45)
%47 = call i32 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %44, %14
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@R_OK = global i32 0
@W_OK = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"cannot open\00"
@.str.2 = [6 x i8] c"opend\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = tail call i32 @umask(i32 0)
%3 = tail call i32 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 438)
%4 = load i32, i32* @F_OK
%5 = load i32, i32* @R_OK
%6 = or i32 %5, %4
%7 = load i32, i32* @W_OK
%8 = or i32 %6, %7
%9 = tail call i64 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %36
13: ; preds = %0
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
%17 = select i1 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%20 = call i32 @read(i32 %15, i8* %19, i32 128)
%21 = icmp slt i32 %20, 1
br i1 %21, label %33, label %22
22: ; preds = %13, %30
%23 = phi i32 [ %31, %30 ], [ %20, %13 ]
%24 = call i32 @write(i32 1, i8* %19, i32 %23)
%25 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%26 = icmp eq i32 %23, 4
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %22, %27
%31 = call i32 @read(i32 %15, i8* %19, i32 128)
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %22
33: ; preds = %27, %30, %13
%34 = call i32 @close(i32 %15)
%35 = call i32 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %33, %11
%37 = phi i32 [ 1, %11 ], [ 0, %33 ]
ret i32 %37
}