#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 O_CREAT;
int O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
scalar_t__ mkfifo(char *, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int main() {
  int fd;
  char cont_r[255];
  if (mkfifo("myfifofile", 0666) < 0 && errno != EEXIST) {
    perror("create fifo failed");
    return -1;
  } else {
    printf("create fifo success\n");
    fd = open("myfifofile", O_CREAT | O_RDONLY, 0666);
    if (fd > 0) {
      while (1) {
        read(fd, cont_r, 255);
        printf("read:%s\n", cont_r);
      }
      close(fd);
    } else {
      perror("open failed");
    }
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
cmp    $0x0,%rax
jge    11af <main+0x5f>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%rax
je     11af <main+0x5f>
lea    0xe6d(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <main+0xe3>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
or     (%rax),%esi
lea    0xe2a(%rip),%rdi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1220 <main+0xd0>
jmp    11f2 <main+0xa2>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1040 <read@plt>
lea    -0x110(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f2 <main+0xa2>
lea    0xe15(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe8e(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <mkfifo@plt>
test   %rax,%rax
jns    1197 <main+0x37>
mov    0x2e40(%rip),%rax
mov    (%rax),%rax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%rax
jne    1209 <main+0xa9>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e4e(%rip),%rax
mov    0x2e2f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe44(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
test   %eax,%eax
jle    11fe <main+0x9e>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xe48(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e0 <main+0x80>
xor    %ebx,%ebx
lea    0xe20(%rip),%rdi
jmp    1215 <main+0xb5>
mov    $0xffffffff,%ebx
lea    0xdf6(%rip),%rdi
call   1080 <perror@plt>
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"myfifofile\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [19 x i8] c"create fifo failed\00"
@.str.2 = [21 x i8] c"create fifo success\0A\00"
@O_CREAT = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [9 x i8] c"read:%s\0A\00"
@.str.4 = [12 x i8] c"open failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [255 x i8]
store i32 0, i32* %1
%4 = call i64 @mkfifo(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 438)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i64, i64* @errno
%8 = load i64, i64* @EEXIST
%9 = icmp ne i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %30
12: ; preds = %6, %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @O_CREAT
%15 = load i32, i32* @O_RDONLY
%16 = or i32 %14, %15
%17 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %16, i32 438)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %12
br label %21
21: ; preds = %20, %21
%22 = load i32, i32* %2
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%24 = call i32 @read(i32 %22, i8* %23, i32 255)
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %21
27: ; preds = %12
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27
store i32 0, i32* %1
br label %30
30: ; preds = %29, %10
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [11 x i8] c"myfifofile\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [19 x i8] c"create fifo failed\00"
@O_CREAT = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [9 x i8] c"read:%s\0A\00"
@.str.4 = [12 x i8] c"open failed\00"
@str = [20 x i8] c"create fifo success\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%3 = tail call i64 @mkfifo(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 438)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = load i64, i64* @EEXIST
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %5, %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_RDONLY
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13, i32 438)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %9, %16
%17 = call i32 @read(i32 %14, i8* %2, i32 255)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %16
19: ; preds = %9, %5
%20 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %9 ]
%21 = phi i32 [ -1, %5 ], [ 0, %9 ]
%22 = tail call i32 @perror(i8* %20)
ret i32 %21
}