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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int main() {
  FILE *fp;
  char buf[255];
  while (1) {
    if ((fp = fopen("myfifo", "r")) == NULL)
      return 0;
    fgets(buf, sizeof(buf), fp);
    printf("gets:[%s]", buf);
    if (strncmp(buf, "quit", 4) == 0 || strncmp(buf, "exit", 4) == 0)
      break;
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    118f <main+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1215 <main+0xc5>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
lea    -0x110(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11fb <main+0xab>
lea    -0x110(%rbp),%rdi
lea    0xe31(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1200 <main+0xb0>
jmp    120e <main+0xbe>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1162 <main+0x12>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe98(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1204 <main+0xb4>
mov    %rax,%rbx
mov    %rsp,%r15
lea    0xe7f(%rip),%r14
lea    0xe82(%rip),%r12
lea    0xe80(%rip),%r13
lea    0xe68(%rip),%rbp
nop
mov    %r15,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1204 <main+0xb4>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1204 <main+0xb4>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe0c(%rip),%rdi
mov    %rbp,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a0 <main+0x50>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"myfifo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"gets:[%s]\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"exit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [255 x i8]
store i32 0, i32* %1
br label %4
4: ; preds = %0, %22
%5 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %4
store i32 0, i32* %1
br label %26
8: ; preds = %4
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i32 @fgets(i8* %9, i32 255, i32* %10)
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %8
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17, %8
br label %25
22: ; preds = %17
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
br label %4
25: ; preds = %21
store i32 0, i32* %1
br label %26
26: ; preds = %25, %7
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [7 x i8] c"myfifo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"gets:[%s]\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"exit\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%3 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %18, label %5
5: ; preds = %0, %14
%6 = phi i32* [ %16, %14 ], [ %3, %0 ]
%7 = call i32 @fgets(i8* %2, i32 255, i32* %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%9 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %5
%12 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = call i32 @fclose(i32* %6)
%16 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %5
18: ; preds = %14, %5, %11, %0
ret i32 0
}