#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_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char *fifo_path = "pipe";
  int fd = open(fifo_path, O_WRONLY);
  if (fd == -1) {
    perror("open fifo");
    exit(1);
  }
  char buff[10];
  int n = read(0, buff, 10);
  while (n > 0) {
    write(fd, buff, n);
    n = read(0, buff, 10);
  }
  printf("EOF\n");
  close(fd);
  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    0xe73(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11c6 <main+0x56>
lea    0xe4e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x26(%rbp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    120a <main+0x9a>
mov    -0x1c(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <write@plt>
lea    -0x26(%rbp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
jmp    11d9 <main+0x69>
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11eb <main+0x7b>
mov    %eax,%ebp
lea    0xe(%rsp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11cf <main+0x5f>
lea    0xe(%rsp),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11b0 <main+0x40>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@O_WRONLY = 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 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%20 = call i32 @read(i32 0, i8* %19, i32 10)
store i32 %20, i32* %9
br label %21
21: ; preds = %24, %18
%22 = load i32, i32* %9
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %7
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* %9
%28 = call i32 @write(i32 %25, i8* %26, i32 %27)
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%30 = call i32 @read(i32 0, i8* %29, i32 10)
store i32 %30, i32* %9
br label %21
31: ; preds = %21
%32 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* %7
%34 = call i32 @close(i32 %33)
ret i32 0
}

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