#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_WRONLY;
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 /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main() {
  int ret;
  ret = mkfifo("./myfifo1", 0640);
  if ((ret < 0) && errno != EEXIST) {
    perror("mkfifo");
    return -1;
  }
  int fd;
  char buff[1024] = {0};
  fd = open("./myfifo1", O_WRONLY);
  if (fd < 0) {
    perror("open");
    return -1;
  }
  while (1) {
    memset(buff, 0, 1024);
    printf("Input  messages:    ");
    scanf("%s", buff);
    ret = write(fd, buff, strlen(buff));
    if (ret < 0) {
      perror("open");
      return -1;
    }
    printf("信息已发送\n");
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
mov    $0x1a0,%esi
call   1070 <mkfifo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11e2 <main+0x62>
mov    0x2e21(%rip),%rax
mov    (%rax),%rax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
je     11e2 <main+0x62>
lea    0xe39(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d3 <main+0x153>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    0xdfb(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    122f <main+0xaf>
lea    0xdf3(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d3 <main+0x153>
jmp    1234 <main+0xb4>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0xdc8(%rip),%rdi
call   1050 <printf@plt>
lea    -0x410(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1080 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x41c(%rbp),%edi
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12c2 <main+0x142>
lea    0xd60(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d3 <main+0x153>
lea    0xd65(%rip),%rdi
call   1050 <printf@plt>
jmp    1234 <main+0xb4>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
lea    0xe5a(%rip),%rdi
mov    $0x1a0,%esi
call   1080 <mkfifo@plt>
test   %eax,%eax
jns    11ce <main+0x3e>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
jne    1264 <main+0xd4>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
jns    11ff <main+0x6f>
lea    0xe14(%rip),%rdi
jmp    126b <main+0xdb>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xe0b(%rip),%r14
lea    0xe19(%rip),%r15
lea    0xe15(%rip),%r12
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     11f6 <main+0x66>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1220 <main+0x90>
lea    0xd9f(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
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_WRONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [21 x i8] c"Input messages: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [17 x i8] c"\E4\BF\A1\E6\81\AF\E5\B7\B2\E5\8F\91\E9\80\81\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 ([10 x i8], [10 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 %40
14: ; preds = %8, %0
%15 = bitcast [1024 x i8]* %4 to i8*
%16 = load i32, i32* @O_WRONLY
%17 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 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 %40
22: ; preds = %14
br label %23
23: ; preds = %22, %38
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 1024)
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %3
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @write(i32 %29, i8* %30, i32 %32)
store i32 %33, i32* %2
%34 = load i32, i32* %2
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %23
%37 = 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 %40
38: ; preds = %23
%39 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %23
40: ; preds = %36, %20, %12
%41 = load i32, i32* %1
ret i32 %41
}

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_WRONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [21 x i8] c"Input messages: \00"
@.str.4 = [3 x i8] c"%s\00"
@str = [16 x i8] c"\E4\BF\A1\E6\81\AF\E5\B7\B2\E5\8F\91\E9\80\81\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 %29
10: ; preds = %4, %0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%12 = load i32, i32* @O_WRONLY
%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 %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 %28
17: ; preds = %10, %26
%18 = call i32 @memset(i8* %11, i32 0, i32 1024)
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%21 = call i32 @strlen(i8* %11)
%22 = call i32 @write(i32 %13, i8* %11, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %28
26: ; preds = %17
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %17
28: ; preds = %24, %15
br label %29
29: ; preds = %28, %8
ret i32 -1
}