#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ server(int, int);
char *strerror(scalar_t__);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  int readfd;
  int writefd;
  if ((0 > mkfifo("/tmp/fifo.1", (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) &&
      (EEXIST != errno)) {
    printf("mkfifo %s error: %s", "/tmp/fifo.1", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((0 > mkfifo("/tmp/fifo.2", (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) &&
      (EEXIST != errno)) {
    printf("mkfifo %s error: %s", "/tmp/fifo.2", strerror(errno));
    unlink("/tmp/fifo.1");
    exit(EXIT_FAILURE);
  }
  if (0 > (readfd = open("/tmp/fifo.1", O_RDONLY, 0))) {
    printf("open %s error: %s", "/tmp/fifo.1", strerror(errno));
  }
  if (0 > (writefd = open("/tmp/fifo.2", O_WRONLY, 0))) {
    printf("open %s error: %s", "/tmp/fifo.2", strerror(errno));
  }
  server(readfd, writefd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    0x2e4a(%rip),%rax
or     (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
lea    0xe4f(%rip),%rdi
call   1050 <mkfifo@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    1211 <main+0xa1>
mov    0x2e05(%rip),%rax
mov    (%rax),%rax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%rax
je     1211 <main+0xa1>
mov    0x2de3(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rdx
lea    0xe15(%rip),%rdi
lea    0xe02(%rip),%rsi
call   1040 <printf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    0x2dbf(%rip),%rax
or     (%rax),%esi
mov    0x2d96(%rip),%rax
or     (%rax),%esi
mov    0x2d85(%rip),%rax
or     (%rax),%esi
lea    0xde4(%rip),%rdi
call   1050 <mkfifo@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    12a8 <main+0x138>
mov    0x2d7a(%rip),%rax
mov    (%rax),%rax
mov    0x2d68(%rip),%rcx
cmp    (%rcx),%rax
je     12a8 <main+0x138>
mov    0x2d58(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rdx
lea    0xd8a(%rip),%rdi
lea    0xd97(%rip),%rsi
call   1040 <printf@plt>
lea    0xd6b(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
lea    0xd48(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jle    12f3 <main+0x183>
mov    0x2cf3(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rdx
lea    0xd45(%rip),%rdi
lea    0xd12(%rip),%rsi
call   1040 <printf@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%esi
lea    0xd1d(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jle    133e <main+0x1ce>
mov    0x2ca8(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rdx
lea    0xcfa(%rip),%rdi
lea    0xce7(%rip),%rsi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <server@plt>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e2a(%rip),%r14
mov    0x2e5b(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r14),%esi
mov    0x2e2e(%rip),%r15
or     (%r15),%esi
mov    0x2e1c(%rip),%rbx
or     (%rbx),%esi
lea    0xe5b(%rip),%rdi
call   1050 <mkfifo@plt>
test   %rax,%rax
jns    11c9 <main+0x59>
mov    0x2e1a(%rip),%rax
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%rdi
cmp    %rdi,(%rax)
jne    129a <main+0x12a>
mov    0x0(%rbp),%esi
or     (%r14),%esi
or     (%r15),%esi
or     (%rbx),%esi
lea    0xe45(%rip),%rdi
call   1050 <mkfifo@plt>
test   %rax,%rax
jns    11ff <main+0x8f>
mov    0x2de4(%rip),%rax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%rdi
cmp    %rdi,(%rax)
jne    12b7 <main+0x147>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    0xdf1(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1241 <main+0xd1>
mov    0x2da5(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xdfa(%rip),%rdi
lea    0xdc7(%rip),%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
lea    0xdcf(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1283 <main+0x113>
mov    0x2d63(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xdb8(%rip),%rdi
lea    0xda5(%rip),%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <server@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
call   1090 <strerror@plt>
lea    0xd66(%rip),%rdi
lea    0xd53(%rip),%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
jmp    12de <main+0x16e>
call   1090 <strerror@plt>
lea    0xd49(%rip),%rdi
lea    0xd56(%rip),%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
lea    0xd27(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/fifo.1\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@EEXIST = global i64 0
@errno = global i64 0
@.str.1 = [20 x i8] c"mkfifo %s error: %s\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"/tmp/fifo.2\00"
@O_RDONLY = global i32 0
@.str.3 = [18 x i8] c"open %s error: %s\00"
@O_WRONLY = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IROTH
%14 = or i32 %12, %13
%15 = call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp sgt i64 0, %15
br i1 %16, label %17, label %27
17: ; preds = %2
%18 = load i64, i64* @EEXIST
%19 = load i64, i64* @errno
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %17, %2
%28 = load i32, i32* @S_IRUSR
%29 = load i32, i32* @S_IWUSR
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IRGRP
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IROTH
%34 = or i32 %32, %33
%35 = call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = icmp sgt i64 0, %35
br i1 %36, label %37, label %48
37: ; preds = %27
%38 = load i64, i64* @EEXIST
%39 = load i64, i64* @errno
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %48
41: ; preds = %37
%42 = load i64, i64* @errno
%43 = call i8* @strerror(i64 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %37, %27
%49 = load i32, i32* @O_RDONLY
%50 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %49, i32 0)
store i32 %50, i32* %6
%51 = icmp sgt i32 0, %50
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i64, i64* @errno
%54 = call i8* @strerror(i64 %53)
%55 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %52, %48
%57 = load i32, i32* @O_WRONLY
%58 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %57, i32 0)
store i32 %58, i32* %7
%59 = icmp sgt i32 0, %58
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i64, i64* @errno
%62 = call i8* @strerror(i64 %61)
%63 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %60, %56
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = call i32 @server(i32 %65, i32 %66)
%68 = load i32, i32* @EXIT_SUCCESS
%69 = call i32 @exit(i32 %68)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/fifo.1\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@EEXIST = global i64 0
@errno = global i64 0
@.str.1 = [20 x i8] c"mkfifo %s error: %s\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"/tmp/fifo.2\00"
@O_RDONLY = global i32 0
@.str.3 = [18 x i8] c"open %s error: %s\00"
@O_WRONLY = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @S_IRUSR
%4 = load i32, i32* @S_IWUSR
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IRGRP
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IROTH
%9 = or i32 %7, %8
%10 = tail call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i64, i64* @EEXIST
%14 = load i64, i64* @errno
%15 = icmp eq i64 %13, %14
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = tail call i8* @strerror(i64 %14)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %12, %2
%22 = load i32, i32* @S_IRUSR
%23 = load i32, i32* @S_IWUSR
%24 = or i32 %23, %22
%25 = load i32, i32* @S_IRGRP
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IROTH
%28 = or i32 %26, %27
%29 = tail call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %21
%32 = load i64, i64* @EEXIST
%33 = load i64, i64* @errno
%34 = icmp eq i64 %32, %33
br i1 %34, label %41, label %35
35: ; preds = %31
%36 = tail call i8* @strerror(i64 %33)
%37 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %31, %21
%42 = load i32, i32* @O_RDONLY
%43 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %42, i32 0)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i64, i64* @errno
%47 = tail call i8* @strerror(i64 %46)
%48 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %45, %41
%50 = load i32, i32* @O_WRONLY
%51 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %50, i32 0)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i64, i64* @errno
%55 = tail call i8* @strerror(i64 %54)
%56 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %53, %49
%58 = tail call i32 @server(i32 %43, i32 %51)
%59 = load i32, i32* @EXIT_SUCCESS
%60 = tail call i32 @exit(i32 %59)
unreachable
}