#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) {
  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);
  } else if (edx == 3) {
    cons_putstr1(cons, (char *)ebx, ecx);
  }
  return;
}


x86 assembly (clang, -O0):
<hrb_api>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    $0xfec,%eax
movslq (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    1184 <hrb_api+0x54>
mov    -0x20(%rbp),%rdi
mov    0x18(%rbp),%esi
and    $0xff,%esi
mov    $0x1,%edx
call   1030 <cons_putchar@plt>
jmp    11c4 <hrb_api+0x94>
cmpl   $0x2,-0x18(%rbp)
jne    11a0 <hrb_api+0x70>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rsi
call   1040 <cons_putstr0@plt>
jmp    11bf <hrb_api+0x8f>
cmpl   $0x3,-0x18(%rbp)
jne    11ba <hrb_api+0x8a>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1050 <cons_putstr1@plt>
jmp    11bf <hrb_api+0x8f>
jmp    11c4 <hrb_api+0x94>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hrb_api>:
movslq 0xfec,%rdi
cmp    $0x3,%r9d
je     115b <hrb_api+0x2b>
cmp    $0x2,%r9d
je     1167 <hrb_api+0x37>
cmp    $0x1,%r9d
jne    116f <hrb_api+0x3f>
mov    0x10(%rsp),%eax
movzbl %al,%esi
mov    $0x1,%edx
jmp    1030 <cons_putchar@plt>
mov    0x8(%rsp),%edx
movslq %r8d,%rsi
jmp    1050 <cons_putstr1@plt>
movslq %r8d,%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 %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
%18 = load i32, i32* inttoptr (i64 4076 to i32*)
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to %struct.CONSOLE*
store %struct.CONSOLE* %20, %struct.CONSOLE** %17
%21 = load i32, i32* %14
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %28
23: ; preds = %8
%24 = load %struct.CONSOLE*, %struct.CONSOLE** %17
%25 = load i32, i32* %16
%26 = and i32 %25, 255
%27 = call i32 @cons_putchar(%struct.CONSOLE* %24, i32 %26, i32 1)
br label %49
28: ; preds = %8
%29 = load i32, i32* %14
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load %struct.CONSOLE*, %struct.CONSOLE** %17
%33 = load i32, i32* %13
%34 = sext i32 %33 to i64
%35 = inttoptr i64 %34 to i8*
%36 = call i32 @cons_putstr0(%struct.CONSOLE* %32, i8* %35)
br label %48
37: ; preds = %28
%38 = load i32, i32* %14
%39 = icmp eq i32 %38, 3
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load %struct.CONSOLE*, %struct.CONSOLE** %17
%42 = load i32, i32* %13
%43 = sext i32 %42 to i64
%44 = inttoptr i64 %43 to i8*
%45 = load i32, i32* %15
%46 = call i32 @cons_putstr1(%struct.CONSOLE* %41, i8* %44, i32 %45)
br label %47
47: ; preds = %40, %37
br label %48
48: ; preds = %47, %31
br label %49
49: ; preds = %48, %23
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 4076 to i32*)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to %struct.CONSOLE*
switch i32 %5, label %23 [
i32 1, label %12
i32 2, label %15
i32 3, label %19
]
12: ; preds = %8
%13 = and i32 %7, 255
%14 = tail call i32 @cons_putchar(%struct.CONSOLE* %11, i32 %13, i32 1)
br label %23
15: ; preds = %8
%16 = sext i32 %4 to i64
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 @cons_putstr0(%struct.CONSOLE* %11, i8* %17)
br label %23
19: ; preds = %8
%20 = sext i32 %4 to i64
%21 = inttoptr i64 %20 to i8*
%22 = tail call i32 @cons_putstr1(%struct.CONSOLE* %11, i8* %21, i32 %6)
br label %23
23: ; preds = %8, %15, %19, %12
ret void
}