#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*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ strcmp(char *, char *);
int main(void) {
  char buffer[128];
  char fifoname[] = "myfifo";
  int fifofd;
  fifofd = open(fifoname, O_RDONLY);
  printf("Reading FIFO:\n");
  do {
    read(fifofd, buffer, sizeof(buffer));
    printf("%s", buffer);
  } while (strcmp(buffer, "exit\n") != 0);
  close(fifofd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe98(%rip),%eax
mov    %eax,-0x97(%rbp)
mov    0xe8f(%rip),%ax
mov    %ax,-0x93(%rbp)
mov    0xe84(%rip),%al
mov    %al,-0x91(%rbp)
lea    -0x97(%rbp),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x9c(%rbp)
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x9c(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
lea    -0x90(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11b1 <main+0x61>
mov    -0x9c(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
movl   $0x6f6669,0xb(%rsp)
movl   $0x6966796d,0x8(%rsp)
69
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbx
lea    0xe5d(%rip),%r14
lea    0xe59(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1060 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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