const char *lockName(int eLock) {
  const char *azLockNames[] = {"NONE", "SHARED", "RESERVED", "PENDING",
                               "EXCLUSIVE"};
  if (eLock < 0 || eLock >= sizeof(azLockNames) / sizeof(azLockNames[0])) {
    return "???";
  } else {
    return azLockNames[eLock];
  }
}


x86 assembly (clang, -O0):
<lockName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
lea    0xece(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xec8(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xec4(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xec2(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xebf(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     117a <lockName+0x6a>
movslq -0xc(%rbp),%rax
cmp    $0x5,%rax
jb     118a <lockName+0x7a>
lea    0xea6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1197 <lockName+0x87>
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lockName>:
lea    0xef9(%rip),%rax
mov    %rax,-0x28(%rsp)
lea    0xef2(%rip),%rax
mov    %rax,-0x20(%rsp)
lea    0xeed(%rip),%rax
mov    %rax,-0x18(%rsp)
lea    0xeea(%rip),%rax
mov    %rax,-0x10(%rsp)
lea    0xee6(%rip),%rax
mov    %rax,-0x8(%rsp)
cmp    $0x4,%edi
jbe    1149 <lockName+0x49>
lea    0xedf(%rip),%rax
ret
mov    %edi,%eax
mov    -0x28(%rsp,%rax,8),%rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"NONE\00"
@.str.1 = [7 x i8] c"SHARED\00"
@.str.2 = [9 x i8] c"RESERVED\00"
@.str.3 = [8 x i8] c"PENDING\00"
@.str.4 = [10 x i8] c"EXCLUSIVE\00"
@.str.5 = [4 x i8] c"???\00"
define i8* @lockName(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [5 x i8*]
store i32 %0, i32* %3
%5 = bitcast [5 x i8*]* %4 to i8*
%6 = bitcast i8* %5 to [5 x i8*]*
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8** %11
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = icmp uge i64 %16, 5
br i1 %17, label %18, label %19
18: ; preds = %14, %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %24
19: ; preds = %14
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 %21
%23 = load i8*, i8** %22
store i8* %23, i8** %2
br label %24
24: ; preds = %19, %18
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"NONE\00"
@.str.1 = [7 x i8] c"SHARED\00"
@.str.2 = [9 x i8] c"RESERVED\00"
@.str.3 = [8 x i8] c"PENDING\00"
@.str.4 = [10 x i8] c"EXCLUSIVE\00"
@.str.5 = [4 x i8] c"???\00"
define i8* @lockName(i32 %0) {
%2 = alloca [5 x i8*]
%3 = bitcast [5 x i8*]* %2 to i8*
%4 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %8
%9 = icmp ugt i32 %0, 4
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = zext i32 %0 to i64
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %11
%13 = load i8*, i8** %12
br label %14
14: ; preds = %1, %10
%15 = phi i8* [ %13, %10 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %1 ]
ret i8* %15
}