#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 int ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ __NR_read;
int /*<<< orphan*/ __NR_write;
scalar_t__ install_emulator();
scalar_t__ install_filter();
int syscall(int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  char buf[4096];
  ssize_t bytes = 0;
  if (install_emulator()) {
    return 1;
  }
  if (install_filter()) {
    return 1;
  }
  syscall(__NR_write, STDOUT_FILENO, ("OHAI! WHAT IS YOUR NAME? "),
          sizeof(("OHAI! WHAT IS YOUR NAME? ")));
  bytes = syscall(__NR_read, STDIN_FILENO, buf, sizeof(buf));
  syscall(__NR_write, STDOUT_FILENO, ("HELLO, "), sizeof(("HELLO, ")));
  syscall(__NR_write, STDOUT_FILENO, buf, bytes);
  syscall(__NR_write, STDERR_FILENO, ("Error message going to STDERR\n"),
          sizeof(("Error message going to STDERR\n")));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1014(%rbp)
mov    $0x0,%al
call   1030 <install_emulator@plt>
cmp    $0x0,%rax
je     1170 <main+0x40>
movl   $0x1,-0x4(%rbp)
jmp    124a <main+0x11a>
mov    $0x0,%al
call   1040 <install_filter@plt>
cmp    $0x0,%rax
je     118d <main+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    124a <main+0x11a>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdx
mov    $0x1a,%ecx
call   1050 <syscall@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    -0x1010(%rbp),%rdx
mov    $0x1000,%ecx
call   1050 <syscall@plt>
mov    %eax,-0x1014(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    0xe28(%rip),%rdx
mov    $0x8,%ecx
call   1050 <syscall@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    -0x1010(%rbp),%rdx
mov    -0x1014(%rbp),%ecx
call   1050 <syscall@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
lea    0xde9(%rip),%rdx
mov    $0x1f,%ecx
call   1050 <syscall@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
xor    %eax,%eax
call   1030 <install_emulator@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    11ed <main+0xbd>
xor    %eax,%eax
call   1040 <install_filter@plt>
test   %rax,%rax
jne    11ed <main+0xbd>
mov    0x2e77(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e7e(%rip),%r15
mov    (%r15),%esi
lea    0xe84(%rip),%rdx
mov    $0x1a,%ecx
call   1050 <syscall@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
mov    %r14,%rdx
mov    $0x1000,%ecx
call   1050 <syscall@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
mov    (%r15),%esi
lea    0xe64(%rip),%rdx
mov    $0x8,%ecx
call   1050 <syscall@plt>
mov    (%rbx),%edi
mov    (%r15),%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1050 <syscall@plt>
mov    (%rbx),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdx
mov    $0x1f,%ecx
call   1050 <syscall@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__NR_write = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [26 x i8] c"OHAI! WHAT IS YOUR NAME? \00"
@__NR_read = global i32 0
@STDIN_FILENO = global i32 0
@.str.1 = [8 x i8] c"HELLO, \00"
@STDERR_FILENO = global i32 0
@.str.2 = [31 x i8] c"Error message going to STDERR\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = call i64 (...) @install_emulator()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %34
11: ; preds = %2
%12 = call i64 (...) @install_filter()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 1, i32* %3
br label %34
15: ; preds = %11
%16 = load i32, i32* @__NR_write
%17 = load i32, i32* @STDOUT_FILENO
%18 = call i32 @syscall(i32 %16, i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 26)
%19 = load i32, i32* @__NR_read
%20 = load i32, i32* @STDIN_FILENO
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%22 = call i32 @syscall(i32 %19, i32 %20, i8* %21, i32 4096)
store i32 %22, i32* %7
%23 = load i32, i32* @__NR_write
%24 = load i32, i32* @STDOUT_FILENO
%25 = call i32 @syscall(i32 %23, i32 %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 8)
%26 = load i32, i32* @__NR_write
%27 = load i32, i32* @STDOUT_FILENO
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%29 = load i32, i32* %7
%30 = call i32 @syscall(i32 %26, i32 %27, i8* %28, i32 %29)
%31 = load i32, i32* @__NR_write
%32 = load i32, i32* @STDERR_FILENO
%33 = call i32 @syscall(i32 %31, i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 31)
store i32 0, i32* %3
br label %34
34: ; preds = %15, %14, %10
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@__NR_write = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [26 x i8] c"OHAI! WHAT IS YOUR NAME? \00"
@__NR_read = global i32 0
@STDIN_FILENO = global i32 0
@.str.1 = [8 x i8] c"HELLO, \00"
@STDERR_FILENO = global i32 0
@.str.2 = [31 x i8] c"Error message going to STDERR\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i64 (...) @install_emulator()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %2
%8 = tail call i64 (...) @install_filter()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = load i32, i32* @__NR_write
%12 = load i32, i32* @STDOUT_FILENO
%13 = tail call i32 @syscall(i32 %11, i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 26)
%14 = load i32, i32* @__NR_read
%15 = load i32, i32* @STDIN_FILENO
%16 = call i32 @syscall(i32 %14, i32 %15, i8* %4, i32 4096)
%17 = load i32, i32* @__NR_write
%18 = load i32, i32* @STDOUT_FILENO
%19 = call i32 @syscall(i32 %17, i32 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 8)
%20 = load i32, i32* @__NR_write
%21 = load i32, i32* @STDOUT_FILENO
%22 = call i32 @syscall(i32 %20, i32 %21, i8* %4, i32 %16)
%23 = load i32, i32* @__NR_write
%24 = load i32, i32* @STDERR_FILENO
%25 = call i32 @syscall(i32 %23, i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 31)
br label %26
26: ; preds = %7, %2, %10
%27 = phi i32 [ 0, %10 ], [ 1, %2 ], [ 1, %7 ]
ret i32 %27
}