#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 /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main() {
  int ret;
  ret = mkfifo("./myfifo1", 0640);
  if ((ret < 0) && errno != EEXIST) {
    perror("mkfifo");
    return -1;
  }
  int fd, fd1;
  char buff[1024] = {0};
  fd = open("./myfifo1", O_RDONLY);
  if (fd < 0) {
    perror("open");
    return -1;
  }
  while (1) {
    memset(buff, 0, 1024);
    ret = read(fd, buff, 1023);
    if (ret < 0) {
      perror("open");
      return -1;
    }
    printf("recv messages:    %s\n", buff);
    printf("信息已受到\n");
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x1a0,%esi
call   1060 <mkfifo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c2 <main+0x62>
mov    0x2e39(%rip),%rax
mov    (%rax),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
je     11c2 <main+0x62>
lea    0xe59(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <main+0x128>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
lea    0xe1b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    120f <main+0xaf>
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <main+0x128>
jmp    1214 <main+0xb4>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1260 <main+0x100>
lea    0xdc2(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <main+0x128>
lea    -0x410(%rbp),%rsi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1214 <main+0xb4>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xe7c(%rip),%rdi
mov    $0x1a0,%esi
call   1070 <mkfifo@plt>
test   %eax,%eax
jns    11ac <main+0x3c>
mov    0x2e37(%rip),%rax
mov    (%rax),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jne    1250 <main+0xe0>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1247 <main+0xd7>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1247 <main+0xd7>
lea    0xe14(%rip),%r14
mov    %rsp,%rbx
lea    0xe20(%rip),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
test   %eax,%eax
jns    1210 <main+0xa0>
lea    0xdc3(%rip),%rdi
jmp    1257 <main+0xe7>
lea    0xdb3(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"./myfifo1\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 = [22 x i8] c"recv messages: %s\0A\00"
@.str.4 = [17 x i8] c"\E4\BF\A1\E6\81\AF\E5\B7\B2\E5\8F\97\E5\88\B0\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 0, i32* %1
%6 = call i32 @mkfifo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 416)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i64, i64* @errno
%11 = load i64, i64* @EEXIST
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = 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 %38
15: ; preds = %9, %0
%16 = bitcast [1024 x i8]* %5 to i8*
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = 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 %38
23: ; preds = %15
br label %24
24: ; preds = %23, %34
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i32 0, i32 1024)
%27 = load i32, i32* %3
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 1023)
store i32 %29, i32* %2
%30 = load i32, i32* %2
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = 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 %38
34: ; preds = %24
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %24
38: ; preds = %32, %21, %13
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [10 x i8] c"./myfifo1\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 = [22 x i8] c"recv messages: %s\0A\00"
@str = [16 x i8] c"\E4\BF\A1\E6\81\AF\E5\B7\B2\E5\8F\97\E5\88\B0\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = tail call i32 @mkfifo(i8* getelementptr inbounds ([10 x i8], [10 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 %30
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 ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = call i32 @memset(i8* %11, i32 0, i32 1024)
%17 = call i32 @read(i32 %13, i8* %11, i32 1023)
%18 = icmp slt i32 %17, 0
br i1 %18, label %21, label %23
19: ; preds = %10
%20 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %29
21: ; preds = %23, %15
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %29
23: ; preds = %15, %23
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%26 = call i32 @memset(i8* %11, i32 0, i32 1024)
%27 = call i32 @read(i32 %13, i8* %11, i32 1023)
%28 = icmp slt i32 %27, 0
br i1 %28, label %21, label %23
29: ; preds = %21, %19
br label %30
30: ; preds = %29, %8
ret i32 -1
}