#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char *fifo_path = "pipe";
  mkfifo(fifo_path, 0666);
  int fd = open(fifo_path, O_RDONLY);
  if (fd == -1) {
    perror("open fifo");
    exit(1);
  }
  char buff[10];
  int n = read(fd, buff, 10);
  while (n > 0) {
    write(1, buff, n);
    n = read(fd, buff, 10);
  }
  printf("EOF\n");
  close(fd);
  unlink(fifo_path);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1b6,%esi
call   1080 <mkfifo@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11f4 <main+0x64>
lea    0xe20(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    $0xa,%edx
call   1070 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    123c <main+0xac>
lea    -0x26(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    -0x1c(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    $0xa,%edx
call   1070 <read@plt>
mov    %eax,-0x2c(%rbp)
jmp    1208 <main+0x78>
lea    0xdcc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe63(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1080 <mkfifo@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     122a <main+0x9a>
mov    %eax,%ebp
lea    0xe(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1202 <main+0x72>
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     11e0 <main+0x50>
lea    0xe06(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xde4(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdd4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"open fifo\00"
@.str.2 = [5 x i8] c"EOF\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [10 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @mkfifo(i8* %10, i32 438)
%12 = load i8*, i8** %6
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* %7
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%23 = call i32 @read(i32 %21, i8* %22, i32 10)
store i32 %23, i32* %9
br label %24
24: ; preds = %27, %20
%25 = load i32, i32* %9
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%29 = load i32, i32* %9
%30 = call i32 @write(i32 1, i8* %28, i32 %29)
%31 = load i32, i32* %7
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 10)
store i32 %33, i32* %9
br label %24
34: ; preds = %24
%35 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = load i8*, i8** %6
%39 = call i32 @unlink(i8* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"open fifo\00"
@str = [4 x i8] c"EOF\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%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_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%13 = call i32 @read(i32 %6, i8* %12, i32 10)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11, %15
%16 = phi i32 [ %18, %15 ], [ %13, %11 ]
%17 = call i32 @write(i32 1, i8* %12, i32 %16)
%18 = call i32 @read(i32 %6, i8* %12, i32 10)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %15, %11
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @close(i32 %6)
%23 = tail call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret i32 0
}