#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 csv_error_string(int code, char **out_error_string) {
  static const char *strings[] = {"OK",
                                  "End",
                                  "Null pointer",
                                  "Unexpected newline",
                                  "Field count can not be zero",
                                  "I/O error",
                                  "Too few fields for record",
                                  "Too many fields for record",
                                  "Not enough lines to skip",
                                  "Invalid return code"};
  if (out_error_string == NULL)
    return 2;
  if (code < 0 || code > 9)
    return 9;
  *out_error_string = (char *)strings[code];
  return 0;
}


x86 assembly (clang, -O0):
<csv_error_string>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1122 <csv_error_string+0x22>
movl   $0x2,-0x4(%rbp)
jmp    115f <csv_error_string+0x5f>
cmpl   $0x0,-0x8(%rbp)
jl     1136 <csv_error_string+0x36>
cmpl   $0x9,-0x8(%rbp)
jle    1142 <csv_error_string+0x42>
movl   $0x9,-0x4(%rbp)
jmp    115f <csv_error_string+0x5f>
movslq -0x8(%rbp),%rcx
lea    0x2ee3(%rip),%rax
mov    (%rax,%rcx,8),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<csv_error_string>:
test   %rsi,%rsi
je     1125 <csv_error_string+0x25>
mov    $0x9,%eax
cmp    $0x9,%edi
ja     1124 <csv_error_string+0x24>
mov    %edi,%eax
lea    0xee8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
mov    %rax,(%rsi)
xor    %eax,%eax
ret
mov    $0x2,%eax
ret

LLVM IR (-O0):
@csv_error_string.strings = internal global [10 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i32 0, i32 0)]
@.str = [3 x i8] c"OK\00"
@.str.1 = [4 x i8] c"End\00"
@.str.2 = [13 x i8] c"Null pointer\00"
@.str.3 = [19 x i8] c"Unexpected newline\00"
@.str.4 = [28 x i8] c"Field count can not be zero\00"
@.str.5 = [10 x i8] c"I/O error\00"
@.str.6 = [26 x i8] c"Too few fields for record\00"
@.str.7 = [27 x i8] c"Too many fields for record\00"
@.str.8 = [25 x i8] c"Not enough lines to skip\00"
@.str.9 = [20 x i8] c"Invalid return code\00"
define i32 @csv_error_string(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i8**, i8*** %5
%7 = icmp eq i8** %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 2, i32* %3
br label %22
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 9
br i1 %14, label %15, label %16
15: ; preds = %12, %9
store i32 9, i32* %3
br label %22
16: ; preds = %12
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10 x i8*], [10 x i8*]* @csv_error_string.strings, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
store i8* %20, i8** %21
store i32 0, i32* %3
br label %22
22: ; preds = %16, %15, %8
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@reltable.csv_error_string = internal unnamed_addr constant [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.csv_error_string to i64)) to i32)]
@.str = [3 x i8] c"OK\00"
@.str.1 = [4 x i8] c"End\00"
@.str.2 = [13 x i8] c"Null pointer\00"
@.str.3 = [19 x i8] c"Unexpected newline\00"
@.str.4 = [28 x i8] c"Field count can not be zero\00"
@.str.5 = [10 x i8] c"I/O error\00"
@.str.6 = [26 x i8] c"Too few fields for record\00"
@.str.7 = [27 x i8] c"Too many fields for record\00"
@.str.8 = [25 x i8] c"Not enough lines to skip\00"
@.str.9 = [20 x i8] c"Invalid return code\00"
define i32 @csv_error_string(i32 %0, i8** writeonly %1) {
%3 = icmp eq i8** %1, null
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = icmp ugt i32 %0, 9
br i1 %5, label %10, label %6
6: ; preds = %4
%7 = zext i32 %0 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.csv_error_string to i8*), i64 %8)
store i8* %9, i8** %1
br label %10
10: ; preds = %4, %2, %6
%11 = phi i32 [ 0, %6 ], [ 2, %2 ], [ 9, %4 ]
ret i32 %11
}