#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 O_NONBLOCK;
int O_RDONLY;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ clr_fl(int, int);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ mkfifo(char *, int);
int open(char *, int);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  int fdread, fdwrite;
  unlink("temp.fifo");
  if (mkfifo("temp.fifo", (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0)
    err_sys("mkfifo error");
  if ((fdread = open("temp.fifo", O_RDONLY | O_NONBLOCK)) < 0)
    err_sys("open error for reading");
  if ((fdwrite = open("temp.fifo", O_WRONLY)) < 0)
    err_sys("open error for writing");
  clr_fl(fdread, O_NONBLOCK);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    0x2e4d(%rip),%rax
or     (%rax),%esi
mov    0x2e34(%rip),%rax
or     (%rax),%esi
mov    0x2e23(%rip),%rax
or     (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1050 <mkfifo@plt>
cmp    $0x0,%rax
jge    11c1 <main+0x61>
lea    0xe4e(%rip),%rdi
call   1040 <err_sys@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    0x2e17(%rip),%rax
or     (%rax),%esi
lea    0xe26(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11f7 <main+0x97>
lea    0xe25(%rip),%rdi
call   1040 <err_sys@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
lea    0xdf9(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1224 <main+0xc4>
lea    0xe0f(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x8(%rbp),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
call   1060 <clr_fl@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2e3e(%rip),%rax
mov    0x2e57(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e3c(%rip),%rax
or     (%rax),%esi
mov    0x2e2b(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1050 <mkfifo@plt>
test   %rax,%rax
jns    11b0 <main+0x50>
lea    0xe5f(%rip),%rdi
call   1040 <err_sys@plt>
mov    0x2e29(%rip),%rax
mov    0x2e2a(%rip),%r14
mov    (%r14),%esi
or     (%rax),%esi
lea    0xe36(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11e1 <main+0x81>
lea    0xe3b(%rip),%rdi
call   1040 <err_sys@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
jns    1206 <main+0xa6>
lea    0xe2d(%rip),%rdi
call   1040 <err_sys@plt>
mov    (%r14),%esi
mov    %ebx,%edi
call   1060 <clr_fl@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"temp.fifo\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [13 x i8] c"mkfifo error\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [23 x i8] c"open error for reading\00"
@O_WRONLY = global i32 0
@.str.3 = [23 x i8] c"open error for writing\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRGRP
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IROTH
%11 = or i32 %9, %10
%12 = call i64 @mkfifo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = load i32, i32* @O_RDONLY
%18 = load i32, i32* @O_NONBLOCK
%19 = or i32 %17, %18
%20 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %2
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @err_sys(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = load i32, i32* @O_WRONLY
%26 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 %26, i32* %3
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @err_sys(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* %2
%32 = load i32, i32* @O_NONBLOCK
%33 = call i32 @clr_fl(i32 %31, i32 %32)
%34 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"temp.fifo\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [13 x i8] c"mkfifo error\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [23 x i8] c"open error for reading\00"
@O_WRONLY = global i32 0
@.str.3 = [23 x i8] c"open error for writing\00"
define i32 @main() {
%1 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @S_IRUSR
%3 = load i32, i32* @S_IWUSR
%4 = or i32 %3, %2
%5 = load i32, i32* @S_IRGRP
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IROTH
%8 = or i32 %6, %7
%9 = tail call i64 @mkfifo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = load i32, i32* @O_RDONLY
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %15, %14
%17 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 @err_sys(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = load i32, i32* @O_WRONLY
%23 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @err_sys(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* @O_NONBLOCK
%29 = tail call i32 @clr_fl(i32 %17, i32 %28)
%30 = tail call i32 @exit(i32 0)
unreachable
}