const char *reg_name(int reg, int id) {
  static char ret[32];
  char *buf = ret;
  switch (reg) {
  case 0 ... 15:
    sprintf(buf, "r%d", reg);
    break;
  case 16 ... 23:
    sprintf(buf, "g%d", reg - 16);
    break;
  case 24 ... 27:
    sprintf(buf, "alu%d", reg - 24);
    break;
  case 28 ... 30:
    sprintf(buf, "imm%d", reg - 28);
    break;
  case 31:
    if (id == -1) {
      sprintf(buf, "lp");
    } else {
      sprintf(buf, "#%d", id);
    }
    break;
  case 32 ... 63:
    sprintf(buf, "u%d", reg - 32);
    break;
  case 64 ... 71:
    sprintf(buf, "cr%d", (reg - 64) * 2 + id);
    break;
  case 72:
    sprintf(buf, "posx");
    break;
  case 73:
    sprintf(buf, "posy");
    break;
  case 75:
    sprintf(buf, "pface");
    break;
  case 76:
    sprintf(buf, "kill");
    break;
  default:
    sprintf(buf, "invalid reg %d", reg);
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<reg_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0x2f1b(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x4c,%rax
ja     1296 <reg_name+0x186>
mov    -0x18(%rbp),%rax
lea    0xebb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xff0(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x10,%edx
lea    0xfbb(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x18,%edx
lea    0xfa2(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x1c,%edx
lea    0xf8b(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e0 <reg_name+0xd0>
mov    -0x10(%rbp),%rdi
lea    0xf70(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11f5 <reg_name+0xe5>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xf59(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x20,%edx
lea    0xf2f(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
sub    $0x40,%edx
shl    $0x1,%edx
add    -0x8(%rbp),%edx
lea    0xf1d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
lea    0xf0b(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
lea    0xef9(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
lea    0xee7(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
lea    0xed6(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ab <reg_name+0x19b>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xec1(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
lea    0x2d8e(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reg_name>:
push   %rax
mov    %edi,%edx
cmp    $0x4c,%edi
ja     11e8 <reg_name+0xd8>
mov    %esi,%eax
mov    %edx,%ecx
lea    0xed9(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
add    $0xffffffe0,%edx
lea    0x2f06(%rip),%rdi
lea    0xff9(%rip),%rsi
jmp    11f6 <reg_name+0xe6>
lea    0x2ef3(%rip),%rdi
lea    0xff8(%rip),%rsi
jmp    11f6 <reg_name+0xe6>
add    $0xfffffff0,%edx
lea    0x2edd(%rip),%rdi
lea    0xfca(%rip),%rsi
jmp    11f6 <reg_name+0xe6>
lea    (%rax,%rdx,2),%edx
add    $0xffffff80,%edx
lea    0x2ec4(%rip),%rdi
lea    0xfc8(%rip),%rsi
jmp    11f6 <reg_name+0xe6>
add    $0xffffffe8,%edx
lea    0x2eb1(%rip),%rdi
lea    0xfa2(%rip),%rsi
jmp    11f6 <reg_name+0xe6>
add    $0xffffffe4,%edx
lea    0x2e9e(%rip),%rdi
lea    0xf95(%rip),%rsi
jmp    11f6 <reg_name+0xe6>
cmp    $0xffffffff,%eax
je     122e <reg_name+0x11e>
lea    0x2e89(%rip),%rdi
lea    0xf89(%rip),%rsi
mov    %eax,%edx
jmp    11f6 <reg_name+0xe6>
movb   $0x0,0x2e7b(%rip)
movl   $0x78736f70,0x2e6d(%rip)
6f 73 78
jmp    11fd <reg_name+0xed>
movb   $0x0,0x2e68(%rip)
movl   $0x79736f70,0x2e5a(%rip)
6f 73 79
jmp    11fd <reg_name+0xed>
lea    0x2e51(%rip),%rdi
lea    0xf6f(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0x2e3c(%rip),%rax
pop    %rcx
ret
movw   $0x65,0x2e35(%rip)
movl   $0x63616670,0x2e27(%rip)
66 61 63
jmp    11fd <reg_name+0xed>
movb   $0x0,0x2e22(%rip)
movl   $0x6c6c696b,0x2e14(%rip)
69 6c 6c
jmp    11fd <reg_name+0xed>
movb   $0x0,0x2e0d(%rip)
movw   $0x706c,0x2e02(%rip)
6c 70
jmp    11fd <reg_name+0xed>

LLVM IR (-O0):
@reg_name.ret = internal global [32 x i8] zeroinitializer
@.str = [4 x i8] c"r%d\00"
@.str.1 = [4 x i8] c"g%d\00"
@.str.2 = [6 x i8] c"alu%d\00"
@.str.3 = [6 x i8] c"imm%d\00"
@.str.4 = [3 x i8] c"lp\00"
@.str.5 = [4 x i8] c"#%d\00"
@.str.6 = [4 x i8] c"u%d\00"
@.str.7 = [5 x i8] c"cr%d\00"
@.str.8 = [5 x i8] c"posx\00"
@.str.9 = [5 x i8] c"posy\00"
@.str.10 = [6 x i8] c"pface\00"
@.str.11 = [5 x i8] c"kill\00"
@.str.12 = [15 x i8] c"invalid reg %d\00"
define i8* @reg_name(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8** %5
%6 = load i32, i32* %3
switch i32 %6, label %62 [
i32 0, label %7
i32 1, label %7
i32 2, label %7
i32 3, label %7
i32 4, label %7
i32 5, label %7
i32 6, label %7
i32 7, label %7
i32 8, label %7
i32 9, label %7
i32 10, label %7
i32 11, label %7
i32 12, label %7
i32 13, label %7
i32 14, label %7
i32 15, label %7
i32 16, label %11
i32 17, label %11
i32 18, label %11
i32 19, label %11
i32 20, label %11
i32 21, label %11
i32 22, label %11
i32 23, label %11
i32 24, label %16
i32 25, label %16
i32 26, label %16
i32 27, label %16
i32 28, label %21
i32 29, label %21
i32 30, label %21
i32 31, label %26
i32 32, label %37
i32 33, label %37
i32 34, label %37
i32 35, label %37
i32 36, label %37
i32 37, label %37
i32 38, label %37
i32 39, label %37
i32 40, label %37
i32 41, label %37
i32 42, label %37
i32 43, label %37
i32 44, label %37
i32 45, label %37
i32 46, label %37
i32 47, label %37
i32 48, label %37
i32 49, label %37
i32 50, label %37
i32 51, label %37
i32 52, label %37
i32 53, label %37
i32 54, label %37
i32 55, label %37
i32 56, label %37
i32 57, label %37
i32 58, label %37
i32 59, label %37
i32 60, label %37
i32 61, label %37
i32 62, label %37
i32 63, label %37
i32 64, label %42
i32 65, label %42
i32 66, label %42
i32 67, label %42
i32 68, label %42
i32 69, label %42
i32 70, label %42
i32 71, label %42
i32 72, label %50
i32 73, label %53
i32 75, label %56
i32 76, label %59
]
7: ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
%8 = load i8*, i8** %5
%9 = load i32, i32* %3
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %66
11: ; preds = %2, %2, %2, %2, %2, %2, %2, %2
%12 = load i8*, i8** %5
%13 = load i32, i32* %3
%14 = sub nsw i32 %13, 16
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %66
16: ; preds = %2, %2, %2, %2
%17 = load i8*, i8** %5
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 24
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %66
21: ; preds = %2, %2, %2
%22 = load i8*, i8** %5
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 28
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %66
26: ; preds = %2
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %5
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %36
32: ; preds = %26
%33 = load i8*, i8** %5
%34 = load i32, i32* %4
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32, %29
br label %66
37: ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
%38 = load i8*, i8** %5
%39 = load i32, i32* %3
%40 = sub nsw i32 %39, 32
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %40)
br label %66
42: ; preds = %2, %2, %2, %2, %2, %2, %2, %2
%43 = load i8*, i8** %5
%44 = load i32, i32* %3
%45 = sub nsw i32 %44, 64
%46 = mul nsw i32 %45, 2
%47 = load i32, i32* %4
%48 = add nsw i32 %46, %47
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %48)
br label %66
50: ; preds = %2
%51 = load i8*, i8** %5
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %66
53: ; preds = %2
%54 = load i8*, i8** %5
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %66
56: ; preds = %2
%57 = load i8*, i8** %5
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %66
59: ; preds = %2
%60 = load i8*, i8** %5
%61 = call i32 (i8*, i8*, ...) @sprintf(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %66
62: ; preds = %2
%63 = load i8*, i8** %5
%64 = load i32, i32* %3
%65 = call i32 (i8*, i8*, ...) @sprintf(i8* %63, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %62, %59, %56, %53, %50, %42, %37, %36, %21, %16, %11, %7
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0)
}

LLVM IR (-O2):
@reg_name.ret = internal global [32 x i8] zeroinitializer
@.str = [4 x i8] c"r%d\00"
@.str.1 = [4 x i8] c"g%d\00"
@.str.2 = [6 x i8] c"alu%d\00"
@.str.3 = [6 x i8] c"imm%d\00"
@.str.4 = [3 x i8] c"lp\00"
@.str.5 = [4 x i8] c"#%d\00"
@.str.6 = [4 x i8] c"u%d\00"
@.str.7 = [5 x i8] c"cr%d\00"
@.str.8 = [5 x i8] c"posx\00"
@.str.9 = [5 x i8] c"posy\00"
@.str.10 = [6 x i8] c"pface\00"
@.str.11 = [5 x i8] c"kill\00"
@.str.12 = [15 x i8] c"invalid reg %d\00"
define i8* @reg_name(i32 %0, i32 %1) {
switch i32 %0, label %31 [
i32 0, label %3
i32 1, label %3
i32 2, label %3
i32 3, label %3
i32 4, label %3
i32 5, label %3
i32 6, label %3
i32 7, label %3
i32 8, label %3
i32 9, label %3
i32 10, label %3
i32 11, label %3
i32 12, label %3
i32 13, label %3
i32 14, label %3
i32 15, label %3
i32 16, label %5
i32 17, label %5
i32 18, label %5
i32 19, label %5
i32 20, label %5
i32 21, label %5
i32 22, label %5
i32 23, label %5
i32 24, label %8
i32 25, label %8
i32 26, label %8
i32 27, label %8
i32 28, label %11
i32 29, label %11
i32 30, label %11
i32 31, label %14
i32 32, label %19
i32 33, label %19
i32 34, label %19
i32 35, label %19
i32 36, label %19
i32 37, label %19
i32 38, label %19
i32 39, label %19
i32 40, label %19
i32 41, label %19
i32 42, label %19
i32 43, label %19
i32 44, label %19
i32 45, label %19
i32 46, label %19
i32 47, label %19
i32 48, label %19
i32 49, label %19
i32 50, label %19
i32 51, label %19
i32 52, label %19
i32 53, label %19
i32 54, label %19
i32 55, label %19
i32 56, label %19
i32 57, label %19
i32 58, label %19
i32 59, label %19
i32 60, label %19
i32 61, label %19
i32 62, label %19
i32 63, label %19
i32 64, label %22
i32 65, label %22
i32 66, label %22
i32 67, label %22
i32 68, label %22
i32 69, label %22
i32 70, label %22
i32 71, label %22
i32 72, label %27
i32 73, label %28
i32 75, label %29
i32 76, label %30
]
3: ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
%4 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %33
5: ; preds = %2, %2, %2, %2, %2, %2, %2, %2
%6 = add nsw i32 %0, -16
%7 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %33
8: ; preds = %2, %2, %2, %2
%9 = add nsw i32 %0, -24
%10 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %33
11: ; preds = %2, %2, %2
%12 = add nsw i32 %0, -28
%13 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %33
14: ; preds = %2
%15 = icmp eq i32 %1, -1
br i1 %15, label %16, label %17
16: ; preds = %14
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(3) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 3, i1 false)
br label %33
17: ; preds = %14
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %1)
br label %33
19: ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
%20 = add nsw i32 %0, -32
%21 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %20)
br label %33
22: ; preds = %2, %2, %2, %2, %2, %2, %2, %2
%23 = shl nuw nsw i32 %0, 1
%24 = add nsw i32 %23, -128
%25 = add nsw i32 %24, %1
%26 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %25)
br label %33
27: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(5) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64 5, i1 false)
br label %33
28: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(5) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i64 5, i1 false)
br label %33
29: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(6) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i64 6, i1 false)
br label %33
30: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(5) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i64 5, i1 false)
br label %33
31: ; preds = %2
%32 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i32 %0)
br label %33
33: ; preds = %16, %17, %31, %30, %29, %28, %27, %22, %19, %11, %8, %5, %3
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @reg_name.ret, i64 0, i64 0)
}