#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
char action() {
  char ch;
  int fd;
  if ((fd = open("status_pipe", O_RDONLY)) == -1)
    err(6, "Error opening named pipe");
  if (read(fd, &ch, 1) == -1)
    err(7, "Error reading named pipe");
  close(fd);
  return ch;
}


x86 assembly (clang, -O0):
<action>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    117a <action+0x3a>
mov    $0x6,%edi
lea    0xe97(%rip),%rsi
call   1050 <err@plt>
mov    -0x8(%rbp),%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    11a5 <action+0x65>
mov    $0x7,%edi
lea    0xe85(%rip),%rsi
call   1050 <err@plt>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<action>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1172 <action+0x32>
lea    0xea4(%rip),%rsi
mov    $0x6,%edi
call   1050 <err@plt>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    1199 <action+0x59>
lea    0xe96(%rip),%rsi
mov    $0x7,%edi
call   1050 <err@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    0xf(%rsp),%al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"status_pipe\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Error opening named pipe\00"
@.str.2 = [25 x i8] c"Error reading named pipe\00"
define signext i8 @action() {
%1 = alloca i8
%2 = alloca i32
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @err(i32 6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i32, i32* %2
%10 = call i32 @read(i32 %9, i8* %1, i32 1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @err(i32 7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* %2
%16 = call i32 @close(i32 %15)
%17 = load i8, i8* %1
ret i8 %17
}

LLVM IR (-O2):
@.str = [12 x i8] c"status_pipe\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Error opening named pipe\00"
@.str.2 = [25 x i8] c"Error reading named pipe\00"
define signext i8 @action() {
%1 = alloca i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @err(i32 6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i32 @read(i32 %3, i8* %1, i32 1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @err(i32 7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @close(i32 %3)
%14 = load i8, i8* %1
ret i8 %14
}