#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open_pipe(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  char buffer[100];
  int pd;
  ssize_t message_length;
  pd = open_pipe("./testfifo");
  strcpy(buffer, "");
  message_length = read(pd, buffer, 100);
  if (message_length > 0) {
    printf("\nRead message from the pipe...\n");
    printf("%s\n", buffer);
  } else {
    printf("Named pipe is empty.\n");
  }
  close(pd);
  unlink("./testfifo");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
call   1080 <open_pipe@plt>
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x74(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jle    11e6 <main+0x76>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f4 <main+0x84>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x74(%rbp),%edi
call   1060 <close@plt>
lea    0xdfd(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xe82(%rip),%rdi
call   1080 <open_pipe@plt>
mov    %eax,%ebx
lea    0xeb2(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
test   %rax,%rax
jle    11bc <main+0x4c>
lea    0xe6e(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rdi
jmp    11c3 <main+0x53>
lea    0xe48(%rip),%rdi
call   1050 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe2a(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"./testfifo\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [32 x i8] c"\0ARead message from the pipe...\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [22 x i8] c"Named pipe is empty.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 @open_pipe(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %5, i32* %3
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = call i64 @read(i32 %8, i8* %9, i32 100)
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %19
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
%22 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_SUCCESS
%24 = call i32 @exit(i32 %23)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"./testfifo\00"
@.str.1 = [1 x i8] zeroinitializer
@EXIT_SUCCESS = global i32 0
@str = [21 x i8] c"Named pipe is empty.\00"
@str.5 = [31 x i8] c"\0ARead message from the pipe...\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @open_pipe(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%5 = call i64 @read(i32 %3, i8* %2, i32 100)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
%9 = call i32 @puts(i8* %2)
br label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i32 @close(i32 %3)
%14 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_SUCCESS
%16 = call i32 @exit(i32 %15)
unreachable
}