#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
const char *region_filename(int region_type) {
  static const char *region_filenames[9] = {
      "flashregion_0_flashdescriptor.bin",
      "flashregion_1_bios.bin",
      "flashregion_2_intel_me.bin",
      "flashregion_3_gbe.bin",
      "flashregion_4_platform_data.bin",
      "flashregion_5_reserved.bin",
      "flashregion_6_reserved.bin",
      "flashregion_7_reserved.bin",
      "flashregion_8_ec.bin",
  };
  if (region_type < 0 || region_type >= 9) {
    fprintf(stderr, "Invalid region type %d.\n", region_type);
    exit(EXIT_FAILURE);
  }
  return region_filenames[region_type];
}


x86 assembly (clang, -O0):
<region_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     113f <region_filename+0x1f>
cmpl   $0x9,-0x4(%rbp)
jl     1165 <region_filename+0x45>
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xf9e(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
movslq -0x4(%rbp),%rcx
lea    0x2ed0(%rip),%rax
mov    (%rax,%rcx,8),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<region_filename>:
push   %rax
mov    %edi,%edx
cmp    $0x9,%edi
jae    113a <region_filename+0x1a>
mov    %edx,%eax
lea    0xecf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
pop    %rcx
ret
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
lea    0xfca(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@region_filename.region_filenames = internal global [9 x i8*] [i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([27 x i8], [27 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 ([21 x i8], [21 x i8]* @.str.8, i32 0, i32 0)]
@.str = [34 x i8] c"flashregion_0_flashdescriptor.bin\00"
@.str.1 = [23 x i8] c"flashregion_1_bios.bin\00"
@.str.2 = [27 x i8] c"flashregion_2_intel_me.bin\00"
@.str.3 = [22 x i8] c"flashregion_3_gbe.bin\00"
@.str.4 = [32 x i8] c"flashregion_4_platform_data.bin\00"
@.str.5 = [27 x i8] c"flashregion_5_reserved.bin\00"
@.str.6 = [27 x i8] c"flashregion_6_reserved.bin\00"
@.str.7 = [27 x i8] c"flashregion_7_reserved.bin\00"
@.str.8 = [21 x i8] c"flashregion_8_ec.bin\00"
@stderr = global i32 0
@.str.9 = [25 x i8] c"Invalid region type %d.\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @region_filename(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp sge i32 %6, 9
br i1 %7, label %8, label %14
8: ; preds = %5, %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %5
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [9 x i8*], [9 x i8*]* @region_filename.region_filenames, i64 0, i64 %16
%18 = load i8*, i8** %17
ret i8* %18
}

LLVM IR (-O2):
@reltable.region_filename = internal unnamed_addr constant [9 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([34 x i8]* @.str to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.2 to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.3 to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.4 to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.5 to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.6 to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.7 to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.8 to i64), i64 ptrtoint ([9 x i32]* @reltable.region_filename to i64)) to i32)]
@.str = [34 x i8] c"flashregion_0_flashdescriptor.bin\00"
@.str.1 = [23 x i8] c"flashregion_1_bios.bin\00"
@.str.2 = [27 x i8] c"flashregion_2_intel_me.bin\00"
@.str.3 = [22 x i8] c"flashregion_3_gbe.bin\00"
@.str.4 = [32 x i8] c"flashregion_4_platform_data.bin\00"
@.str.5 = [27 x i8] c"flashregion_5_reserved.bin\00"
@.str.6 = [27 x i8] c"flashregion_6_reserved.bin\00"
@.str.7 = [27 x i8] c"flashregion_7_reserved.bin\00"
@.str.8 = [21 x i8] c"flashregion_8_ec.bin\00"
@stderr = global i32 0
@.str.9 = [25 x i8] c"Invalid region type %d.\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @region_filename(i32 %0) {
%2 = icmp ugt i32 %0, 8
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %0)
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = zext i32 %0 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([9 x i32]* @reltable.region_filename to i8*), i64 %10)
ret i8* %11
}