#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*/ F_OK;
int /*<<< orphan*/ O_WRONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
int main() {
  char line[(8092)];
  int fifo;
  if (access("myfifo.f", F_OK) == -1) {
    perror("[write]");
    if (mkfifo("myfifo.f", (0644)) == -1) {
      perror("[write]");
      return -1;
    }
  }
  if ((fifo = open("myfifo.f", O_WRONLY)) == -1) {
    perror("[write]");
    return -1;
  }
  while (1) {
    memset(line, 0, (8092));
    fgets(line, (8092), stdin);
    line[strlen(line) - 1] = 0;
    if (write(fifo, line, (8092)) == -1) {
      perror("[write]");
      break;
    }
    if (line[0] == 'q') {
      break;
    }
  }
  close(fifo);
  unlink("myfifo.f");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1fb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe2e(%rip),%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    1223 <main+0x73>
lea    0xe22(%rip),%rdi
call   10c0 <perror@plt>
lea    0xe0d(%rip),%rdi
mov    $0x1a4,%esi
call   1090 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    121e <main+0x6e>
lea    0xdfc(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1313 <main+0x163>
jmp    1223 <main+0x73>
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
lea    0xdcd(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x1fa4(%rbp)
cmp    $0xffffffff,%eax
jne    125f <main+0xaf>
lea    0xdbb(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1313 <main+0x163>
jmp    1264 <main+0xb4>
lea    -0x1fa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f9c,%edx
call   1060 <memset@plt>
lea    -0x1fa0(%rbp),%rdi
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
mov    $0x1f9c,%esi
call   1080 <fgets@plt>
lea    -0x1fa0(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x1fa0(%rbp,%rax,1)
mov    -0x1fa4(%rbp),%edi
lea    -0x1fa0(%rbp),%rsi
mov    $0x1f9c,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    12db <main+0x12b>
lea    0xd38(%rip),%rdi
call   10c0 <perror@plt>
jmp    12f5 <main+0x145>
movsbl -0x1fa0(%rbp),%eax
cmp    $0x71,%eax
jne    12f0 <main+0x140>
jmp    12f5 <main+0x145>
jmp    1264 <main+0xb4>
mov    -0x1fa4(%rbp),%edi
call   1070 <close@plt>
lea    0xcf9(%rip),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x1fb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1fa0,%rsp
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    11f8 <main+0x48>
lea    0xe2c(%rip),%rdi
call   10c0 <perror@plt>
lea    0xe17(%rip),%rdi
mov    $0x1a4,%esi
call   1090 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     1212 <main+0x62>
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
lea    0xdf8(%rip),%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
jne    1230 <main+0x80>
lea    0xdf0(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x1fa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %eax,%ebx
mov    %rsp,%r14
mov    0x2dac(%rip),%r15
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1f9c,%edx
call   1060 <memset@plt>
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0x1f9c,%esi
call   1080 <fgets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1f9c,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1287 <main+0xd7>
cmpb   $0x71,(%rsp)
jne    123c <main+0x8c>
jmp    1293 <main+0xe3>
lea    0xd7b(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xd5f(%rip),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"myfifo.f\00"
@F_OK = global i32 0
@.str.1 = [8 x i8] c"[write]\00"
@O_WRONLY = global i32 0
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [8092 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @F_OK
%5 = call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 420)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %50
13: ; preds = %7
br label %14
14: ; preds = %13, %0
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %3
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %50
20: ; preds = %14
br label %21
21: ; preds = %20, %44
%22 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 8092)
%24 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 0
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %24, i32 8092, i32 %25)
%27 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 %30
store i8 0, i8* %31
%32 = load i32, i32* %3
%33 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 0
%34 = call i32 @write(i32 %32, i8* %33, i32 8092)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %21
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %45
38: ; preds = %21
%39 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 113
br i1 %42, label %43, label %44
43: ; preds = %38
br label %45
44: ; preds = %38
br label %21
45: ; preds = %43, %36
%46 = load i32, i32* %3
%47 = call i32 @close(i32 %46)
%48 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %18, %11
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [9 x i8] c"myfifo.f\00"
@F_OK = global i32 0
@.str.1 = [8 x i8] c"[write]\00"
@O_WRONLY = global i32 0
@stdin = global i32 0
define i32 @main() {
%1 = alloca [8092 x i8]
%2 = getelementptr inbounds [8092 x i8], [8092 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 420)
%9 = icmp eq i32 %8, -1
br i1 %9, label %33, label %10
10: ; preds = %6, %0
%11 = load i32, i32* @O_WRONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %33, label %14
14: ; preds = %10, %26
%15 = call i32 @memset(i8* %2, i32 0, i32 8092)
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %2, i32 8092, i32 %16)
%18 = call i32 @strlen(i8* %2)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [8092 x i8], [8092 x i8]* %1, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 @write(i32 %12, i8* %2, i32 8092)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %29
26: ; preds = %14
%27 = load i8, i8* %2
%28 = icmp eq i8 %27, 113
br i1 %28, label %29, label %14
29: ; preds = %26, %24
%30 = call i32 @close(i32 %12)
%31 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %10, %6
%34 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
}