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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int S_IFIFO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int main(void) {
  int fd;
  char to_me[] = "lab072";
  char rd[64];
  (void)umask(0);
  if (mknod(to_me, S_IFIFO | 0666, 0) < 0) {
    printf("Can\'t create FIFO\n");
    exit(-1);
  }
  if ((fd = open(to_me, O_RDONLY)) < 0) {
    printf("Can\'t open FIFO for reading\n");
    exit(-1);
  }
  while (read(fd, rd, 64) != 0) {
    printf("%s", rd);
  }
  close(fd);
  remove(to_me);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe6b(%rip),%eax
mov    %eax,-0xf(%rbp)
mov    0xe65(%rip),%ax
mov    %ax,-0xb(%rbp)
mov    0xe5d(%rip),%al
mov    %al,-0x9(%rbp)
xor    %edi,%edi
call   1070 <umask@plt>
lea    -0xf(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
xor    %edx,%edx
call   1080 <mknod@plt>
cmp    $0x0,%rax
jge    11ef <main+0x6f>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    -0xf(%rbp),%rdi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1225 <main+0xa5>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    122a <main+0xaa>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
je     125c <main+0xdc>
lea    -0x50(%rbp),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122a <main+0xaa>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    -0xf(%rbp),%rdi
call   1030 <remove@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
movl   $0x323730,0xb(%rsp)
movl   $0x3062616c,0x8(%rsp)
30
xor    %edi,%edi
call   1080 <umask@plt>
mov    0x2e22(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0x8(%rsp),%rdi
xor    %edx,%edx
call   1090 <mknod@plt>
test   %rax,%rax
js     124d <main+0xbd>
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     1256 <main+0xc6>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x40,%edx
call   1070 <read@plt>
test   %rax,%rax
je     1231 <main+0xa1>
lea    0xe03(%rip),%r14
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1070 <read@plt>
test   %rax,%rax
jne    1210 <main+0x80>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0x8(%rsp),%rdi
call   1030 <remove@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd2(%rip),%rdi
jmp    125d <main+0xcd>
lea    0xdad(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@__const.main.to_me = [7 x i8] c"lab072\00"
@S_IFIFO = global i32 0
@.str = [19 x i8] c"Can't create FIFO\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [29 x i8] c"Can't open FIFO for reading\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [7 x i8]
%4 = alloca [64 x i8]
store i32 0, i32* %1
%5 = bitcast [7 x i8]* %3 to i8*
%6 = call i32 @umask(i32 0)
%7 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @S_IFIFO
%9 = or i32 %8, 438
%10 = call i64 @mknod(i8* %7, i32 %9, i32 0)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
%16 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %15
br label %24
24: ; preds = %29, %23
%25 = load i32, i32* %2
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%27 = call i64 @read(i32 %25, i8* %26, i32 64)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %24
32: ; preds = %24
%33 = load i32, i32* %2
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%36 = call i32 @remove(i8* %35)
ret i32 0
}

LLVM IR (-O2):
@__const.main.to_me = [7 x i8] c"lab072\00"
@S_IFIFO = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@str = [28 x i8] c"Can't open FIFO for reading\00"
@str.3 = [18 x i8] c"Can't create FIFO\00"
define i32 @main() {
%1 = alloca [7 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @umask(i32 0)
%6 = load i32, i32* @S_IFIFO
%7 = or i32 %6, 438
%8 = call i64 @mknod(i8* %3, i32 %7, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* %3, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i64 @read(i32 %15, i8* %4, i32 64)
%19 = icmp eq i64 %18, 0
br i1 %19, label %27, label %23
20: ; preds = %13
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %17, %23
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%25 = call i64 @read(i32 %15, i8* %4, i32 64)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %23
27: ; preds = %23, %17
%28 = call i32 @close(i32 %15)
%29 = call i32 @remove(i8* %3)
ret i32 0
}