#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 /*<<< orphan*/ code_table;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int print_error(int code) {
  static char *code_table[] = {
      "CMD_SUCCESS",         "INCALID_COMMAND",
      "SRC_ADDR_ERROR",      "DST_ADDR_ERROR",
      "SRC_ADDR_NOT_MAPPED", "DST_ADDR_NOT_MAPPED",
      "COUNT_ERROR",         "INVALID_SECTOR",
      "SECTOR_NOT_BLANK",    "SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION",
      "COMPARE_ERROR",       "BUSY",
      "PARAM_ERROR",         "ADDR_ERROR",
      "ADDR_NOT_MAPPED",     "CMD_LOCKED",
      "INVALID_CODE",        "INVALID_BAUD_RATE",
      "INVALID_STOP_BIT",    "CODE_READ_PROTECTION_ENABLED"};
  if (code < 0 || code >= sizeof(code_table) / sizeof(char *)) {
    fprintf(stderr, "unknown return code\n");
    return 33;
  }
  fprintf(stderr, "%s\n", code_table[code]);
  return code;
}


x86 assembly (clang, -O0):
<print_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1133 <print_error+0x23>
movslq -0x8(%rbp),%rax
cmp    $0x14,%rax
jb     1156 <print_error+0x46>
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
lea    0xfea(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x21,-0x4(%rbp)
jmp    1182 <print_error+0x72>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
movslq -0x8(%rbp),%rcx
lea    0x2ec6(%rip),%rax
mov    (%rax,%rcx,8),%rdx
lea    0xfcd(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_error>:
push   %rbx
cmp    $0x14,%edi
jb     1134 <print_error+0x24>
mov    0x2ec3(%rip),%rax
mov    (%rax),%edi
lea    0x1057(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x21,%ebx
jmp    115d <print_error+0x4d>
mov    %edi,%ebx
mov    %edi,%eax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%edi
lea    0xeb8(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
lea    0x103c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@print_error.code_table = internal global [20 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.19, i32 0, i32 0)]
@.str = [12 x i8] c"CMD_SUCCESS\00"
@.str.1 = [16 x i8] c"INCALID_COMMAND\00"
@.str.2 = [15 x i8] c"SRC_ADDR_ERROR\00"
@.str.3 = [15 x i8] c"DST_ADDR_ERROR\00"
@.str.4 = [20 x i8] c"SRC_ADDR_NOT_MAPPED\00"
@.str.5 = [20 x i8] c"DST_ADDR_NOT_MAPPED\00"
@.str.6 = [12 x i8] c"COUNT_ERROR\00"
@.str.7 = [15 x i8] c"INVALID_SECTOR\00"
@.str.8 = [17 x i8] c"SECTOR_NOT_BLANK\00"
@.str.9 = [40 x i8] c"SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION\00"
@.str.10 = [14 x i8] c"COMPARE_ERROR\00"
@.str.11 = [5 x i8] c"BUSY\00"
@.str.12 = [12 x i8] c"PARAM_ERROR\00"
@.str.13 = [11 x i8] c"ADDR_ERROR\00"
@.str.14 = [16 x i8] c"ADDR_NOT_MAPPED\00"
@.str.15 = [11 x i8] c"CMD_LOCKED\00"
@.str.16 = [13 x i8] c"INVALID_CODE\00"
@.str.17 = [18 x i8] c"INVALID_BAUD_RATE\00"
@.str.18 = [17 x i8] c"INVALID_STOP_BIT\00"
@.str.19 = [29 x i8] c"CODE_READ_PROTECTION_ENABLED\00"
@stderr = global i32 0
@.str.20 = [21 x i8] c"unknown return code\0A\00"
@.str.21 = [4 x i8] c"%s\0A\00"
define i32 @print_error(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = icmp uge i64 %8, 20
br i1 %9, label %10, label %13
10: ; preds = %6, %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0))
store i32 33, i32* %2
br label %21
13: ; preds = %6
%14 = load i32, i32* @stderr
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [20 x i8*], [20 x i8*]* @print_error.code_table, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.21, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %3
store i32 %20, i32* %2
br label %21
21: ; preds = %13, %10
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@reltable.print_error = internal unnamed_addr constant [20 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.1 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.2 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.3 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.4 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.5 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.6 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.7 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.8 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([40 x i8]* @.str.9 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.10 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.11 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.12 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.13 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.14 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.15 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.16 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.17 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.18 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([29 x i8]* @.str.19 to i64), i64 ptrtoint ([20 x i32]* @reltable.print_error to i64)) to i32)]
@.str = [12 x i8] c"CMD_SUCCESS\00"
@.str.1 = [16 x i8] c"INCALID_COMMAND\00"
@.str.2 = [15 x i8] c"SRC_ADDR_ERROR\00"
@.str.3 = [15 x i8] c"DST_ADDR_ERROR\00"
@.str.4 = [20 x i8] c"SRC_ADDR_NOT_MAPPED\00"
@.str.5 = [20 x i8] c"DST_ADDR_NOT_MAPPED\00"
@.str.6 = [12 x i8] c"COUNT_ERROR\00"
@.str.7 = [15 x i8] c"INVALID_SECTOR\00"
@.str.8 = [17 x i8] c"SECTOR_NOT_BLANK\00"
@.str.9 = [40 x i8] c"SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION\00"
@.str.10 = [14 x i8] c"COMPARE_ERROR\00"
@.str.11 = [5 x i8] c"BUSY\00"
@.str.12 = [12 x i8] c"PARAM_ERROR\00"
@.str.13 = [11 x i8] c"ADDR_ERROR\00"
@.str.14 = [16 x i8] c"ADDR_NOT_MAPPED\00"
@.str.15 = [11 x i8] c"CMD_LOCKED\00"
@.str.16 = [13 x i8] c"INVALID_CODE\00"
@.str.17 = [18 x i8] c"INVALID_BAUD_RATE\00"
@.str.18 = [17 x i8] c"INVALID_STOP_BIT\00"
@.str.19 = [29 x i8] c"CODE_READ_PROTECTION_ENABLED\00"
@stderr = global i32 0
@.str.20 = [21 x i8] c"unknown return code\0A\00"
@.str.21 = [4 x i8] c"%s\0A\00"
define i32 @print_error(i32 %0) {
%2 = icmp ugt i32 %0, 19
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0))
br label %12
6: ; preds = %1
%7 = zext i32 %0 to i64
%8 = load i32, i32* @stderr
%9 = shl i64 %7, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([20 x i32]* @reltable.print_error to i8*), i64 %9)
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.21, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %6, %3
%13 = phi i32 [ 33, %3 ], [ %0, %6 ]
ret i32 %13
}