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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2a(%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)
lea    0xe2e(%rip),%rdi
mov    $0x1b6,%esi
call   10a0 <mkfifo@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    0xe14(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%edx
lea    0xdf8(%rip),%rsi
call   1080 <dprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
lea    0xdd6(%rip),%rdi
call   10b0 <open@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d90(%rip),%rax
mov    (%rax),%edx
call   1090 <read@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
call   1060 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
lea    0xd87(%rip),%rdi
call   1030 <unlink@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    0x2e2e(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe42(%rip),%r14
mov    %r14,%rdi
mov    $0x1b6,%esi
call   10a0 <mkfifo@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10b0 <open@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe18(%rip),%rsi
mov    %r15d,%edi
mov    %eax,%edx
call   1080 <dprintf@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10b0 <open@plt>
mov    %eax,%r15d
mov    (%r12),%edx
mov    %eax,%edi
mov    %rbx,%rsi
call   1090 <read@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%r12d
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %r14,%rdi
call   1030 <unlink@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_WRONLY = global i32 0
@.str.1 = [29 x i8] c"Message from pid %d: Hello!\0A\00"
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
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 = call i32 @mkfifo(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 438)
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = call i32 (...) @getpid()
%14 = call i32 @dprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %4
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = load i32, i32* @BUFSIZ
%21 = call i32 @read(i32 %19, i8* %8, i32 %20)
%22 = load i32, i32* @STDOUT_FILENO
%23 = call i32 @strlen(i8* %8)
%24 = call i32 @write(i32 %22, i8* %8, i32 %23)
%25 = load i32, i32* %4
%26 = call i32 @close(i32 %25)
%27 = call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
%28 = load i8*, i8** %2
%29 = load i32, i32* %1
ret i32 %29
}

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