#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 */
scalar_t__ EEXIST;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ O_RDONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int getpid();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char buff[1024];
  int real_read;
  int fd;
  printf("%s at PID = %d  ", argv[0], getpid());
  if (access("myfifo", F_OK) == -1) {
    if ((mkfifo("myfifo", 0666) < 0) && (errno != EEXIST)) {
      printf("Can NOT create fifo file!\n");
      exit(1);
    }
  }
  if ((fd = open("myfifo", O_RDONLY)) == -1) {
    printf("Open fifo error!\n");
    exit(1);
  }
  while (1) {
    memset(buff, 0, 1024);
    if ((real_read = read(fd, buff, 1024)) > 0) {
      printf("Read from pipe: '%s'.\n", buff);
    }
  }
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x420(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x420(%rbp),%rsi
mov    %eax,%edx
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    0xe3c(%rip),%rdi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
jne    1235 <main+0xb5>
lea    0xe27(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
cmp    $0x0,%rax
jge    1230 <main+0xb0>
mov    0x2dcb(%rip),%rax
mov    (%rax),%rax
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%rax
je     1230 <main+0xb0>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1235 <main+0xb5>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xdcc(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x418(%rbp)
cmp    $0xffffffff,%eax
jne    1271 <main+0xf1>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1276 <main+0xf6>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jle    12c4 <main+0x144>
lea    -0x410(%rbp),%rsi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1276 <main+0xf6>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    (%rsi),%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe54(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    0xe49(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    11fe <main+0x6e>
lea    0xe38(%rip),%rdi
mov    $0x1b6,%esi
call   1080 <mkfifo@plt>
test   %rax,%rax
jns    11fe <main+0x6e>
mov    0x2de1(%rip),%rax
mov    (%rax),%rax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
jne    1277 <main+0xe7>
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
lea    0xe03(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1261 <main+0xd1>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xdf4(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1230 <main+0xa0>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1230 <main+0xa0>
lea    0xdc7(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdc2(%rip),%rdi
jmp    1268 <main+0xd8>

LLVM IR (-O0):
@.str = [17 x i8] c"%s at PID = %d \00"
@.str.1 = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.2 = [27 x i8] c"Can NOT create fifo file!\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [18 x i8] c"Open fifo error!\0A\00"
@.str.4 = [23 x i8] c"Read from pipe: '%s'.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 (...) @getpid()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
%14 = load i32, i32* @F_OK
%15 = call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 438)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i64, i64* @errno
%22 = load i64, i64* @EEXIST
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20, %17
br label %28
28: ; preds = %27, %2
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 %30, i32* %8
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
br label %36
36: ; preds = %35, %46
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 0, i32 1024)
%39 = load i32, i32* %8
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 1024)
store i32 %41, i32* %7
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %36
br label %36
}

LLVM IR (-O2):
@.str = [17 x i8] c"%s at PID = %d \00"
@.str.1 = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@O_RDONLY = global i32 0
@.str.4 = [23 x i8] c"Read from pipe: '%s'.\0A\00"
@str = [17 x i8] c"Open fifo error!\00"
@str.5 = [26 x i8] c"Can NOT create fifo file!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %6)
%8 = load i32, i32* @F_OK
%9 = tail call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = tail call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 438)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i64, i64* @errno
%16 = load i64, i64* @EEXIST
%17 = icmp eq i64 %15, %16
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %11, %14, %2
%22 = load i32, i32* @O_RDONLY
%23 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %21, %34
%29 = call i32 @memset(i8* %4, i32 0, i32 1024)
%30 = call i32 @read(i32 %23, i8* %4, i32 1024)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %34
34: ; preds = %32, %28
br label %28
}