#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int main() {
  int len = 0;
  char buf[10];
  memset(buf, 0, sizeof(buf));
  int fd = open("fifo_file", O_RDONLY);
  while ((len = read(fd, buf, sizeof(buf))) > 0) {
    printf("%s\n", buf);
    memset(buf, 0, sizeof(buf));
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11d0 <main+0x80>
lea    -0x12(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
jmp    118e <main+0x3e>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11dd <main+0x8d>
lea    0xe6d(%rip),%r14
lea    0x6(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11b0 <main+0x60>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"fifo_file\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 10)
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
br label %9
9: ; preds = %14, %0
%10 = load i32, i32* %4
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 10)
store i32 %12, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 10)
br label %9
19: ; preds = %9
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"fifo_file\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 10)
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @read(i32 %5, i8* %2, i32 10)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0, %8
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%10 = call i32 @memset(i8* %2, i32 0, i32 10)
%11 = call i32 @read(i32 %5, i8* %2, i32 10)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %8, label %13
13: ; preds = %8, %0
%14 = call i32 @close(i32 %5)
ret i32 0
}