#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*/ fputs(char *, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int writer, reader, i;
  char p[100], c[1000], ch;
  printf(" Status: Waiting for Server... \n ");
  mknod("/tmp/fifo1", S_IFIFO | 777, 0);
  mknod("/tmp/fifo2", S_IFIFO | 777, 0);
  writer = open("/tmp/fifo1", O_WRONLY);
  printf(" Status: Server seems to be active. \n ");
  printf(" Enter file name to read from: ");
  i = 0;
  while (1) {
    ch = getchar();
    if (ch == '\n')
      break;
    p[i++] = ch;
  }
  p[i] = '\0';
  write(writer, p, strlen(p));
  reader = open("/tmp/fifo2", O_RDONLY);
  read(reader, c, 1000);
  printf(" Status: Server Responded. \n ");
  printf(" Status: Displaying Contents... \n ");
  fputs(c, stdout);
  printf("\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
or     $0x309,%esi
lea    0xe6e(%rip),%rdi
xor    %edx,%edx
call   1090 <mknod@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
or     $0x309,%esi
lea    0xe5c(%rip),%rdi
xor    %edx,%edx
call   1090 <mknod@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    0xe3a(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe41(%rip),%rdi
call   1050 <printf@plt>
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x471(%rbp)
movsbl -0x471(%rbp),%eax
cmp    $0xa,%eax
jne    1231 <main+0xb1>
jmp    124d <main+0xcd>
mov    -0x471(%rbp),%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0x80(%rbp,%rax,1)
jmp    120f <main+0x8f>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
mov    %eax,-0x484(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x480(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x484(%rbp),%edi
mov    -0x480(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
lea    0xd96(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x470(%rbp),%rsi
mov    $0x3e8,%edx
call   1070 <read@plt>
lea    0xdc5(%rip),%rdi
call   1050 <printf@plt>
lea    0xdd7(%rip),%rdi
call   1050 <printf@plt>
lea    -0x470(%rbp),%rdi
mov    0x2cff(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
lea    0xdd9(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x458,%rsp
lea    0xe5c(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e20(%rip),%rbp
mov    $0x309,%ebx
mov    0x0(%rbp),%esi
or     %ebx,%esi
lea    0xe61(%rip),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %edx,%edx
call   10a0 <mknod@plt>
or     0x0(%rbp),%ebx
lea    0xe55(%rip),%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   10a0 <mknod@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10b0 <open@plt>
mov    %eax,%r14d
lea    0xe3c(%rip),%rdi
call   1060 <printf@plt>
lea    0xe57(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0xa,%al
je     1235 <main+0xa5>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0xa,%al
jne    1220 <main+0x90>
mov    %ebx,%r15d
movb   $0x0,(%rsp,%r15,1)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
lea    0xdcb(%rip),%rdi
call   10b0 <open@plt>
lea    0x70(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1080 <read@plt>
lea    0xdfd(%rip),%rdi
call   1060 <printf@plt>
lea    0xe0f(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <fputs@plt>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x458,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c" Status: Waiting for Server... \0A \00"
@.str.1 = [11 x i8] c"/tmp/fifo1\00"
@S_IFIFO = global i32 0
@.str.2 = [11 x i8] c"/tmp/fifo2\00"
@O_WRONLY = global i32 0
@.str.3 = [39 x i8] c" Status: Server seems to be active. \0A \00"
@.str.4 = [32 x i8] c" Enter file name to read from: \00"
@O_RDONLY = global i32 0
@.str.5 = [30 x i8] c" Status: Server Responded. \0A \00"
@.str.6 = [35 x i8] c" Status: Displaying Contents... \0A \00"
@stdout = global i32 0
@.str.7 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca [1000 x i8]
%7 = alloca i8
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @S_IFIFO
%10 = or i32 %9, 777
%11 = call i32 @mknod(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 0)
%12 = load i32, i32* @S_IFIFO
%13 = or i32 %12, 777
%14 = call i32 @mknod(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 0)
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %16, i32* %2
%17 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %19
19: ; preds = %0, %25
%20 = call signext i8 (...) @getchar()
store i8 %20, i8* %7
%21 = load i8, i8* %7
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %25
24: ; preds = %19
br label %31
25: ; preds = %19
%26 = load i8, i8* %7
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %29
store i8 %26, i8* %30
br label %19
31: ; preds = %24
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* %2
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @write(i32 %35, i8* %36, i32 %38)
%40 = load i32, i32* @O_RDONLY
%41 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %40)
store i32 %41, i32* %3
%42 = load i32, i32* %3
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%44 = call i32 @read(i32 %42, i8* %43, i32 1000)
%45 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%47 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%48 = load i32, i32* @stdout
%49 = call i32 @fputs(i8* %47, i32 %48)
%50 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c" Status: Waiting for Server... \0A \00"
@.str.1 = [11 x i8] c"/tmp/fifo1\00"
@S_IFIFO = global i32 0
@.str.2 = [11 x i8] c"/tmp/fifo2\00"
@O_WRONLY = global i32 0
@.str.3 = [39 x i8] c" Status: Server seems to be active. \0A \00"
@.str.4 = [32 x i8] c" Enter file name to read from: \00"
@O_RDONLY = global i32 0
@.str.5 = [30 x i8] c" Status: Server Responded. \0A \00"
@.str.6 = [35 x i8] c" Status: Displaying Contents... \0A \00"
@stdout = global i32 0
@str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @S_IFIFO
%7 = or i32 %6, 777
%8 = tail call i32 @mknod(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 0)
%9 = load i32, i32* @S_IFIFO
%10 = or i32 %9, 777
%11 = tail call i32 @mknod(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 0)
%12 = load i32, i32* @O_WRONLY
%13 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call signext i8 (...) @getchar()
%17 = icmp eq i8 %16, 10
br i1 %17, label %27, label %18
18: ; preds = %0, %18
%19 = phi i64 [ %21, %18 ], [ 0, %0 ]
%20 = phi i8 [ %23, %18 ], [ %16, %0 ]
%21 = add nuw i64 %19, 1
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %19
store i8 %20, i8* %22
%23 = tail call signext i8 (...) @getchar()
%24 = icmp eq i8 %23, 10
br i1 %24, label %25, label %18
25: ; preds = %18
%26 = and i64 %21, 4294967295
br label %27
27: ; preds = %25, %0
%28 = phi i64 [ 0, %0 ], [ %26, %25 ]
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %28
store i8 0, i8* %29
%30 = call i32 @strlen(i8* %3)
%31 = call i32 @write(i32 %13, i8* %3, i32 %30)
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = call i32 @read(i32 %33, i8* %4, i32 1000)
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%37 = load i32, i32* @stdout
%38 = call i32 @fputs(i8* %4, i32 %37)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}