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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ mkfifo(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main() {
  char buf[100];
  FILE *fifo;
  mkfifo("myfifo", 0640);
  fifo = fopen("myfifo", "r");
  while (fgets(buf, 100, fifo) != 0) {
    printf("%s", buf);
  }
  unlink("myfifo");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
mov    $0x1a0,%esi
call   1060 <mkfifo@plt>
lea    0xe86(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11bb <main+0x6b>
lea    -0x70(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
jmp    118a <main+0x3a>
lea    0xe3e(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xea0(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1a0,%esi
call   1060 <mkfifo@plt>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <main+0x70>
lea    0xe6e(%rip),%r14
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x50>
lea    0xe39(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"myfifo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 416)
%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** %3
br label %6
6: ; preds = %11, %0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i64 @fgets(i8* %7, i32 100, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %6
14: ; preds = %6
%15 = call i32 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"myfifo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 416)
%4 = tail 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))
%5 = call i64 @fgets(i8* %2, i32 100, i32* %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %0, %7
%8 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%9 = call i64 @fgets(i8* %2, i32 100, i32* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %7
11: ; preds = %7, %0
%12 = call i32 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
ret i32 0
}