#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 */
int /*<<< orphan*/ sprintf(char *, char *, int);
const char *regname(int a) {
  switch (a & 036) {
  case 000:
    return "ID";
  case 004:
    return "ERR";
  case 006:
    return "SECTOR";
  case 010:
    return "DATA";
  case 012:
    return "CYL";
  case 014:
    return "HEAD";
  case 016:
    return "CS";
  case 020:
    return "SI";
  }
  static char buf[16];
  sprintf(buf, "%06o", a);
  return buf;
}


x86 assembly (clang, -O0):
<regname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1e,%eax
mov    %rax,-0x18(%rbp)
sub    $0x10,%eax
ja     11c2 <regname+0xb2>
mov    -0x18(%rbp),%rax
lea    0xec7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xefb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <regname+0xd3>
lea    0xeee(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <regname+0xd3>
lea    0xee2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <regname+0xd3>
lea    0xed9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <regname+0xd3>
lea    0xece(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <regname+0xd3>
lea    0xec2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <regname+0xd3>
lea    0xeb7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <regname+0xd3>
lea    0xeaa(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <regname+0xd3>
mov    -0xc(%rbp),%edx
lea    0x2e74(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2e61(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regname>:
push   %rbx
mov    %edi,%edx
mov    %edi,%eax
and    $0x1e,%eax
cmp    $0x11,%eax
jae    1127 <regname+0x17>
mov    $0x15551,%ecx
bt     %eax,%ecx
jb     113f <regname+0x2f>
lea    0x2f12(%rip),%rbx
lea    0xeed(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
jmp    114f <regname+0x3f>
mov    %eax,%eax
lea    0xee0(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ID\00"
@.str.1 = [4 x i8] c"ERR\00"
@.str.2 = [7 x i8] c"SECTOR\00"
@.str.3 = [5 x i8] c"DATA\00"
@.str.4 = [4 x i8] c"CYL\00"
@.str.5 = [5 x i8] c"HEAD\00"
@.str.6 = [3 x i8] c"CS\00"
@.str.7 = [3 x i8] c"SI\00"
@regname.buf = internal global [16 x i8] zeroinitializer
@.str.8 = [5 x i8] c"%06o\00"
define i8* @regname(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = and i32 %4, 30
switch i32 %5, label %14 [
i32 0, label %6
i32 4, label %7
i32 6, label %8
i32 8, label %9
i32 10, label %10
i32 12, label %11
i32 14, label %12
i32 16, label %13
]
6: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %17
7: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %17
8: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %17
9: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %17
10: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %17
11: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %17
12: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %17
13: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %17
14: ; preds = %1
%15 = load i32, i32* %3
%16 = call i32 @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @regname.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 %15)
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @regname.buf, i64 0, i64 0), i8** %2
br label %17
17: ; preds = %14, %13, %12, %11, %10, %9, %8, %7, %6
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
@.str = [3 x i8] c"ID\00"
@.str.1 = [4 x i8] c"ERR\00"
@.str.2 = [7 x i8] c"SECTOR\00"
@.str.3 = [5 x i8] c"DATA\00"
@.str.4 = [4 x i8] c"CYL\00"
@.str.5 = [5 x i8] c"HEAD\00"
@.str.6 = [3 x i8] c"CS\00"
@.str.7 = [3 x i8] c"SI\00"
@regname.buf = internal global [16 x i8] zeroinitializer
@.str.8 = [5 x i8] c"%06o\00"
@reltable.regname = [17 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.6 to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.7 to i64), i64 ptrtoint ([17 x i32]* @reltable.regname to i64)) to i32)]
define i8* @regname(i32 %0) {
%2 = and i32 %0, 30
%3 = icmp ult i32 %2, 17
br i1 %3, label %6, label %4
4: ; preds = %6, %1
%5 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @regname.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 %0)
br label %14
6: ; preds = %1
%7 = lshr i32 87377, %2
%8 = and i32 %7, 1
%9 = icmp eq i32 %8, 0
br i1 %9, label %4, label %10
10: ; preds = %6
%11 = zext i32 %2 to i64
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([17 x i32]* @reltable.regname to i8*), i64 %12)
br label %14
14: ; preds = %10, %4
%15 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @regname.buf, i64 0, i64 0), %4 ], [ %13, %10 ]
ret i8* %15
}