#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 F_OK;
int /*<<< orphan*/ O_WRONLY;
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*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
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_WRONLY);
  puts(fd == -1 ? "cannot open" : "opened");
  char buf[128];
  for (;;) {
    printf("input:");
    scanf(" %[^\n]", buf);
    write(fd, buf, strlen(buf));
    if (!strcmp(buf, "quit"))
      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   10b0 <umask@plt>
lea    0xe10(%rip),%rdi
mov    $0x1b6,%esi
call   10a0 <mkfifo@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
mov    0x2dce(%rip),%rax
or     (%rax),%esi
mov    0x2dd5(%rip),%rax
or     (%rax),%esi
lea    0xde4(%rip),%rdi
call   10e0 <access@plt>
cmp    $0x0,%rax
je     1243 <main+0x73>
lea    0xdce(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1308 <main+0x138>
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
lea    0xdad(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
lea    0xdae(%rip),%rdi
lea    0xd9b(%rip),%rax
cmp    $0xffffffff,%ecx
cmove  %rax,%rdi
call   1040 <puts@plt>
lea    0xd9b(%rip),%rdi
call   1070 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xd8f(%rip),%rdi
call   10c0 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    -0x90(%rbp),%rdi
lea    0xd4c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    12ef <main+0x11f>
jmp    12f4 <main+0x124>
jmp    1278 <main+0xa8>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
lea    0xcfd(%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    0xe23(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1090 <mkfifo@plt>
mov    0x2dcf(%rip),%rax
mov    0x2de0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2de5(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   10d0 <access@plt>
test   %rax,%rax
jne    12bb <main+0xfb>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    0xdda(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
lea    0xdd0(%rip),%rax
lea    0xdd5(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
lea    0xdcc(%rip),%r14
lea    0xdcc(%rip),%r15
mov    %rsp,%rbx
mov    $0x74697571,%r12d
xchg   %ax,%ax
mov    %r14,%rdi
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    (%rsp),%eax
xor    %r12d,%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
jne    1260 <main+0xa0>
mov    %ebp,%edi
call   1080 <close@plt>
lea    0xd5c(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd3e(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%eax
jmp    12ab <main+0xeb>

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_WRONLY = global i32 0
@.str.1 = [12 x i8] c"cannot open\00"
@.str.2 = [7 x i8] c"opened\00"
@.str.3 = [7 x i8] c"input:\00"
@.str.4 = [7 x i8] c" %[^\0A]\00"
@.str.5 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
store i32 0, i32* %1
%4 = call i32 @umask(i32 0)
%5 = call i32 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 438)
%6 = load i32, i32* @F_OK
%7 = load i32, i32* @R_OK
%8 = or i32 %6, %7
%9 = load i32, i32* @W_OK
%10 = or i32 %8, %9
%11 = call i64 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %41
15: ; preds = %0
%16 = load i32, i32* @O_WRONLY
%17 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, -1
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%22 = call i32 @puts(i8* %21)
br label %23
23: ; preds = %36, %15
%24 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%26 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %2
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @write(i32 %27, i8* %28, i32 %30)
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %23
br label %37
36: ; preds = %23
br label %23
37: ; preds = %35
%38 = load i32, i32* %2
%39 = call i32 @close(i32 %38)
%40 = call i32 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %37, %13
%42 = load i32, i32* %1
ret i32 %42
}

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_WRONLY = global i32 0
@.str.1 = [12 x i8] c"cannot open\00"
@.str.2 = [7 x i8] c"opened\00"
@.str.3 = [7 x i8] c"input:\00"
@.str.4 = [7 x i8] c" %[^\0A]\00"
@.str.5 = [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 %30
13: ; preds = %0
%14 = load i32, i32* @O_WRONLY
%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 ([7 x i8], [7 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
br label %20
20: ; preds = %20, %13
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%23 = call i32 @strlen(i8* %19)
%24 = call i32 @write(i32 %15, i8* %19, i32 %23)
%25 = call i32 @bcmp(i8* dereferenceable(5) %19, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 5)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %20
27: ; preds = %20
%28 = call i32 @close(i32 %15)
%29 = call i32 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %27, %11
%31 = phi i32 [ 1, %11 ], [ 0, %27 ]
ret i32 %31
}