#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 BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dprintf(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ getpid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(void) {
  char buf[BUFSIZ];
  int fd;
  fd = open("fifo", O_RDONLY);
  read(fd, buf, BUFSIZ);
  write(STDOUT_FILENO, buf, strlen(buf));
  close(fd);
  fd = open("fifo", O_WRONLY);
  dprintf(fd, "Reply from pid %d: Hello.\n", getpid());
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1090 <open@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
lea    0xded(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xdd1(%rip),%rsi
call   1070 <dprintf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e4e(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe59(%rip),%r14
mov    %r14,%rdi
call   1090 <open@plt>
mov    %eax,%r15d
mov    (%r12),%edx
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <read@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%r12d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <open@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdfd(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1070 <dprintf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [5 x i8] c"fifo\00"
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [27 x i8] c"Reply from pid %d: Hello.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %2
%8 = alloca i8, i64 %6
store i64 %6, i64* %3
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = load i32, i32* @BUFSIZ
%13 = call i32 @read(i32 %11, i8* %8, i32 %12)
%14 = load i32, i32* @STDOUT_FILENO
%15 = call i32 @strlen(i8* %8)
%16 = call i32 @write(i32 %14, i8* %8, i32 %15)
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* @O_WRONLY
%20 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = call i32 (...) @getpid()
%23 = call i32 @dprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
store i32 0, i32* %1
%26 = load i8*, i8** %2
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [5 x i8] c"fifo\00"
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [27 x i8] c"Reply from pid %d: Hello.\0A\00"
define i32 @main() {
%1 = load i32, i32* @BUFSIZ
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @BUFSIZ
%7 = call i32 @read(i32 %5, i8* %3, i32 %6)
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @strlen(i8* %3)
%10 = call i32 @write(i32 %8, i8* %3, i32 %9)
%11 = call i32 @close(i32 %5)
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 (...) @getpid()
%15 = call i32 @dprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @close(i32 %13)
ret i32 0
}