#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int hfifo, n;
  char buf[1024];
  if (argv[1] == NULL) {
    fprintf(stderr, "You must specify a named pipe.\n");
    return -1;
  }
  hfifo = open(argv[1], O_RDWR);
  if (hfifo == -1) {
    fprintf(stderr, "Fifo file open error.\n");
    return -1;
  }
  if ((n = read(hfifo, buf, 1024)) == -1)
    printf("Error.\n");
  if (n >= 0)
    printf("%s\n", buf);
  close(hfifo);
  return 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
cmpq   $0x0,0x8(%rax)
jne    1199 <main+0x49>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <main+0xe9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11dd <main+0x8d>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <main+0xe9>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    120b <main+0xbb>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jl     122a <main+0xda>
lea    -0x420(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1193 <main+0x43>
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11a5 <main+0x55>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11c1 <main+0x71>
test   %eax,%eax
js     11cd <main+0x7d>
mov    %rsp,%rdi
jmp    11c8 <main+0x78>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
jmp    11b5 <main+0x65>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11d6 <main+0x86>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"You must specify a named pipe.\0A\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Fifo file open error.\0A\00"
@.str.2 = [8 x i8] c"Error.\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
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 1
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDWR
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
27: ; preds = %16
%28 = load i32, i32* %6
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 1024)
store i32 %30, i32* %7
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i32, i32* %7
%36 = icmp sge i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %34
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %40, %24, %13
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"You must specify a named pipe.\0A\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Fifo file open error.\0A\00"
@str = [7 x i8] c"Error.\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 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %29
11: ; preds = %2
%12 = load i32, i32* @O_RDWR
%13 = tail call i32 @open(i8* %6, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %29
18: ; preds = %11
%19 = call i32 @read(i32 %13, i8* %4, i32 1024)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %27
23: ; preds = %18
%24 = icmp sgt i32 %19, -1
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = call i32 @puts(i8* %4)
br label %27
27: ; preds = %21, %25, %23
%28 = tail call i32 @close(i32 %13)
br label %29
29: ; preds = %27, %15, %8
%30 = phi i32 [ -1, %8 ], [ -1, %15 ], [ 0, %27 ]
ret i32 %30
}