const char *event_type_string(int type) {
  static const char *strings[] = {
      "SCENARIO_START", "SCENARIO_DONE", "SWITCH_ON",      "SWITCH_OFF",
      "WORKER_ON",      "WORKER_ONLINE", "WORKER_OFFLINE", "WORKER_OFF",
      "WORKER_REBOOT",  "WORK_REQUEST",  "WORK_COMMAND",   "WORK_ACK",
      "WORK_COMPLETE",  "HALT_COMMAND",  "HALT_ACK",       "MEM_COMMAND",
      "MEM_ACK",        "E_METER_RESET", "ADAPT",
  };
  return strings[type];
}


x86 assembly (clang, -O0):
<event_type_string>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rcx
lea    0x2f1e(%rip),%rax
mov    (%rax,%rcx,8),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<event_type_string>:
movslq %edi,%rax
lea    0xef6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@event_type_string.strings = internal global [19 x i8*] [i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i32 0, i32 0)]
@.str = [15 x i8] c"SCENARIO_START\00"
@.str.1 = [14 x i8] c"SCENARIO_DONE\00"
@.str.2 = [10 x i8] c"SWITCH_ON\00"
@.str.3 = [11 x i8] c"SWITCH_OFF\00"
@.str.4 = [10 x i8] c"WORKER_ON\00"
@.str.5 = [14 x i8] c"WORKER_ONLINE\00"
@.str.6 = [15 x i8] c"WORKER_OFFLINE\00"
@.str.7 = [11 x i8] c"WORKER_OFF\00"
@.str.8 = [14 x i8] c"WORKER_REBOOT\00"
@.str.9 = [13 x i8] c"WORK_REQUEST\00"
@.str.10 = [13 x i8] c"WORK_COMMAND\00"
@.str.11 = [9 x i8] c"WORK_ACK\00"
@.str.12 = [14 x i8] c"WORK_COMPLETE\00"
@.str.13 = [13 x i8] c"HALT_COMMAND\00"
@.str.14 = [9 x i8] c"HALT_ACK\00"
@.str.15 = [12 x i8] c"MEM_COMMAND\00"
@.str.16 = [8 x i8] c"MEM_ACK\00"
@.str.17 = [14 x i8] c"E_METER_RESET\00"
@.str.18 = [6 x i8] c"ADAPT\00"
define i8* @event_type_string(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds [19 x i8*], [19 x i8*]* @event_type_string.strings, i64 0, i64 %4
%6 = load i8*, i8** %5
ret i8* %6
}

LLVM IR (-O2):
@reltable.event_type_string = internal unnamed_addr constant [19 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.1 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.2 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.4 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.5 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.6 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.7 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.8 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.9 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.10 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.11 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.12 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.13 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.14 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.15 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.16 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.17 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.18 to i64), i64 ptrtoint ([19 x i32]* @reltable.event_type_string to i64)) to i32)]
@.str = [15 x i8] c"SCENARIO_START\00"
@.str.1 = [14 x i8] c"SCENARIO_DONE\00"
@.str.2 = [10 x i8] c"SWITCH_ON\00"
@.str.3 = [11 x i8] c"SWITCH_OFF\00"
@.str.4 = [10 x i8] c"WORKER_ON\00"
@.str.5 = [14 x i8] c"WORKER_ONLINE\00"
@.str.6 = [15 x i8] c"WORKER_OFFLINE\00"
@.str.7 = [11 x i8] c"WORKER_OFF\00"
@.str.8 = [14 x i8] c"WORKER_REBOOT\00"
@.str.9 = [13 x i8] c"WORK_REQUEST\00"
@.str.10 = [13 x i8] c"WORK_COMMAND\00"
@.str.11 = [9 x i8] c"WORK_ACK\00"
@.str.12 = [14 x i8] c"WORK_COMPLETE\00"
@.str.13 = [13 x i8] c"HALT_COMMAND\00"
@.str.14 = [9 x i8] c"HALT_ACK\00"
@.str.15 = [12 x i8] c"MEM_COMMAND\00"
@.str.16 = [8 x i8] c"MEM_ACK\00"
@.str.17 = [14 x i8] c"E_METER_RESET\00"
@.str.18 = [6 x i8] c"ADAPT\00"
define i8* @event_type_string(i32 %0) {
%2 = sext i32 %0 to i64
%3 = shl i64 %2, 2
%4 = call i8* @llvm.load.relative.i64(i8* bitcast ([19 x i32]* @reltable.event_type_string to i8*), i64 %3)
ret i8* %4
}