const char *gps_error_string(const int e) {
  static const char *msg[] = {
      "No error while parsing NMEA", "Header '$' missing",
      "Footer CRLF missing",         "Checksum did not match",
      "Sentence truncated",          "Unsupported NMEA sentence"};
  if ((0 <= e) && (e < ((int)(sizeof(msg) / sizeof(msg[0])))))
    return msg[e];
  return "Unknown error";
}


x86 assembly (clang, -O0):
<gps_error_string>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jg     1134 <gps_error_string+0x34>
cmpl   $0x6,-0xc(%rbp)
jge    1134 <gps_error_string+0x34>
movslq -0xc(%rbp),%rcx
lea    0x2f09(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    113f <gps_error_string+0x3f>
lea    0xf4c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<gps_error_string>:
cmp    $0x5,%edi
ja     1116 <gps_error_string+0x16>
mov    %edi,%eax
lea    0xef2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xf82(%rip),%rax
ret

LLVM IR (-O0):
@gps_error_string.msg = internal global [6 x i8*] [i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i32 0, i32 0)]
@.str = [28 x i8] c"No error while parsing NMEA\00"
@.str.1 = [19 x i8] c"Header '$' missing\00"
@.str.2 = [20 x i8] c"Footer CRLF missing\00"
@.str.3 = [23 x i8] c"Checksum did not match\00"
@.str.4 = [19 x i8] c"Sentence truncated\00"
@.str.5 = [26 x i8] c"Unsupported NMEA sentence\00"
@.str.6 = [14 x i8] c"Unknown error\00"
define i8* @gps_error_string(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sle i32 0, %4
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 6
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* @gps_error_string.msg, i64 0, i64 %11
%13 = load i8*, i8** %12
store i8* %13, i8** %2
br label %15
14: ; preds = %6, %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %15
15: ; preds = %14, %9
%16 = load i8*, i8** %2
ret i8* %16
}

LLVM IR (-O2):
@reltable.gps_error_string = internal unnamed_addr constant [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str to i64), i64 ptrtoint ([6 x i32]* @reltable.gps_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.gps_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.gps_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.gps_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.gps_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.gps_error_string to i64)) to i32)]
@.str = [28 x i8] c"No error while parsing NMEA\00"
@.str.1 = [19 x i8] c"Header '$' missing\00"
@.str.2 = [20 x i8] c"Footer CRLF missing\00"
@.str.3 = [23 x i8] c"Checksum did not match\00"
@.str.4 = [19 x i8] c"Sentence truncated\00"
@.str.5 = [26 x i8] c"Unsupported NMEA sentence\00"
@.str.6 = [14 x i8] c"Unknown error\00"
define i8* @gps_error_string(i32 %0) {
%2 = icmp ult i32 %0, 6
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = zext i32 %0 to i64
%5 = shl i64 %4, 2
%6 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.gps_error_string to i8*), i64 %5)
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), %1 ]
ret i8* %8
}