#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 void *ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int S_IFIFO;
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void *read(int, char *, int);
int write(int, char *, void *);
int main() {
  char s[300];
  char resp_buff[1000];
  int num_read, num_write;
  int fd_c2s, fd_s2c;
  mknod("cl_2_srvr", S_IFIFO | 0666, 0);
  fd_c2s = open("cl_2_srvr", O_RDWR);
  mknod("srvr_2_cl", S_IFIFO | 0666, 0);
  fd_s2c = open("srvr_2_cl", O_RDWR);
  printf("SERVER: Ready to Recieve Requests...\n");
  do {
    if ((num_read = read(fd_c2s, s, 300)) == -1)
      perror("read");
    else {
      s[num_read] = '\0';
      printf("SERVER: bytes written : %d bytes \nSERVER: Requested File is "
             "::\"%s\"\n",
             num_read, s);
      break;
    }
  } while (num_read > 0);
  printf("\nSERVER: Processing the request...\n");
  int fdfile = open(s, O_RDONLY);
  ssize_t len = read(fdfile, resp_buff, 1000);
  int red = write(fd_s2c, resp_buff, len);
  if (red == -1)
    perror("SERVER: No Such File");
  else
    printf("SERVER: Responded Succesfully\nSERVER: Bytes written :: %d B", red);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x550,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe78(%rip),%rdi
xor    %edx,%edx
call   1060 <mknod@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x52c(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe4a(%rip),%rdi
xor    %edx,%edx
call   1060 <mknod@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
lea    0xe33(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x530(%rbp)
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x52c(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x12c,%edx
call   1050 <read@plt>
mov    %eax,-0x524(%rbp)
cmp    $0xffffffff,%eax
jne    1227 <main+0xc7>
lea    0xe1d(%rip),%rdi
call   1080 <perror@plt>
jmp    1256 <main+0xf6>
movslq -0x524(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x524(%rbp),%esi
lea    -0x130(%rbp),%rdx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1268 <main+0x108>
jmp    125b <main+0xfb>
cmpl   $0x0,-0x524(%rbp)
jg     11f0 <main+0x90>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x130(%rbp),%rdi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x534(%rbp)
mov    -0x534(%rbp),%edi
lea    -0x520(%rbp),%rsi
mov    $0x3e8,%edx
call   1050 <read@plt>
mov    %rax,-0x540(%rbp)
mov    -0x530(%rbp),%edi
lea    -0x520(%rbp),%rsi
mov    -0x540(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x544(%rbp)
cmpl   $0xffffffff,-0x544(%rbp)
jne    12ec <main+0x18c>
lea    0xdc5(%rip),%rdi
call   1080 <perror@plt>
jmp    1300 <main+0x1a0>
mov    -0x544(%rbp),%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x518,%rsp
mov    0x2e4c(%rip),%rbp
mov    $0x1b6,%ebx
mov    0x0(%rbp),%esi
or     %ebx,%esi
lea    0xe6b(%rip),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1070 <mknod@plt>
mov    0x2e42(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1080 <open@plt>
mov    %eax,%r14d
or     0x0(%rbp),%ebx
lea    0xe4c(%rip),%rbp
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1070 <mknod@plt>
mov    (%r15),%esi
mov    %rbp,%rdi
call   1080 <open@plt>
mov    %eax,%ebx
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x12c,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     127c <main+0x10c>
movslq %eax,%rcx
movb   $0x0,(%rsp,%rcx,1)
lea    0xe0f(%rip),%rdi
mov    %rsp,%rdx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1080 <open@plt>
lea    0x130(%rsp),%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x3e8,%edx
call   1060 <read@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     128a <main+0x11a>
lea    0xe0f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x518,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd91(%rip),%rdi
call   1090 <perror@plt>
jmp    1216 <main+0xa6>
lea    0xdcc(%rip),%rdi
call   1090 <perror@plt>
jmp    126c <main+0xfc>

LLVM IR (-O0):
@.str = [10 x i8] c"cl_2_srvr\00"
@S_IFIFO = global i32 0
@O_RDWR = global i32 0
@.str.1 = [10 x i8] c"srvr_2_cl\00"
@.str.2 = [38 x i8] c"SERVER: Ready to Recieve Requests...\0A\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [68 x i8] c"SERVER: bytes written : %d bytes \0ASERVER: Requested File is ::\22%s\22\0A\00"
@.str.5 = [36 x i8] c"\0ASERVER: Processing the request...\0A\00"
@O_RDONLY = global i32 0
@.str.6 = [21 x i8] c"SERVER: No Such File\00"
@.str.7 = [60 x i8] c"SERVER: Responded Succesfully\0ASERVER: Bytes written :: %d B\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [300 x i8]
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %1
%11 = load i32, i32* @S_IFIFO
%12 = or i32 %11, 438
%13 = call i32 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12, i32 0)
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* @S_IFIFO
%17 = or i32 %16, 438
%18 = call i32 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 0)
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %38, %0
%23 = load i32, i32* %6
%24 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%25 = call i8* @read(i32 %23, i8* %24, i32 300)
%26 = ptrtoint i8* %25 to i32
store i32 %26, i32* %4
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %37
30: ; preds = %22
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 %32
store i8 0, i8* %33
%34 = load i32, i32* %4
%35 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i32 %34, i8* %35)
br label %41
37: ; preds = %28
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = icmp sgt i32 %39, 0
br i1 %40, label %22, label %41
41: ; preds = %38, %30
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%43 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%44 = load i32, i32* @O_RDONLY
%45 = call i32 @open(i8* %43, i32 %44)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%48 = call i8* @read(i32 %46, i8* %47, i32 1000)
store i8* %48, i8** %9
%49 = load i32, i32* %7
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%51 = load i8*, i8** %9
%52 = call i32 @write(i32 %49, i8* %50, i8* %51)
store i32 %52, i32* %10
%53 = load i32, i32* %10
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %41
%56 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %60
57: ; preds = %41
%58 = load i32, i32* %10
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %57, %55
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"cl_2_srvr\00"
@S_IFIFO = global i32 0
@O_RDWR = global i32 0
@.str.1 = [10 x i8] c"srvr_2_cl\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [68 x i8] c"SERVER: bytes written : %d bytes \0ASERVER: Requested File is ::\22%s\22\0A\00"
@O_RDONLY = global i32 0
@.str.6 = [21 x i8] c"SERVER: No Such File\00"
@.str.7 = [60 x i8] c"SERVER: Responded Succesfully\0ASERVER: Bytes written :: %d B\00"
@str = [37 x i8] c"SERVER: Ready to Recieve Requests...\00"
@str.8 = [35 x i8] c"\0ASERVER: Processing the request...\00"
define i32 @main() {
%1 = alloca [300 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @S_IFIFO
%6 = or i32 %5, 438
%7 = tail call i32 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @S_IFIFO
%11 = or i32 %10, 438
%12 = tail call i32 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 0)
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%16 = call i8* @read(i32 %9, i8* %3, i32 300)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %27
22: ; preds = %0
%23 = shl i64 %17, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i32 %18, i8* %3)
br label %27
27: ; preds = %20, %22
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.8, i64 0, i64 0))
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* %3, i32 %29)
%31 = call i8* @read(i32 %30, i8* %4, i32 1000)
%32 = call i32 @write(i32 %14, i8* %4, i8* %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %38
36: ; preds = %27
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0), i32 %32)
br label %38
38: ; preds = %36, %34
ret i32 0
}