#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 */
#define PERF_REG_X86_AX 143
#define PERF_REG_X86_BP 142
#define PERF_REG_X86_BX 141
#define PERF_REG_X86_CS 140
#define PERF_REG_X86_CX 139
#define PERF_REG_X86_DI 138
#define PERF_REG_X86_DS 137
#define PERF_REG_X86_DX 136
#define PERF_REG_X86_ES 135
#define PERF_REG_X86_FLAGS 134
#define PERF_REG_X86_FS 133
#define PERF_REG_X86_GS 132
#define PERF_REG_X86_IP 131
#define PERF_REG_X86_SI 130
#define PERF_REG_X86_SP 129
#define PERF_REG_X86_SS 128
const char *perf_reg_name(int id) {
  switch (id) {
  case PERF_REG_X86_AX:
    return "AX";
  case PERF_REG_X86_BX:
    return "BX";
  case PERF_REG_X86_CX:
    return "CX";
  case PERF_REG_X86_DX:
    return "DX";
  case PERF_REG_X86_SI:
    return "SI";
  case PERF_REG_X86_DI:
    return "DI";
  case PERF_REG_X86_BP:
    return "BP";
  case PERF_REG_X86_SP:
    return "SP";
  case PERF_REG_X86_IP:
    return "IP";
  case PERF_REG_X86_FLAGS:
    return "FLAGS";
  case PERF_REG_X86_CS:
    return "CS";
  case PERF_REG_X86_SS:
    return "SS";
  case PERF_REG_X86_DS:
    return "DS";
  case PERF_REG_X86_ES:
    return "ES";
  case PERF_REG_X86_FS:
    return "FS";
  case PERF_REG_X86_GS:
    return "GS";
  default:
    return NULL;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<perf_reg_name>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xf,%eax
ja     1230 <perf_reg_name+0x130>
mov    -0x18(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf09(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xefc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xeef(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xee2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xed5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xec8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xebb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xea1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xe94(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xe8a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xe7d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xe70(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xe63(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xe56(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
lea    0xe37(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <perf_reg_name+0x138>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<perf_reg_name>:
add    $0xffffff80,%edi
cmp    $0xf,%edi
ja     111a <perf_reg_name+0x1a>
movslq %edi,%rax
lea    0xf1e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"AX\00"
@.str.1 = [3 x i8] c"BX\00"
@.str.2 = [3 x i8] c"CX\00"
@.str.3 = [3 x i8] c"DX\00"
@.str.4 = [3 x i8] c"SI\00"
@.str.5 = [3 x i8] c"DI\00"
@.str.6 = [3 x i8] c"BP\00"
@.str.7 = [3 x i8] c"SP\00"
@.str.8 = [3 x i8] c"IP\00"
@.str.9 = [6 x i8] c"FLAGS\00"
@.str.10 = [3 x i8] c"CS\00"
@.str.11 = [3 x i8] c"SS\00"
@.str.12 = [3 x i8] c"DS\00"
@.str.13 = [3 x i8] c"ES\00"
@.str.14 = [3 x i8] c"FS\00"
@.str.15 = [3 x i8] c"GS\00"
define i8* @perf_reg_name(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %21 [
i32 143, label %5
i32 141, label %6
i32 139, label %7
i32 136, label %8
i32 130, label %9
i32 138, label %10
i32 142, label %11
i32 129, label %12
i32 131, label %13
i32 134, label %14
i32 140, label %15
i32 128, label %16
i32 137, label %17
i32 135, label %18
i32 133, label %19
i32 132, label %20
]
5: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %22
6: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %22
7: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %22
8: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %22
9: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %22
10: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %22
11: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %22
12: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %22
13: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %22
14: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %22
15: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %22
16: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8** %2
br label %22
17: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8** %2
br label %22
18: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8** %2
br label %22
19: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i8** %2
br label %22
20: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i8** %2
br label %22
21: ; preds = %1
store i8* null, i8** %2
br label %22
22: ; preds = %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"AX\00"
@.str.1 = [3 x i8] c"BX\00"
@.str.2 = [3 x i8] c"CX\00"
@.str.3 = [3 x i8] c"DX\00"
@.str.4 = [3 x i8] c"SI\00"
@.str.5 = [3 x i8] c"DI\00"
@.str.6 = [3 x i8] c"BP\00"
@.str.7 = [3 x i8] c"SP\00"
@.str.8 = [3 x i8] c"IP\00"
@.str.9 = [6 x i8] c"FLAGS\00"
@.str.10 = [3 x i8] c"CS\00"
@.str.11 = [3 x i8] c"SS\00"
@.str.12 = [3 x i8] c"DS\00"
@.str.13 = [3 x i8] c"ES\00"
@.str.14 = [3 x i8] c"FS\00"
@.str.15 = [3 x i8] c"GS\00"
@reltable.perf_reg_name = [16 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.11 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.7 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.4 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.8 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.15 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.14 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.9 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.13 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.3 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.12 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.5 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.10 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.6 to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.perf_reg_name to i64)) to i32)]
define i8* @perf_reg_name(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 16
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([16 x i32]* @reltable.perf_reg_name to i8*), i64 %6)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ %7, %4 ], [ null, %1 ]
ret i8* %9
}