#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int main() {
  int ret;
  ret = mkfifo("./myfifo", 0640);
  if ((ret < 0) && errno != EEXIST) {
    perror("mkfifo");
    return -1;
  }
  int fd;
  char buff[1024] = {0};
  fd = open("./myfifo", O_RDONLY);
  if (fd < 0) {
    perror("open");
    return -1;
  }
  ret = read(fd, buff, 1023);
  if (ret < 0) {
    perror("open");
    return -1;
  }
  printf("recv a message:%s\n", buff);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x1a0,%esi
call   1070 <mkfifo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11d2 <main+0x62>
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
je     11d2 <main+0x62>
lea    0xe48(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <main+0x10a>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
lea    0xe0b(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    121f <main+0xaf>
lea    0xe02(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <main+0x10a>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1258 <main+0xe8>
lea    0xdc9(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127a <main+0x10a>
lea    -0x410(%rbp),%rsi
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
lea    0xe81(%rip),%rdi
mov    $0x1a0,%esi
call   1070 <mkfifo@plt>
test   %eax,%eax
jns    11a3 <main+0x33>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
jne    1214 <main+0xa4>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1201 <main+0x91>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x3ff,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1201 <main+0x91>
lea    0xe2e(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret
lea    0xe08(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    11f8 <main+0x88>
lea    0xdee(%rip),%rdi
jmp    1208 <main+0x98>

LLVM IR (-O0):
@.str = [9 x i8] c"./myfifo\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [7 x i8] c"mkfifo\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [19 x i8] c"recv a message:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
store i32 0, i32* %1
%5 = call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 416)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
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 %14
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %35
14: ; preds = %8, %0
%15 = bitcast [1024 x i8]* %4 to i8*
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %35
22: ; preds = %14
%23 = load i32, i32* %3
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%25 = call i32 @read(i32 %23, i8* %24, i32 1023)
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %35
30: ; preds = %22
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32, i32* %3
%34 = call i32 @close(i32 %33)
store i32 0, i32* %1
br label %35
35: ; preds = %30, %28, %20, %12
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [9 x i8] c"./myfifo\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [7 x i8] c"mkfifo\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [19 x i8] c"recv a message:%s\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = tail call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 416)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %10
4: ; preds = %0
%5 = load i64, i64* @errno
%6 = load i64, i64* @EEXIST
%7 = icmp eq i64 %5, %6
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %27
10: ; preds = %4, %0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %25
17: ; preds = %10
%18 = call i32 @read(i32 %13, i8* %11, i32 1023)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %25
22: ; preds = %17
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%24 = call i32 @close(i32 %13)
br label %25
25: ; preds = %22, %20, %15
%26 = phi i32 [ -1, %15 ], [ -1, %20 ], [ 0, %22 ]
br label %27
27: ; preds = %25, %8
%28 = phi i32 [ -1, %8 ], [ %26, %25 ]
ret i32 %28
}