#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 int /*<<< orphan*/ fname;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ write(int, char *, int, ...);
int main() {
  char fname[50], buffer[1025];
  int request, response, n;
  request = open("request.fifo", O_WRONLY);
  response = open("response.fifo", O_RDONLY);
  printf("Enter a filename to request: ");
  scanf("%s", fname);
  write(request, fname, sizeof(fname), 0);
  printf("Received response: \n");
  while ((n = read(response, buffer, sizeof(buffer), 0)) > 0) {
    write(1, buffer, n);
  }
  close(request);
  close(response);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x454(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x458(%rbp)
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x454(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x32,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1030 <write@plt>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    -0x458(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x401,%edx
xor    %ecx,%ecx
call   1060 <read@plt>
mov    %eax,-0x45c(%rbp)
cmp    $0x0,%eax
jle    122e <main+0xce>
lea    -0x450(%rbp),%rsi
mov    -0x45c(%rbp),%edx
mov    $0x1,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    11e8 <main+0x88>
mov    -0x454(%rbp),%edi
call   1050 <close@plt>
mov    -0x458(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x450,%rsp
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r14d
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x32,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <write@plt>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
lea    0x40(%rsp),%rsi
mov    %ebp,%edi
mov    $0x401,%edx
xor    %ecx,%ecx
call   1070 <read@plt>
test   %eax,%eax
jle    1236 <main+0xc6>
lea    0x40(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x401,%edx
xor    %ecx,%ecx
call   1070 <read@plt>
test   %eax,%eax
jg     1210 <main+0xa0>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"request.fifo\00"
@O_WRONLY = global i32 0
@.str.1 = [14 x i8] c"response.fifo\00"
@O_RDONLY = global i32 0
@.str.2 = [30 x i8] c"Enter a filename to request: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [21 x i8] c"Received response: \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca [1025 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %4
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%16 = call i32 (i32, i8*, i32, ...) @write(i32 %14, i8* %15, i32 50, i32 0)
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %23, %0
%19 = load i32, i32* %5
%20 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 1025, i32 0)
store i32 %21, i32* %6
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%25 = load i32, i32* %6
%26 = call i32 (i32, i8*, i32, ...) @write(i32 1, i8* %24, i32 %25)
br label %18
27: ; preds = %18
%28 = load i32, i32* %4
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"request.fifo\00"
@O_WRONLY = global i32 0
@.str.1 = [14 x i8] c"response.fifo\00"
@O_RDONLY = global i32 0
@.str.2 = [30 x i8] c"Enter a filename to request: \00"
@.str.3 = [3 x i8] c"%s\00"
@str = [20 x i8] c"Received response: \00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [1025 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%11 = call i32 (i32, i8*, i32, ...) @write(i32 %6, i8* %3, i32 50, i32 0)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%13 = call i32 @read(i32 %8, i8* %4, i32 1025, i32 0)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %0, %15
%16 = phi i32 [ %18, %15 ], [ %13, %0 ]
%17 = call i32 (i32, i8*, i32, ...) @write(i32 1, i8* %4, i32 %16)
%18 = call i32 @read(i32 %8, i8* %4, i32 1025, i32 0)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %15, %0
%21 = call i32 @close(i32 %6)
%22 = call i32 @close(i32 %8)
ret i32 0
}