#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 */
int S_IFIFO;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int main(void) {
  FILE *fp;
  char readbuf[80];
  umask(0);
  mknod("MYFIFO", S_IFIFO | 0666, 0);
  while (1) {
    fp = fopen("MYFIFO", "r");
    fgets(readbuf, 80, fp);
    printf("Received string: %s\n", readbuf);
    fclose(fp);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <umask@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe74(%rip),%rdi
xor    %edx,%edx
call   1070 <mknod@plt>
lea    0xe66(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
lea    -0x60(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1193 <main+0x33>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
xor    %edi,%edi
call   1060 <umask@plt>
mov    0x2e65(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xe77(%rip),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1070 <mknod@plt>
lea    0xe6d(%rip),%r15
mov    %rsp,%r13
lea    0xe65(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11b0 <main+0x50>

LLVM IR (-O0):
@.str = [7 x i8] c"MYFIFO\00"
@S_IFIFO = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Received string: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [80 x i8]
store i32 0, i32* %1
%4 = call i32 @umask(i32 0)
%5 = load i32, i32* @S_IFIFO
%6 = or i32 %5, 438
%7 = call i32 @mknod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
br label %8
8: ; preds = %0, %8
%9 = 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* %9, i32** %2
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i32 @fgets(i8* %10, i32 80, i32* %11)
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
br label %8
}

LLVM IR (-O2):
@.str = [7 x i8] c"MYFIFO\00"
@S_IFIFO = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Received string: %s\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @umask(i32 0)
%4 = load i32, i32* @S_IFIFO
%5 = or i32 %4, 438
%6 = tail call i32 @mknod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5, i32 0)
br label %7
7: ; preds = %7, %0
%8 = 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))
%9 = call i32 @fgets(i8* %2, i32 80, i32* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%11 = call i32 @fclose(i32* %8)
br label %7
}