#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*/ F_OK;
int /*<<< orphan*/ O_RDONLY;
int PIPE_BUF;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int main(void) {
  char buf[PIPE_BUF];
  int fd;
  if (access("/tmp/myfifo", F_OK) == -1)
    mkfifo("/tmp/myfifo", 0666);
  fd = open("/tmp/myfifo", O_RDONLY);
  while (1) {
    bzero(buf, PIPE_BUF);
    if (read(fd, buf, PIPE_BUF) == 0)
      break;
    printf("%s", buf);
  }
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%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    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    11ea <main+0x6a>
lea    0xe20(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <mkfifo@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
lea    0xe06(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
jmp    1207 <main+0x87>
mov    -0x28(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
call   1090 <bzero@plt>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jne    123d <main+0xbd>
jmp    1252 <main+0xd2>
mov    -0x28(%rbp),%rsi
lea    0xdc4(%rip),%rdi
call   1030 <printf@plt>
jmp    1202 <main+0x82>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e43(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    11d5 <main+0x55>
lea    0xe35(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <mkfifo@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
lea    0xe1b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
mov    0x0(%r13),%r15d
mov    %r12,%rdi
mov    %r15d,%esi
call   1090 <bzero@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1050 <read@plt>
test   %rax,%rax
je     124b <main+0xcb>
lea    0xdf6(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
mov    0x0(%r13),%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1090 <bzero@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <read@plt>
test   %rax,%rax
jne    1220 <main+0xa0>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@PIPE_BUF = global i32 0
@.str = [12 x i8] c"/tmp/myfifo\00"
@F_OK = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%s\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* @PIPE_BUF
%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* @F_OK
%10 = call i32 @access(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 438)
br label %14
14: ; preds = %12, %0
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %4
br label %17
17: ; preds = %26, %14
br label %18
18: ; preds = %17
%19 = load i32, i32* @PIPE_BUF
%20 = call i32 @bzero(i8* %8, i32 %19)
%21 = load i32, i32* %4
%22 = load i32, i32* @PIPE_BUF
%23 = call i64 @read(i32 %21, i8* %8, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %18
br label %28
26: ; preds = %18
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %17
28: ; preds = %25
%29 = load i32, i32* %4
%30 = call i32 @close(i32 %29)
%31 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@PIPE_BUF = global i32 0
@.str = [12 x i8] c"/tmp/myfifo\00"
@F_OK = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = load i32, i32* @PIPE_BUF
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = load i32, i32* @F_OK
%5 = tail call i32 @access(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 438)
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @PIPE_BUF
%13 = call i32 @bzero(i8* %3, i32 %12)
%14 = call i64 @read(i32 %11, i8* %3, i32 %12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %9, %16
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%18 = load i32, i32* @PIPE_BUF
%19 = call i32 @bzero(i8* %3, i32 %18)
%20 = call i64 @read(i32 %11, i8* %3, i32 %18)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %16
22: ; preds = %16, %9
%23 = call i32 @close(i32 %11)
%24 = call i32 @exit(i32 0)
unreachable
}