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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1070 <umask@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe61(%rip),%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
lea    0xe53(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x338(%rbp)
mov    -0x338(%rbp),%rsi
lea    0xe3b(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x338(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe26(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x340(%rbp)
lea    -0x330(%rbp),%rax
cmp    $0x0,%rax
jne    1246 <main+0xd6>
lea    -0x330(%rbp),%rdi
mov    -0x340(%rbp),%rdx
mov    $0x320,%esi
call   1060 <fgets@plt>
lea    -0x330(%rbp),%rsi
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x340(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11f9 <main+0x89>
xor    %eax,%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1040 <umask@plt>
mov    0x2e81(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xe93(%rip),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <mknod@plt>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe79(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe5b(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1060 <fopen@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"MYFIFO\00"
@S_IFIFO = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [8 x i8] c"MYFIFO2\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [21 x i8] c"Received string: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [800 x i8]
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 @umask(i32 0)
%6 = load i32, i32* @S_IFIFO
%7 = or i32 %6, 438
%8 = call i32 @mknod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7, i32 0)
%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** %3
%10 = load i32*, i32** %3
%11 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %10)
%12 = load i32*, i32** %3
%13 = call i32 @fclose(i32* %12)
%14 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %14, i32** %4
br label %15
15: ; preds = %18, %0
%16 = getelementptr inbounds [800 x i8], [800 x i8]* %2, i64 0, i64 0
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = getelementptr inbounds [800 x i8], [800 x i8]* %2, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32 @fgets(i8* %19, i32 800, i32* %20)
%22 = getelementptr inbounds [800 x i8], [800 x i8]* %2, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
br label %15
26: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"MYFIFO\00"
@S_IFIFO = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [8 x i8] c"MYFIFO2\00"
@.str.4 = [2 x i8] c"r\00"
define i32 @main() {
%1 = tail call i32 @umask(i32 0)
%2 = load i32, i32* @S_IFIFO
%3 = or i32 %2, 438
%4 = tail call i32 @mknod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = 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))
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %5)
%7 = tail call i32 @fclose(i32* %5)
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}