#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 mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int write(int, char *, int);
int main() {
  int ret;
  ret = mkfifo("./myfifo", 0640);
  if ((ret < 0) && errno != EEXIST) {
    perror("mkfifo");
    return -1;
  }
  int fd;
  fd = open("./myfifo", O_WRONLY);
  if (fd < 0) {
    perror("open");
    return -1;
  }
  ret = write(fd, "hello", 5);
  if (ret < 0) {
    perror("open");
    return -1;
  }
  printf("send a message:%s\n", "hello");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x1a0,%esi
call   1060 <mkfifo@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11bf <main+0x5f>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%rax
je     11bf <main+0x5f>
lea    0xe5b(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <main+0xf4>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
lea    0xe31(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11f9 <main+0x99>
lea    0xe28(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <main+0xf4>
mov    -0xc(%rbp),%edi
lea    0xe12(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1232 <main+0xd2>
lea    0xdef(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <main+0xf4>
lea    0xde2(%rip),%rdi
lea    0xdd5(%rip),%rsi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe98(%rip),%rdi
mov    $0x1a0,%esi
call   1060 <mkfifo@plt>
test   %eax,%eax
jns    118c <main+0x2c>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
jne    11ef <main+0x8f>
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11dc <main+0x7c>
mov    %eax,%ebx
lea    0xe67(%rip),%rsi
mov    %eax,%edi
mov    $0x5,%edx
call   1030 <write@plt>
test   %eax,%eax
js     11dc <main+0x7c>
lea    0xe56(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe2d(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
lea    0xe13(%rip),%rdi
jmp    11e3 <main+0x83>

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_WRONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [19 x i8] c"send a message:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 416)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %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 ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
13: ; preds = %7, %0
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = 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 %31
20: ; preds = %13
%21 = load i32, i32* %3
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = 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 %31
27: ; preds = %20
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* %3
%30 = call i32 @close(i32 %29)
store i32 0, i32* %1
br label %31
31: ; preds = %27, %25, %18, %11
%32 = load i32, i32* %1
ret i32 %32
}

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_WRONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [19 x i8] c"send a message:%s\0A\00"
define i32 @main() {
%1 = tail call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 416)
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %9
3: ; preds = %0
%4 = load i64, i64* @errno
%5 = load i64, i64* @EEXIST
%6 = icmp eq i64 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %23
9: ; preds = %3, %0
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %23
15: ; preds = %9
%16 = tail call i32 @write(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %23
20: ; preds = %15
%21 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i32 @close(i32 %11)
br label %23
23: ; preds = %13, %18, %20, %7
%24 = phi i32 [ -1, %7 ], [ -1, %13 ], [ -1, %18 ], [ 0, %20 ]
ret i32 %24
}