#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ mkfifo(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
void main() {
  FILE *in_file;
  int count = 1;
  char buf[80];
  mkfifo("mypipe", 0777);
  in_file = fopen("mypipe", "r");
  if (in_file == NULL) {
    printf("Error in fdopen.\n");
    return;
  }
  while ((count = fread(buf, 1, 80, in_file)) > 0)
    printf("received from pipe: %s\n", buf);
  fclose(in_file);
  remove("mypipe");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x1,-0xc(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x1ff,%esi
call   1070 <mkfifo@plt>
lea    0xe79(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11b5 <main+0x55>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1209 <main+0xa9>
jmp    11ba <main+0x5a>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x50,%edx
call   1040 <fread@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    11f4 <main+0x94>
lea    -0x60(%rbp),%rsi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11ba <main+0x5a>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xdfc(%rip),%rdi
call   1030 <remove@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xe80(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1080 <mkfifo@plt>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1214 <main+0xa4>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x50,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    11f6 <main+0x86>
lea    0xe45(%rip),%r14
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x50,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jg     11d0 <main+0x60>
mov    %r15,%rdi
call   1060 <fclose@plt>
lea    0xdfb(%rip),%rdi
call   1030 <remove@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe06(%rip),%rdi
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"mypipe\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"Error in fdopen.\0A\00"
@.str.3 = [24 x i8] c"received from pipe: %s\0A\00"
define void @main() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca [80 x i8]
store i32 1, i32* %2
%4 = call i32 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 511)
%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** %1
%6 = load i32*, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %23
10: ; preds = %0
br label %11
11: ; preds = %16, %10
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %1
%14 = call i32 @fread(i8* %12, i32 1, i32 80, i32* %13)
store i32 %14, i32* %2
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %11
19: ; preds = %11
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
%22 = call i32 @remove(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %19, %8
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"mypipe\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [24 x i8] c"received from pipe: %s\0A\00"
@str = [17 x i8] c"Error in fdopen.\00"
define void @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 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 511)
%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 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 @fread(i8* %2, i32 1, i32 80, i32* %4)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %11, label %15
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %18
11: ; preds = %6, %11
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%13 = call i32 @fread(i8* %2, i32 1, i32 80, i32* %4)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %11, label %15
15: ; preds = %11, %6
%16 = call i32 @fclose(i32* %4)
%17 = call i32 @remove(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %9
ret void
}