#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*/ O_RDONLY;
char action(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ mem_map();
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ process_options(int, char **);
int /*<<< orphan*/ remove(char *);
int main(int argc, char **argv) {
  int ret;
  int fd;
  char ch;
  process_options(argc, argv);
  ret = mkfifo("status_pipe", 0666);
  if (ret == -1 && errno != EEXIST)
    errx(1, "Error creating named pipe");
  if ((fd = open("status_pipe", O_RDONLY)) == -1)
    err(6, "Error opening named pipe");
  do {
    ch = action(fd);
    if (ch == 'm')
      mem_map();
  } while (ch != 'x');
  close(fd);
  remove("status_pipe");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <process_options@plt>
lea    0xe47(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11fb <main+0x6b>
mov    0x2df9(%rip),%rax
mov    (%rax),%rax
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
je     11fb <main+0x6b>
mov    $0x1,%edi
lea    0xe16(%rip),%rsi
call   1050 <errx@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xdf5(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    122d <main+0x9d>
mov    $0x6,%edi
lea    0xdfe(%rip),%rsi
call   1080 <err@plt>
jmp    1232 <main+0xa2>
mov    -0x18(%rbp),%edi
call   10a0 <action@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x6d,%eax
jne    1251 <main+0xc1>
mov    $0x0,%al
call   10b0 <mem_map@plt>
jmp    1256 <main+0xc6>
movsbl -0x19(%rbp),%eax
cmp    $0x78,%eax
jne    1232 <main+0xa2>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    0xd8e(%rip),%rdi
call   1040 <remove@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
call   1030 <process_options@plt>
lea    0xe63(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    11d3 <main+0x43>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
je     11d3 <main+0x43>
lea    0xe43(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    0xe1d(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1217 <main+0x87>
lea    0xe30(%rip),%rsi
mov    $0x6,%edi
call   1080 <err@plt>
jmp    1217 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   10b0 <mem_map@plt>
mov    %ebx,%edi
call   10a0 <action@plt>
cmp    $0x6d,%al
je     1210 <main+0x80>
cmp    $0x78,%al
jne    1217 <main+0x87>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xdcc(%rip),%rdi
call   1040 <remove@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"status_pipe\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [26 x i8] c"Error creating named pipe\00"
@O_RDONLY = global i32 0
@.str.2 = [25 x i8] c"Error opening named pipe\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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @process_options(i32 %9, i8** %10)
%12 = call i32 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 438)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = load i64, i64* @EEXIST
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15, %2
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 %23, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @err(i32 6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
br label %28
28: ; preds = %37, %27
%29 = load i32, i32* %7
%30 = call signext i8 @action(i32 %29)
store i8 %30, i8* %8
%31 = load i8, i8* %8
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 109
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 (...) @mem_map()
br label %36
36: ; preds = %34, %28
br label %37
37: ; preds = %36
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 120
br i1 %40, label %28, label %41
41: ; preds = %37
%42 = load i32, i32* %7
%43 = call i32 @close(i32 %42)
%44 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"status_pipe\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [26 x i8] c"Error creating named pipe\00"
@O_RDONLY = global i32 0
@.str.2 = [25 x i8] c"Error opening named pipe\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @process_options(i32 %0, i8** %1)
%4 = tail call i32 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 438)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @EEXIST
%9 = icmp eq i64 %7, %8
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %6, %2
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @err(i32 6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
br label %19
19: ; preds = %21, %18
%20 = tail call signext i8 @action(i32 %14)
switch i8 %20, label %21 [
i8 109, label %22
i8 120, label %24
]
21: ; preds = %19, %22
br label %19
22: ; preds = %19
%23 = tail call i32 (...) @mem_map()
br label %21
24: ; preds = %19
%25 = tail call i32 @close(i32 %14)
%26 = tail call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
ret i32 0
}