#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 S_IFIFO;
int /*<<< orphan*/ feof(int /*<<< orphan*/);
scalar_t__ gets(char *);
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main() {
  char s[300];
  char resp_buff[1000];
  int num_read, num_write;
  mknod("cl_2_srvr", S_IFIFO | 0666, 0);
  int fd_c2s = open("cl_2_srvr", O_RDWR);
  mknod("srvr_2_cl", S_IFIFO | 0666, 0);
  int fd_s2c = open("srvr_2_cl", O_RDWR);
  printf("Created the pipe...\nEnter the filename:: ");
  while (gets(s), !feof(stdin)) {
    if ((num_read = write(fd_c2s, s, strlen(s))) == -1)
      perror("write");
    else {
      printf("CLIENT: Request sent to server :::bytes written :: %dBytes\n",
             num_read);
      break;
    }
  }
  do {
    if ((num_write = read(fd_s2c, resp_buff, 1000)) == -1)
      perror("read");
    else {
      s[num_write] = '\0';
      printf("CLIENT: Recieved : %dBytes\n\n\t\t=======SERVER "
             "RESPONSE========\n\n %s \n\n",
             num_write, resp_buff);
      break;
    }
  } while (num_write > 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe48(%rip),%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    0xe31(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x52c(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe1a(%rip),%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
lea    0xe03(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x530(%rbp)
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x130(%rbp),%rdi
call   1090 <gets@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    124f <main+0xbf>
jmp    12c7 <main+0x137>
mov    -0x52c(%rbp),%eax
mov    %eax,-0x53c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x538(%rbp)
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x53c(%rbp),%edi
mov    -0x538(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x524(%rbp)
cmp    $0xffffffff,%eax
jne    12a9 <main+0x119>
lea    0xd9f(%rip),%rdi
call   10b0 <perror@plt>
jmp    12c2 <main+0x132>
mov    -0x524(%rbp),%esi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c7 <main+0x137>
jmp    1220 <main+0x90>
jmp    12cc <main+0x13c>
mov    -0x530(%rbp),%edi
lea    -0x520(%rbp),%rsi
mov    $0x3e8,%edx
call   1060 <read@plt>
mov    %eax,-0x528(%rbp)
cmp    $0xffffffff,%eax
jne    1303 <main+0x173>
lea    0xd87(%rip),%rdi
call   10b0 <perror@plt>
jmp    1332 <main+0x1a2>
movslq -0x528(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x528(%rbp),%esi
lea    -0x520(%rbp),%rdx
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1344 <main+0x1b4>
jmp    1337 <main+0x1a7>
cmpl   $0x0,-0x528(%rbp)
jg     12cc <main+0x13c>
xor    %eax,%eax
add    $0x540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x520,%rsp
mov    0x2e2a(%rip),%r14
mov    $0x1b6,%ebp
mov    (%r14),%esi
or     %ebp,%esi
lea    0xe49(%rip),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
mov    0x2e20(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
mov    %eax,%r12d
or     (%r14),%ebp
lea    0xe2a(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1080 <mknod@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
mov    %eax,%r14d
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1090 <gets@plt>
mov    0x2dc9(%rip),%rbx
mov    (%rbx),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    1273 <main+0xe3>
mov    %rsp,%rbp
lea    0xe12(%rip),%r15
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1263 <main+0xd3>
mov    %r15,%rdi
call   10b0 <perror@plt>
mov    %rbp,%rdi
call   1090 <gets@plt>
mov    (%rbx),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     122c <main+0x9c>
jmp    1273 <main+0xe3>
lea    0xdda(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x130(%rsp),%rsi
mov    %r14d,%edi
mov    $0x3e8,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     12be <main+0x12e>
movslq %eax,%rcx
movb   $0x0,(%rsp,%rcx,1)
lea    0xdea(%rip),%rdi
lea    0x130(%rsp),%rdx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x520,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbb(%rip),%rdi
call   10b0 <perror@plt>
jmp    12ac <main+0x11c>

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 = [42 x i8] c"Created the pipe...\0AEnter the filename:: \00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [60 x i8] c"CLIENT: Request sent to server :::bytes written :: %dBytes\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [69 x i8] c"CLIENT: Recieved : %dBytes\0A\0A\09\09=======SERVER RESPONSE========\0A\0A %s \0A\0A\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
store i32 0, i32* %1
%8 = load i32, i32* @S_IFIFO
%9 = or i32 %8, 438
%10 = call i32 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9, i32 0)
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* @S_IFIFO
%14 = or i32 %13, 438
%15 = call i32 @mknod(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 0)
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 %17, i32* %7
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %38, %0
%20 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%21 = call i64 @gets(i8* %20)
%22 = load i32, i32* @stdin
%23 = call i32 @feof(i32 %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %39
26: ; preds = %19
%27 = load i32, i32* %6
%28 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%29 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @write(i32 %27, i8* %28, i32 %30)
store i32 %31, i32* %4
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %38
35: ; preds = %26
%36 = load i32, i32* %4
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i32 %36)
br label %39
38: ; preds = %33
br label %19
39: ; preds = %35, %19
br label %40
40: ; preds = %55, %39
%41 = load i32, i32* %7
%42 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%43 = call i32 @read(i32 %41, i8* %42, i32 1000)
store i32 %43, i32* %5
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %54
47: ; preds = %40
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 %49
store i8 0, i8* %50
%51 = load i32, i32* %5
%52 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 %51, i8* %52)
br label %58
54: ; preds = %45
br label %55
55: ; preds = %54
%56 = load i32, i32* %5
%57 = icmp sgt i32 %56, 0
br i1 %57, label %40, label %58
58: ; preds = %55, %47
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.2 = [42 x i8] c"Created the pipe...\0AEnter the filename:: \00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [60 x i8] c"CLIENT: Request sent to server :::bytes written :: %dBytes\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [69 x i8] c"CLIENT: Recieved : %dBytes\0A\0A\09\09=======SERVER RESPONSE========\0A\0A %s \0A\0A\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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%16 = call i64 @gets(i8* %3)
%17 = load i32, i32* @stdin
%18 = call i32 @feof(i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %0, %24
%21 = call i32 @strlen(i8* %3)
%22 = call i32 @write(i32 %9, i8* %3, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%26 = call i64 @gets(i8* %3)
%27 = load i32, i32* @stdin
%28 = call i32 @feof(i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %20, label %32
30: ; preds = %20
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i32 %22)
br label %32
32: ; preds = %24, %0, %30
%33 = call i32 @read(i32 %14, i8* %4, i32 1000)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %41
37: ; preds = %32
%38 = sext i32 %33 to i64
%39 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 %33, i8* %4)
br label %41
41: ; preds = %35, %37
ret i32 0
}