#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_RDWR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char c;
  int file;
  for (;;) {
    usleep(1);
    file = open(argv[1], O_RDWR);
    if (file < 0) {
      fprintf(stderr, "Unable to open file\n");
      continue;
    }
    fprintf(stderr, "Opened fifo\n");
    while (read(file, &c, 1) == 1) {
      write(1, &c, 1);
    }
    fprintf(stderr, "Filed died\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1070 <usleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ad <main+0x5d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1166 <main+0x16>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    11f1 <main+0xa1>
mov    $0x1,%edx
lea    -0x11(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    11c2 <main+0x72>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1166 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    0x2e83(%rip),%r14
mov    0x2e6c(%rip),%r15
lea    0x7(%rsp),%rbx
lea    0xeaa(%rip),%r13
jmp    118b <main+0x3b>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %r13,%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <usleep@plt>
mov    0x8(%r12),%rdi
mov    (%r14),%esi
call   1060 <open@plt>
mov    (%r15),%edi
test   %eax,%eax
js     11f0 <main+0xa0>
mov    %eax,%ebp
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1180 <main+0x30>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11c0 <main+0x70>
nopl   0x0(%rax,%rax,1)
lea    0xe09(%rip),%rsi
call   1050 <fprintf@plt>
jmp    118b <main+0x3b>

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"Unable to open file\0A\00"
@.str.1 = [13 x i8] c"Opened fifo\0A\00"
@.str.2 = [12 x i8] c"Filed died\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %29, %17, %2
%9 = call i32 @usleep(i32 1)
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %8
20: ; preds = %8
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %27, %20
%24 = load i32, i32* %7
%25 = call i32 @read(i32 %24, i8* %6, i32 1)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @write(i32 1, i8* %6, i32 1)
br label %23
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %8
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"Unable to open file\0A\00"
@.str.1 = [13 x i8] c"Opened fifo\0A\00"
@.str.2 = [12 x i8] c"Filed died\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = getelementptr inbounds i8*, i8** %1, i64 1
br label %5
5: ; preds = %14, %2
%6 = tail call i32 @usleep(i32 1)
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* %7, i32 %8)
%10 = icmp slt i32 %9, 0
%11 = load i32, i32* @stderr
br i1 %10, label %12, label %15
12: ; preds = %5
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %23
br label %5
15: ; preds = %5
%16 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @read(i32 %9, i8* %3, i32 1)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %15, %19
%20 = call i32 @write(i32 1, i8* %3, i32 1)
%21 = call i32 @read(i32 %9, i8* %3, i32 1)
%22 = icmp eq i32 %21, 1
br i1 %22, label %19, label %23
23: ; preds = %19, %15
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %14
}