#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ client(int, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ server(int, int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main() {
  int readfd, writefd;
  pid_t childpid;
  if ((mkfifo("/tmp/fifo.1", (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) &&
      errno != EEXIST) {
    perror("Can't create Fifo1: ");
  }
  if ((mkfifo("/tmp/fifo.2", (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) &&
      errno != EEXIST) {
    perror("Can't create Fifo2: ");
    unlink("/tmp/fifo.1");
  }
  if ((childpid = fork()) == 0) {
    if ((writefd = open("/tmp/fifo.1", O_WRONLY)) == -1) {
      perror("Can't opem Fifo1: ");
    }
    if ((readfd = open("/tmp/fifo.2", O_RDONLY)) == -1) {
      perror("Can't opem Fifo1: ");
    }
    server(readfd, writefd);
    exit(0);
  }
  if ((readfd = open("/tmp/fifo.1", O_RDONLY)) == -1) {
    perror("Open Readfd");
    exit(-1);
  }
  if ((writefd = open("/tmp/fifo.2", O_WRONLY)) == -1) {
    perror("Open Readfd");
    exit(-1);
  }
  client(readfd, writefd);
  waitpid(childpid, NULL, 0);
  unlink("/tmp/fifo.1");
  unlink("/tmp/fifo.2");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    0x2e31(%rip),%rax
or     (%rax),%esi
mov    0x2e08(%rip),%rax
or     (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
lea    0xe36(%rip),%rdi
call   1040 <mkfifo@plt>
cmp    $0x0,%rax
jge    11ff <main+0x6f>
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    0x2de6(%rip),%rcx
cmp    (%rcx),%rax
je     11ff <main+0x6f>
lea    0xe12(%rip),%rdi
call   1080 <perror@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    0x2dd1(%rip),%rax
or     (%rax),%esi
mov    0x2da8(%rip),%rax
or     (%rax),%esi
mov    0x2d97(%rip),%rax
or     (%rax),%esi
lea    0xdf7(%rip),%rdi
call   1040 <mkfifo@plt>
cmp    $0x0,%rax
jge    126b <main+0xdb>
mov    0x2d88(%rip),%rax
mov    (%rax),%rax
mov    0x2d86(%rip),%rcx
cmp    (%rcx),%rax
je     126b <main+0xdb>
lea    0xdd3(%rip),%rdi
call   1080 <perror@plt>
lea    0xd9a(%rip),%rdi
call   1030 <unlink@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    12ea <main+0x15a>
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
lea    0xd72(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    12ab <main+0x11b>
lea    0xd9c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
lea    0xd66(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    12d8 <main+0x148>
lea    0xd6f(%rip),%rdi
call   1080 <perror@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <server@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
lea    0xd06(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1321 <main+0x191>
lea    0xd43(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%esi
lea    0xcf0(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1358 <main+0x1c8>
lea    0xd0c(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <client@plt>
mov    -0x10(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
lea    0xc88(%rip),%rdi
call   1030 <unlink@plt>
lea    0xc9d(%rip),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e12(%rip),%r14
mov    0x2e3b(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r14),%esi
mov    0x2e0e(%rip),%r15
or     (%r15),%esi
mov    0x2dfc(%rip),%rbx
or     (%rbx),%esi
lea    0xe3b(%rip),%rdi
call   1040 <mkfifo@plt>
test   %rax,%rax
jns    11f1 <main+0x61>
mov    0x2df2(%rip),%rax
mov    (%rax),%rax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
je     11f1 <main+0x61>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
mov    0x0(%rbp),%esi
or     (%r14),%esi
or     (%r15),%esi
or     (%rbx),%esi
lea    0xe1e(%rip),%rdi
call   1040 <mkfifo@plt>
test   %rax,%rax
jns    123b <main+0xab>
mov    0x2db4(%rip),%rax
mov    (%rax),%rax
mov    0x2db2(%rip),%rcx
cmp    (%rcx),%rax
je     123b <main+0xab>
lea    0xe03(%rip),%rdi
call   1080 <perror@plt>
lea    0xdca(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
jne    12a6 <main+0x116>
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
lea    0xdaa(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    126e <main+0xde>
lea    0xdd9(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
lea    0xda3(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1296 <main+0x106>
lea    0xdb1(%rip),%rdi
call   1080 <perror@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <server@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    %eax,%ebx
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
lea    0xd48(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     12de <main+0x14e>
mov    %eax,%ebp
mov    0x2cd5(%rip),%rax
mov    (%rax),%esi
lea    0xd4d(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    12f4 <main+0x164>
lea    0xd70(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1090 <client@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
lea    0xcf1(%rip),%rdi
call   1030 <unlink@plt>
lea    0xd06(%rip),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   10a0 <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
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [21 x i8] c"Can't create Fifo1: \00"
@.str.2 = [12 x i8] c"/tmp/fifo.2\00"
@.str.3 = [21 x i8] c"Can't create Fifo2: \00"
@O_WRONLY = global i32 0
@.str.4 = [19 x i8] c"Can't opem Fifo1: \00"
@O_RDONLY = global i32 0
@.str.5 = [12 x i8] c"Open Readfd\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%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 ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %0
%15 = load i64, i64* @errno
%16 = load i64, i64* @EEXIST
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14, %0
%21 = load i32, i32* @S_IRUSR
%22 = load i32, i32* @S_IWUSR
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IRGRP
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IROTH
%27 = or i32 %25, %26
%28 = call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %20
%31 = load i64, i64* @errno
%32 = load i64, i64* @EEXIST
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %34, %30, %20
%38 = call i32 (...) @fork()
store i32 %38, i32* %4
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %57
40: ; preds = %37
%41 = load i32, i32* @O_WRONLY
%42 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %41)
store i32 %42, i32* %3
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = load i32, i32* @O_RDONLY
%48 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %47)
store i32 %48, i32* %2
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = load i32, i32* %2
%54 = load i32, i32* %3
%55 = call i32 @server(i32 %53, i32 %54)
%56 = call i32 @exit(i32 0)
unreachable
57: ; preds = %37
%58 = load i32, i32* @O_RDONLY
%59 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %58)
store i32 %59, i32* %2
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %57
%65 = load i32, i32* @O_WRONLY
%66 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %65)
store i32 %66, i32* %3
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%70 = call i32 @exit(i32 -1)
unreachable
71: ; preds = %64
%72 = load i32, i32* %2
%73 = load i32, i32* %3
%74 = call i32 @client(i32 %72, i32 %73)
%75 = load i32, i32* %4
%76 = call i32 @waitpid(i32 %75, i32* null, i32 0)
%77 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%78 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%79 = call i32 @exit(i32 0)
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
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [21 x i8] c"Can't create Fifo1: \00"
@.str.2 = [12 x i8] c"/tmp/fifo.2\00"
@.str.3 = [21 x i8] c"Can't create Fifo2: \00"
@O_WRONLY = global i32 0
@.str.4 = [19 x i8] c"Can't opem Fifo1: \00"
@O_RDONLY = global i32 0
@.str.5 = [12 x i8] c"Open Readfd\00"
define i32 @main() {
%1 = load i32, i32* @S_IRUSR
%2 = load i32, i32* @S_IWUSR
%3 = or i32 %2, %1
%4 = load i32, i32* @S_IRGRP
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IROTH
%7 = or i32 %5, %6
%8 = tail call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load i64, i64* @errno
%12 = load i64, i64* @EEXIST
%13 = icmp eq i64 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10, %0
%17 = load i32, i32* @S_IRUSR
%18 = load i32, i32* @S_IWUSR
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IRGRP
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IROTH
%23 = or i32 %21, %22
%24 = tail call i64 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %16
%27 = load i64, i64* @errno
%28 = load i64, i64* @EEXIST
%29 = icmp eq i64 %27, %28
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %30, %26, %16
%34 = tail call i32 (...) @fork()
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %51
36: ; preds = %33
%37 = load i32, i32* @O_WRONLY
%38 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %36
%43 = load i32, i32* @O_RDONLY
%44 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = tail call i32 @server(i32 %44, i32 %38)
%50 = tail call i32 @exit(i32 0)
unreachable
51: ; preds = %33
%52 = load i32, i32* @O_RDONLY
%53 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%57 = tail call i32 @exit(i32 -1)
unreachable
58: ; preds = %51
%59 = load i32, i32* @O_WRONLY
%60 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%64 = tail call i32 @exit(i32 -1)
unreachable
65: ; preds = %58
%66 = tail call i32 @client(i32 %53, i32 %60)
%67 = tail call i32 @waitpid(i32 %34, i32* null, i32 0)
%68 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%69 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%70 = tail call i32 @exit(i32 0)
unreachable
}