#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_WRONLY;
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*/ sleep(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int fd;
  char cont_w[] = "hello sundy !";
  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_WRONLY, 0666);
    if (fd > 0) {
      while (1) {
        write(fd, cont_w, strlen(cont_w));
        printf("write sucess\n");
        sleep(2);
      }
      close(fd);
    } else {
      perror("open failed");
    }
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x16(%rbp)
mov    0xe78(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xe72(%rip),%ax
mov    %ax,-0xa(%rbp)
lea    0xe69(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <mkfifo@plt>
cmp    $0x0,%rax
jge    11eb <main+0x7b>
mov    0x2e10(%rip),%rax
mov    (%rax),%rax
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
je     11eb <main+0x7b>
lea    0xe3f(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <main+0x10f>
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    0x2db9(%rip),%rax
or     (%rax),%esi
lea    0xdfe(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    126c <main+0xfc>
jmp    122c <main+0xbc>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x16(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x16(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xde9(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
jmp    122c <main+0xbc>
lea    0xddc(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movabs $0x212079646e7573,%rax
mov    %rax,0x6(%rsp)
movabs $0x7573206f6c6c6568,%rax
20 73 75
mov    %rax,(%rsp)
lea    0xe72(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <mkfifo@plt>
test   %rax,%rax
jns    11c1 <main+0x51>
mov    0x2e1e(%rip),%rax
mov    (%rax),%rax
mov    0x2e1c(%rip),%rcx
cmp    (%rcx),%rax
jne    1233 <main+0xc3>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e24(%rip),%rax
mov    0x2de5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe28(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
test   %eax,%eax
jle    1228 <main+0xb8>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xe4c(%rip),%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
jmp    1200 <main+0x90>
xor    %ebx,%ebx
lea    0xdfb(%rip),%rdi
jmp    123f <main+0xcf>
mov    $0xffffffff,%ebx
lea    0xdda(%rip),%rdi
call   1080 <perror@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.cont_w = [14 x i8] c"hello sundy !\00"
@.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_WRONLY = global i32 0
@.str.3 = [14 x i8] c"write sucess\0A\00"
@.str.4 = [12 x i8] c"open failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [14 x i8]
store i32 0, i32* %1
%4 = bitcast [14 x i8]* %3 to i8*
%5 = call i64 @mkfifo(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 438)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @EEXIST
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = 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 %33
13: ; preds = %7, %0
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @O_CREAT
%16 = load i32, i32* @O_WRONLY
%17 = or i32 %15, %16
%18 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17, i32 438)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %13
br label %22
22: ; preds = %21, %22
%23 = load i32, i32* %2
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%25 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @write(i32 %23, i8* %24, i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @sleep(i32 2)
br label %22
30: ; preds = %13
%31 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30
store i32 0, i32* %1
br label %33
33: ; preds = %32, %11
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@__const.main.cont_w = [14 x i8] c"hello sundy !\00"
@.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_WRONLY = global i32 0
@.str.4 = [12 x i8] c"open failed\00"
@str = [20 x i8] c"create fifo success\00"
@str.5 = [13 x i8] c"write sucess\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = getelementptr inbounds [14 x i8], [14 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 %21
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_WRONLY
%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 %21
16: ; preds = %9, %16
%17 = call i32 @strlen(i8* %2)
%18 = call i32 @write(i32 %14, i8* %2, i32 %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
%20 = call i32 @sleep(i32 2)
br label %16
21: ; preds = %9, %5
%22 = 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 ]
%23 = phi i32 [ -1, %5 ], [ 0, %9 ]
%24 = tail call i32 @perror(i8* %22)
ret i32 %23
}