#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int FIFO_server, FIFO_client;
  int choice;
  char *buf;
  FIFO_server = open("FIFO-server", O_RDWR);
  if (FIFO_server < 0) {
    fprintf(stderr, "Error opening server side FIFO file");
    exit(-1);
  }
  read(FIFO_server, &choice, sizeof(int));
  sleep(1);
  FIFO_client = open("FIFO-client", O_RDWR);
  if (FIFO_client < 0) {
    fprintf(stderr, "Error opening client side FIFO file");
    exit(-1);
  }
  switch (choice) {
  case 1:
    buf = "Linux";
    break;
  case 2:
    buf = "Debian";
    break;
  case 3:
    buf = "4.0";
  }
  write(FIFO_client, buf, 10 * sizeof(char));
  printf("\n### Data sent to client ###\n");
  close(FIFO_server);
  close(FIFO_client);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11d0 <main+0x50>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    122c <main+0xac>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     1262 <main+0xe2>
jmp    1240 <main+0xc0>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1272 <main+0xf2>
jmp    1251 <main+0xd1>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     1282 <main+0x102>
jmp    128d <main+0x10d>
lea    0xdf7(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    128d <main+0x10d>
lea    0xded(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    128d <main+0x10d>
lea    0xde4(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
lea    0xdcc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe6c(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1229 <main+0xa9>
mov    %eax,%ebx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1060 <read@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    0x0(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     123b <main+0xbb>
mov    %eax,%ebp
mov    0x4(%rsp),%eax
cmp    $0x2,%eax
lea    0xe85(%rip),%rcx
lea    0xe78(%rip),%rdx
cmove  %rcx,%rdx
cmp    $0x3,%eax
lea    0xe77(%rip),%rsi
cmovne %rdx,%rsi
mov    %ebp,%edi
mov    $0xa,%edx
call   1040 <write@plt>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
jmp    124b <main+0xcb>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"FIFO-server\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [36 x i8] c"Error opening server side FIFO file\00"
@.str.2 = [12 x i8] c"FIFO-client\00"
@.str.3 = [36 x i8] c"Error opening client side FIFO file\00"
@.str.4 = [6 x i8] c"Linux\00"
@.str.5 = [7 x i8] c"Debian\00"
@.str.6 = [4 x i8] c"4.0\00"
@.str.7 = [30 x i8] c"\0A### Data sent to client ###\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = load i32, i32* %2
%16 = call i32 @read(i32 %15, i32* %4, i32 4)
%17 = call i32 @sleep(i32 1)
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %14
%27 = load i32, i32* %4
switch i32 %27, label %31 [
i32 1, label %28
i32 2, label %29
i32 3, label %30
]
28: ; preds = %26
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %5
br label %31
29: ; preds = %26
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8** %5
br label %31
30: ; preds = %26
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %5
br label %31
31: ; preds = %30, %26, %29, %28
%32 = load i32, i32* %3
%33 = load i8*, i8** %5
%34 = call i32 @write(i32 %32, i8* %33, i32 10)
%35 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%36 = load i32, i32* %2
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %3
%39 = call i32 @close(i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"FIFO-server\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [36 x i8] c"Error opening server side FIFO file\00"
@.str.2 = [12 x i8] c"FIFO-client\00"
@.str.3 = [36 x i8] c"Error opening client side FIFO file\00"
@.str.4 = [6 x i8] c"Linux\00"
@.str.5 = [7 x i8] c"Debian\00"
@.str.6 = [4 x i8] c"4.0\00"
@str = [29 x i8] c"\0A### Data sent to client ###\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = call i32 @read(i32 %4, i32* %1, i32 4)
%12 = tail call i32 @sleep(i32 1)
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %10
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, 2
%23 = select i1 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%24 = icmp eq i32 %21, 3
%25 = select i1 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %23
%26 = tail call i32 @write(i32 %14, i8* %25, i32 10)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%28 = tail call i32 @close(i32 %4)
%29 = tail call i32 @close(i32 %14)
ret i32 0
}