#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 /*<<< orphan*/ s_strlcpy(char *, char *, int);
char *SakuraObj_getErrorMsg(int errno, char *buf, int len) {
  switch (errno) {
  case 0x1100:
    s_strlcpy(buf, "K_ERROR_SYSTEM", len - 1);
    return buf;
  case 0x1101:
    s_strlcpy(buf, "K_ERROR_SYNTAX", len - 1);
    return buf;
  case 0x1102:
    s_strlcpy(buf, "K_ERROR_FILE_READ", len - 1);
    return buf;
  case 0x1103:
    s_strlcpy(buf, "K_ERROR_LOOP_RANGE", len - 1);
    return buf;
  case 0x1104:
    s_strlcpy(buf, "K_ERROR_FILE_WRITE", len - 1);
    return buf;
  case 0x1105:
    s_strlcpy(buf, "K_ERROR_ARG_COUNT", len - 1);
    return buf;
  }
  s_strlcpy(buf, "K_ERROR_UNKNOWN", len - 1);
  return buf;
}


x86 assembly (clang, -O0):
<SakuraObj_getErrorMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffef00,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     121f <SakuraObj_getErrorMsg+0x10f>
mov    -0x28(%rbp),%rax
lea    0xebc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
lea    0xeba(%rip),%rsi
call   1030 <s_strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123d <SakuraObj_getErrorMsg+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
lea    0xea6(%rip),%rsi
call   1030 <s_strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123d <SakuraObj_getErrorMsg+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
lea    0xe92(%rip),%rsi
call   1030 <s_strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123d <SakuraObj_getErrorMsg+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
lea    0xe81(%rip),%rsi
call   1030 <s_strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123d <SakuraObj_getErrorMsg+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
lea    0xe71(%rip),%rsi
call   1030 <s_strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123d <SakuraObj_getErrorMsg+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
lea    0xe61(%rip),%rsi
call   1030 <s_strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123d <SakuraObj_getErrorMsg+0x12d>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
lea    0xe50(%rip),%rsi
call   1030 <s_strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SakuraObj_getErrorMsg>:
push   %rbx
mov    %rsi,%rbx
add    $0xffffef00,%edi
cmp    $0x5,%edi
ja     1132 <SakuraObj_getErrorMsg+0x22>
movslq %edi,%rax
lea    0xf4f(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    1139 <SakuraObj_getErrorMsg+0x29>
lea    0xf2f(%rip),%rsi
add    $0xffffffff,%edx
mov    %rbx,%rdi
call   1030 <s_strlcpy@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"K_ERROR_SYSTEM\00"
@.str.1 = [15 x i8] c"K_ERROR_SYNTAX\00"
@.str.2 = [18 x i8] c"K_ERROR_FILE_READ\00"
@.str.3 = [19 x i8] c"K_ERROR_LOOP_RANGE\00"
@.str.4 = [19 x i8] c"K_ERROR_FILE_WRITE\00"
@.str.5 = [18 x i8] c"K_ERROR_ARG_COUNT\00"
@.str.6 = [16 x i8] c"K_ERROR_UNKNOWN\00"
define i8* @SakuraObj_getErrorMsg(i32 %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
switch i32 %8, label %45 [
i32 4352, label %9
i32 4353, label %15
i32 4354, label %21
i32 4355, label %27
i32 4356, label %33
i32 4357, label %39
]
9: ; preds = %3
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = sub nsw i32 %11, 1
%13 = call i32 @s_strlcpy(i8* %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8*, i8** %6
store i8* %14, i8** %4
br label %51
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = sub nsw i32 %17, 1
%19 = call i32 @s_strlcpy(i8* %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i8*, i8** %6
store i8* %20, i8** %4
br label %51
21: ; preds = %3
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 1
%25 = call i32 @s_strlcpy(i8* %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %6
store i8* %26, i8** %4
br label %51
27: ; preds = %3
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = sub nsw i32 %29, 1
%31 = call i32 @s_strlcpy(i8* %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i8*, i8** %6
store i8* %32, i8** %4
br label %51
33: ; preds = %3
%34 = load i8*, i8** %6
%35 = load i32, i32* %7
%36 = sub nsw i32 %35, 1
%37 = call i32 @s_strlcpy(i8* %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = load i8*, i8** %6
store i8* %38, i8** %4
br label %51
39: ; preds = %3
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = sub nsw i32 %41, 1
%43 = call i32 @s_strlcpy(i8* %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %42)
%44 = load i8*, i8** %6
store i8* %44, i8** %4
br label %51
45: ; preds = %3
%46 = load i8*, i8** %6
%47 = load i32, i32* %7
%48 = sub nsw i32 %47, 1
%49 = call i32 @s_strlcpy(i8* %46, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = load i8*, i8** %6
store i8* %50, i8** %4
br label %51
51: ; preds = %45, %39, %33, %27, %21, %15, %9
%52 = load i8*, i8** %4
ret i8* %52
}

LLVM IR (-O2):
@.str = [15 x i8] c"K_ERROR_SYSTEM\00"
@.str.1 = [15 x i8] c"K_ERROR_SYNTAX\00"
@.str.2 = [18 x i8] c"K_ERROR_FILE_READ\00"
@.str.3 = [19 x i8] c"K_ERROR_LOOP_RANGE\00"
@.str.4 = [19 x i8] c"K_ERROR_FILE_WRITE\00"
@.str.5 = [18 x i8] c"K_ERROR_ARG_COUNT\00"
@.str.6 = [16 x i8] c"K_ERROR_UNKNOWN\00"
@reltable.SakuraObj_getErrorMsg = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str to i64), i64 ptrtoint ([6 x i32]* @reltable.SakuraObj_getErrorMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.SakuraObj_getErrorMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.SakuraObj_getErrorMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.SakuraObj_getErrorMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.SakuraObj_getErrorMsg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.SakuraObj_getErrorMsg to i64)) to i32)]
define i8* @SakuraObj_getErrorMsg(i32 %0, i8* returned %1, i32 %2) {
%4 = add i32 %0, -4352
%5 = icmp ult i32 %4, 6
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.SakuraObj_getErrorMsg to i8*), i64 %8)
br label %10
10: ; preds = %3, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), %3 ]
%12 = add nsw i32 %2, -1
%13 = tail call i32 @s_strlcpy(i8* %1, i8* %11, i32 %12)
ret i8* %1
}