#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_RDONLY;
int /*<<< orphan*/ O_WRONLY;
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;
  int fd_WK, fd;
  mknod("WELL_KNOWN", S_IFIFO | 0666, 0);
  fd_WK = open("WELL_KNOWN", O_WRONLY);
  mknod("SRVR_2_CLB", S_IFIFO | 0666, 0);
  fd = open("SRVR_2_CLB", O_RDONLY);
  printf("Created the pipe...\nEnter some text:: ");
  while (gets(s), !feof(stdin)) {
    if ((num_read = write(fd_WK, s, strlen(s))) == -1)
      perror("write");
    else {
      printf("CLIENT: Request sent to server ::: %d B written\n", num_read);
      break;
    }
  }
  if ((num_write = read(fd, resp_buff, 1000)) == -1)
    perror("read");
  else {
    s[num_write] = '\0';
    printf("CLIENT: %d B Recieved\nSERVER RESPONSE:\n%s", num_write, resp_buff);
  }
  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    0x2dfa(%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    0xe1b(%rip),%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
lea    0xe04(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x530(%rbp)
lea    0xdfd(%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    0xd9e(%rip),%rdi
call   10b0 <perror@plt>
jmp    12c2 <main+0x132>
mov    -0x524(%rbp),%esi
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c7 <main+0x137>
jmp    1220 <main+0x90>
mov    -0x530(%rbp),%edi
lea    -0x520(%rbp),%rsi
mov    $0x3e8,%edx
call   1060 <read@plt>
mov    %eax,-0x528(%rbp)
cmp    $0xffffffff,%eax
jne    12fe <main+0x16e>
lea    0xd80(%rip),%rdi
call   10b0 <perror@plt>
jmp    1328 <main+0x198>
movslq -0x528(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x528(%rbp),%esi
lea    -0x520(%rbp),%rdx
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
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),%r15
mov    $0x1b6,%ebx
mov    (%r15),%esi
or     %ebx,%esi
lea    0xe49(%rip),%rbp
mov    %rbp,%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10a0 <open@plt>
mov    %eax,%r14d
or     (%r15),%ebx
lea    0xe2c(%rip),%rbp
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1080 <mknod@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
lea    0xe11(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1090 <gets@plt>
mov    0x2dc5(%rip),%r12
mov    (%r12),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    127b <main+0xeb>
mov    %rsp,%rbx
lea    0xe0b(%rip),%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    126b <main+0xdb>
mov    %r15,%rdi
call   10b0 <perror@plt>
mov    %rbx,%rdi
call   1090 <gets@plt>
mov    (%r12),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     1232 <main+0xa2>
jmp    127b <main+0xeb>
lea    0xdd1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x130(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3e8,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     12c5 <main+0x135>
movslq %eax,%rcx
movb   $0x0,(%rsp,%rcx,1)
lea    0xdd7(%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    0xda8(%rip),%rdi
call   10b0 <perror@plt>
jmp    12b3 <main+0x123>

LLVM IR (-O0):
@.str = [11 x i8] c"WELL_KNOWN\00"
@S_IFIFO = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [11 x i8] c"SRVR_2_CLB\00"
@O_RDONLY = global i32 0
@.str.2 = [39 x i8] c"Created the pipe...\0AEnter some text:: \00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [49 x i8] c"CLIENT: Request sent to server ::: %d B written\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [42 x i8] c"CLIENT: %d B Recieved\0ASERVER RESPONSE:\0A%s\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 ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9, i32 0)
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 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 ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 0)
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 %17, i32* %7
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 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 ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i32 %36)
br label %39
38: ; preds = %33
br label %19
39: ; preds = %35, %19
%40 = load i32, i32* %7
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 1000)
store i32 %42, i32* %5
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %53
46: ; preds = %39
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 %48
store i8 0, i8* %49
%50 = load i32, i32* %5
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i32 %50, i8* %51)
br label %53
53: ; preds = %46, %44
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"WELL_KNOWN\00"
@S_IFIFO = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [11 x i8] c"SRVR_2_CLB\00"
@O_RDONLY = global i32 0
@.str.2 = [39 x i8] c"Created the pipe...\0AEnter some text:: \00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [49 x i8] c"CLIENT: Request sent to server ::: %d B written\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [42 x i8] c"CLIENT: %d B Recieved\0ASERVER RESPONSE:\0A%s\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 ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = load i32, i32* @O_WRONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 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 ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 0)
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 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 ([49 x i8], [49 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 ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i32 %33, i8* %4)
br label %41
41: ; preds = %37, %35
ret i32 0
}