#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__ EAGAIN;
scalar_t__ EEXIST;
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ S_IRWXU;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ mkfifo(char *, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main() {
  char buf[100];
  int n = 0;
  int fd;
  if ((mkfifo("/tmp/myfifo", S_IRWXU) < 0) && (errno != EEXIST)) {
    perror("mkfifo error");
    exit(-1);
  }
  if ((fd = open("/tmp/myfifo", O_RDONLY | O_NONBLOCK)) < 0) {
    perror("open error");
    exit(-1);
  }
  while (1) {
    if ((n = read(fd, buf, 100)) < 0) {
      if (errno == EAGAIN) {
        printf("No data yet\n");
      }
    } else if (n == 0)
      printf("No opened by write_only\n");
    else
      write(STDOUT_FILENO, buf, n);
    sleep(1);
  }
  unlink("/tmp/myfifo");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1060 <mkfifo@plt>
cmp    $0x0,%rax
jge    11e8 <main+0x68>
mov    0x2df9(%rip),%rax
mov    (%rax),%rax
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
je     11e8 <main+0x68>
lea    0xe33(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    0x2de0(%rip),%rax
or     (%rax),%esi
lea    0xdff(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x78(%rbp)
cmp    $0x0,%eax
jge    1228 <main+0xa8>
lea    0xe00(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    122d <main+0xad>
mov    -0x78(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jge    1275 <main+0xf5>
mov    0x2d67(%rip),%rax
mov    (%rax),%rax
mov    0x2d4d(%rip),%rcx
cmp    (%rcx),%rax
jne    1270 <main+0xf0>
lea    0xdb9(%rip),%rdi
call   1040 <printf@plt>
jmp    12aa <main+0x12a>
cmpl   $0x0,-0x74(%rbp)
jne    1290 <main+0x110>
lea    0xdab(%rip),%rdi
call   1040 <printf@plt>
jmp    12a5 <main+0x125>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
call   1030 <write@plt>
jmp    12aa <main+0x12a>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    122d <main+0xad>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1060 <mkfifo@plt>
test   %rax,%rax
jns    11c2 <main+0x42>
mov    0x2e09(%rip),%rax
mov    (%rax),%rax
mov    0x2e07(%rip),%rcx
cmp    (%rcx),%rax
jne    1271 <main+0xf1>
mov    0x2e07(%rip),%rax
mov    0x2e08(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe25(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1268 <main+0xe8>
mov    %eax,%ebx
mov    %rsp,%r14
mov    0x2dc4(%rip),%r13
mov    0x2dad(%rip),%rbp
lea    0xe22(%rip),%r12
mov    0x2de7(%rip),%r15
jmp    1227 <main+0xa7>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1250 <main+0xd0>
jne    1210 <main+0x90>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    121d <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%rax
cmp    0x0(%rbp),%rax
jne    121d <main+0x9d>
lea    0xddb(%rip),%rdi
call   1030 <puts@plt>
jmp    121d <main+0x9d>
lea    0xdaa(%rip),%rdi
jmp    1278 <main+0xf8>
lea    0xd94(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/myfifo\00"
@S_IRWXU = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [13 x i8] c"mkfifo error\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [11 x i8] c"open error\00"
@EAGAIN = global i64 0
@.str.3 = [13 x i8] c"No data yet\0A\00"
@.str.4 = [25 x i8] c"No opened by write_only\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%5 = load i32, i32* @S_IRWXU
%6 = call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EEXIST
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %8, %0
%16 = load i32, i32* @O_RDONLY
%17 = load i32, i32* @O_NONBLOCK
%18 = or i32 %16, %17
%19 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %15
br label %25
25: ; preds = %24, %48
%26 = load i32, i32* %4
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 100)
store i32 %28, i32* %3
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %25
%31 = load i64, i64* @errno
%32 = load i64, i64* @EAGAIN
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
br label %48
37: ; preds = %25
%38 = load i32, i32* %3
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %47
42: ; preds = %37
%43 = load i32, i32* @STDOUT_FILENO
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%45 = load i32, i32* %3
%46 = call i32 @write(i32 %43, i8* %44, i32 %45)
br label %47
47: ; preds = %42, %40
br label %48
48: ; preds = %47, %36
%49 = call i32 @sleep(i32 1)
br label %25
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/myfifo\00"
@S_IRWXU = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [13 x i8] c"mkfifo error\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [11 x i8] c"open error\00"
@EAGAIN = global i64 0
@STDOUT_FILENO = global i32 0
@str = [24 x i8] c"No opened by write_only\00"
@str.5 = [12 x i8] c"No data yet\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @S_IRWXU
%4 = tail call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = load i64, i64* @errno
%8 = load i64, i64* @EEXIST
%9 = icmp eq i64 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %6, %0
%14 = load i32, i32* @O_RDONLY
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %15, %14
%17 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %13, %38
%23 = call i32 @read(i32 %17, i8* %2, i32 100)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @EAGAIN
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
br label %38
31: ; preds = %22
%32 = icmp eq i32 %23, 0
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %38
35: ; preds = %31
%36 = load i32, i32* @STDOUT_FILENO
%37 = call i32 @write(i32 %36, i8* %2, i32 %23)
br label %38
38: ; preds = %33, %35, %25, %29
%39 = tail call i32 @sleep(i32 1)
br label %22
}