#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 */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, scalar_t__);
int main() {
  char *fn = (char *)"temp.fifo";
  char out[20] = "FIFO's are fun!";
  int wfd;
  unlink(fn);
  if (mkfifo(fn, 0666) != 0)
    perror("mkfifo() error");
  else {
    {
      if ((wfd = open(fn, O_WRONLY)) < 0)
        perror("open() error for write end");
      else {
        if (write(wfd, out, strlen(out) + 1) == -1)
          perror("write() error");
        close(wfd);
      }
    }
    unlink(fn);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xebf(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xebc(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeba(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
cmp    $0x0,%rax
je     11db <main+0x6b>
lea    0xe39(%rip),%rdi
call   1090 <perror@plt>
jmp    125a <main+0xea>
mov    -0x10(%rbp),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    120a <main+0x9a>
lea    0xe19(%rip),%rdi
call   1090 <perror@plt>
jmp    1251 <main+0xe1>
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1249 <main+0xd9>
lea    0xdf0(%rip),%rdi
call   1090 <perror@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe6f(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
test   %rax,%rax
jne    1201 <main+0x91>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     120f <main+0x9f>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     121d <main+0xad>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe0e(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe02(%rip),%rdi
call   1090 <perror@plt>
jmp    11f7 <main+0x87>
lea    0xe03(%rip),%rdi
call   1090 <perror@plt>
jmp    11eb <main+0x7b>
lea    0xe10(%rip),%rdi
call   1090 <perror@plt>
jmp    11e4 <main+0x74>

LLVM IR (-O0):
@.str = [10 x i8] c"temp.fifo\00"
@__const.main.out = [20 x i8] c"FIFO's are fun!\00\00\00\00\00"
@.str.1 = [15 x i8] c"mkfifo() error\00"
@O_WRONLY = global i32 0
@.str.2 = [27 x i8] c"open() error for write end\00"
@.str.3 = [14 x i8] c"write() error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = bitcast [20 x i8]* %3 to i8*
%6 = load i8*, i8** %2
%7 = call i32 @unlink(i8* %6)
%8 = load i8*, i8** %2
%9 = call i64 @mkfifo(i8* %8, i32 438)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %36
13: ; preds = %0
%14 = load i8*, i8** %2
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %33
20: ; preds = %13
%21 = load i32, i32* %4
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %24, 1
%26 = call i32 @write(i32 %21, i8* %22, i64 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %20
%31 = load i32, i32* %4
%32 = call i32 @close(i32 %31)
br label %33
33: ; preds = %30, %18
%34 = load i8*, i8** %2
%35 = call i32 @unlink(i8* %34)
br label %36
36: ; preds = %33, %11
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [10 x i8] c"temp.fifo\00"
@__const.main.out = [20 x i8] c"FIFO's are fun!\00\00\00\00\00"
@.str.1 = [15 x i8] c"mkfifo() error\00"
@O_WRONLY = global i32 0
@.str.2 = [27 x i8] c"open() error for write end\00"
@.str.3 = [14 x i8] c"write() error\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @mkfifo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 438)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %25
8: ; preds = %0
%9 = load i32, i32* @O_WRONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %23
14: ; preds = %8
%15 = call i64 @strlen(i8* %2)
%16 = add nsw i64 %15, 1
%17 = call i32 @write(i32 %10, i8* %2, i64 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = tail call i32 @close(i32 %10)
br label %23
23: ; preds = %21, %12
%24 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %6
ret i32 0
}