#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 */
struct CONSOLE {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cons_putchar(struct CONSOLE *, int, int);
int /*<<< orphan*/ cons_putstr0(struct CONSOLE *, char *);
int /*<<< orphan*/ cons_putstr1(struct CONSOLE *, char *, int);
void hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx,
             int eax) {
  int cs_base = *((int *)0xfe8);
  struct CONSOLE *cons = (struct CONSOLE *)*((int *)0x0fec);
  if (edx == 1) {
    cons_putchar(cons, eax & 0xff, 1);
  } else if (edx == 2) {
    cons_putstr0(cons, (char *)ebx + cs_base);
  } else if (edx == 3) {
    cons_putstr1(cons, (char *)ebx + cs_base, ecx);
  }
  return;
}


x86 assembly (clang, -O0):
<hrb_api>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
mov    $0xfe8,%eax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xfec,%eax
movslq (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    118e <hrb_api+0x5e>
mov    -0x28(%rbp),%rdi
mov    0x18(%rbp),%esi
and    $0xff,%esi
mov    $0x1,%edx
call   1030 <cons_putchar@plt>
jmp    11dc <hrb_api+0xac>
cmpl   $0x2,-0x18(%rbp)
jne    11b1 <hrb_api+0x81>
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1040 <cons_putstr0@plt>
jmp    11d7 <hrb_api+0xa7>
cmpl   $0x3,-0x18(%rbp)
jne    11d2 <hrb_api+0xa2>
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    0x10(%rbp),%edx
call   1050 <cons_putstr1@plt>
jmp    11d7 <hrb_api+0xa7>
jmp    11dc <hrb_api+0xac>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hrb_api>:
movslq 0xfe8,%rax
movslq 0xfec,%rdi
cmp    $0x3,%r9d
je     1163 <hrb_api+0x33>
cmp    $0x2,%r9d
je     1172 <hrb_api+0x42>
cmp    $0x1,%r9d
jne    117d <hrb_api+0x4d>
mov    0x10(%rsp),%eax
movzbl %al,%esi
mov    $0x1,%edx
jmp    1030 <cons_putchar@plt>
mov    0x8(%rsp),%edx
movslq %r8d,%rsi
add    %rax,%rsi
jmp    1050 <cons_putstr1@plt>
movslq %r8d,%rsi
add    %rax,%rsi
jmp    1040 <cons_putstr0@plt>
ret

LLVM IR (-O0):
%struct.CONSOLE = type { i32 }
define void @hrb_api(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.CONSOLE*
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%19 = load i32, i32* inttoptr (i64 4072 to i32*)
store i32 %19, i32* %17
%20 = load i32, i32* inttoptr (i64 4076 to i32*)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to %struct.CONSOLE*
store %struct.CONSOLE* %22, %struct.CONSOLE** %18
%23 = load i32, i32* %14
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %30
25: ; preds = %8
%26 = load %struct.CONSOLE*, %struct.CONSOLE** %18
%27 = load i32, i32* %16
%28 = and i32 %27, 255
%29 = call i32 @cons_putchar(%struct.CONSOLE* %26, i32 %28, i32 1)
br label %57
30: ; preds = %8
%31 = load i32, i32* %14
%32 = icmp eq i32 %31, 2
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load %struct.CONSOLE*, %struct.CONSOLE** %18
%35 = load i32, i32* %13
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i8*
%38 = load i32, i32* %17
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = call i32 @cons_putstr0(%struct.CONSOLE* %34, i8* %40)
br label %56
42: ; preds = %30
%43 = load i32, i32* %14
%44 = icmp eq i32 %43, 3
br i1 %44, label %45, label %55
45: ; preds = %42
%46 = load %struct.CONSOLE*, %struct.CONSOLE** %18
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = inttoptr i64 %48 to i8*
%50 = load i32, i32* %17
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i32, i32* %15
%54 = call i32 @cons_putstr1(%struct.CONSOLE* %46, i8* %52, i32 %53)
br label %55
55: ; preds = %45, %42
br label %56
56: ; preds = %55, %33
br label %57
57: ; preds = %56, %25
ret void
}

LLVM IR (-O2):
%struct.CONSOLE = type { i32 }
define void @hrb_api(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = load i32, i32* inttoptr (i64 4072 to i32*)
%10 = load i32, i32* inttoptr (i64 4076 to i32*)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to %struct.CONSOLE*
switch i32 %5, label %28 [
i32 1, label %13
i32 2, label %16
i32 3, label %22
]
13: ; preds = %8
%14 = and i32 %7, 255
%15 = tail call i32 @cons_putchar(%struct.CONSOLE* %12, i32 %14, i32 1)
br label %28
16: ; preds = %8
%17 = sext i32 %4 to i64
%18 = inttoptr i64 %17 to i8*
%19 = sext i32 %9 to i64
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = tail call i32 @cons_putstr0(%struct.CONSOLE* %12, i8* %20)
br label %28
22: ; preds = %8
%23 = sext i32 %4 to i64
%24 = inttoptr i64 %23 to i8*
%25 = sext i32 %9 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = tail call i32 @cons_putstr1(%struct.CONSOLE* %12, i8* %26, i32 %6)
br label %28
28: ; preds = %8, %16, %22, %13
ret void
}