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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1080 <umask@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe54(%rip),%rdi
xor    %edx,%edx
call   1090 <mknod@plt>
lea    0xe46(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x32,%esi
call   1070 <fgets@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    -0x50(%rbp),%rdx
lea    0xe0e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11b3 <main+0x33>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
xor    %edi,%edi
call   1080 <umask@plt>
mov    0x2e45(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xe57(%rip),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1090 <mknod@plt>
lea    0xe52(%rip),%r15
mov    %rsp,%r13
lea    0xe4a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
mov    %r13,%rdi
mov    $0x32,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %r13,%rdx
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11d0 <main+0x50>

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/MYFIFO\00"
@S_IFIFO = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"PID %d: Received string : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [50 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 ([12 x i8], [12 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 ([12 x i8], [12 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 [50 x i8], [50 x i8]* %3, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 50)
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32 @fgets(i8* %12, i32 50, i32* %13)
%15 = call i32 (...) @getpid()
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %15, i8* %16)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
br label %8
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/MYFIFO\00"
@S_IFIFO = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"PID %d: Received string : %s\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 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 ([12 x i8], [12 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 ([12 x i8], [12 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 @memset(i8* %2, i32 0, i32 50)
%10 = call i32 @fgets(i8* %2, i32 50, i32* %8)
%11 = call i32 (...) @getpid()
%12 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %11, i8* %2)
%13 = call i32 @fclose(i32* %8)
br label %7
}