#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 */
typedef int u_int;

/* Variables and functions */
const char *State2Nam(u_int state) {
  static const char *const StateNames[] = {
      "Initial",  "Starting", "Closed",   "Stopped",  "Closing",
      "Stopping", "Req-Sent", "Ack-Rcvd", "Ack-Sent", "Opened",
  };
  if (state >= sizeof StateNames / sizeof StateNames[0])
    return "unknown";
  return StateNames[state];
}


x86 assembly (clang, -O0):
<State2Nam>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0xa,%rax
jb     1125 <State2Nam+0x25>
lea    0xf37(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1138 <State2Nam+0x38>
movslq -0xc(%rbp),%rcx
lea    0x2cd0(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<State2Nam>:
cmp    $0x9,%edi
jbe    110d <State2Nam+0xd>
lea    0xf6f(%rip),%rax
ret
mov    %edi,%eax
lea    0xeea(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@State2Nam.StateNames = internal constant [10 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i32 0, i32 0)]
@.str = [8 x i8] c"Initial\00"
@.str.1 = [9 x i8] c"Starting\00"
@.str.2 = [7 x i8] c"Closed\00"
@.str.3 = [8 x i8] c"Stopped\00"
@.str.4 = [8 x i8] c"Closing\00"
@.str.5 = [9 x i8] c"Stopping\00"
@.str.6 = [9 x i8] c"Req-Sent\00"
@.str.7 = [9 x i8] c"Ack-Rcvd\00"
@.str.8 = [9 x i8] c"Ack-Sent\00"
@.str.9 = [7 x i8] c"Opened\00"
@.str.10 = [8 x i8] c"unknown\00"
define i8* @State2Nam(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = sext i32 %4 to i64
%6 = icmp uge i64 %5, 10
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %13
8: ; preds = %1
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [10 x i8*], [10 x i8*]* @State2Nam.StateNames, i64 0, i64 %10
%12 = load i8*, i8** %11
store i8* %12, i8** %2
br label %13
13: ; preds = %8, %7
%14 = load i8*, i8** %2
ret i8* %14
}

LLVM IR (-O2):
@reltable.State2Nam = internal unnamed_addr constant [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.State2Nam to i64)) to i32)]
@.str = [8 x i8] c"Initial\00"
@.str.1 = [9 x i8] c"Starting\00"
@.str.2 = [7 x i8] c"Closed\00"
@.str.3 = [8 x i8] c"Stopped\00"
@.str.4 = [8 x i8] c"Closing\00"
@.str.5 = [9 x i8] c"Stopping\00"
@.str.6 = [9 x i8] c"Req-Sent\00"
@.str.7 = [9 x i8] c"Ack-Rcvd\00"
@.str.8 = [9 x i8] c"Ack-Sent\00"
@.str.9 = [7 x i8] c"Opened\00"
@.str.10 = [8 x i8] c"unknown\00"
define i8* @State2Nam(i32 %0) {
%2 = icmp ugt i32 %0, 9
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = zext i32 %0 to i64
%5 = shl i64 %4, 2
%6 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.State2Nam to i8*), i64 %5)
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), %1 ]
ret i8* %8
}