#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 /*<<< orphan*/ stderr;
const char *region_filename(int region_type) {
  static const char *region_filenames[5] = {
      "flashregion_0_flashdescriptor.bin", "flashregion_1_bios.bin",
      "flashregion_2_intel_me.bin", "flashregion_3_gbe.bin",
      "flashregion_4_platform_data.bin"};
  if (region_type < 0 || region_type > 4) {
    fprintf(stderr, "Invalid region type.\n");
    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   $0x4,-0x4(%rbp)
jle    1162 <region_filename+0x42>
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0xf3b(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
movslq -0x4(%rbp),%rcx
lea    0x2ed3(%rip),%rax
mov    (%rax,%rcx,8),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<region_filename>:
push   %rax
cmp    $0x5,%edi
jae    1138 <region_filename+0x18>
mov    %edi,%eax
lea    0xed1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
pop    %rcx
ret
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xf56(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@region_filename.region_filenames = internal global [5 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)]
@.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"
@stderr = global i32 0
@.str.5 = [22 x i8] c"Invalid region type.\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 sgt i32 %6, 4
br i1 %7, label %8, label %13
8: ; preds = %5, %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %5
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* @region_filename.region_filenames, i64 0, i64 %15
%17 = load i8*, i8** %16
ret i8* %17
}

LLVM IR (-O2):
@reltable.region_filename = internal unnamed_addr constant [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([34 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.region_filename to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.4 to i64), i64 ptrtoint ([5 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"
@stderr = global i32 0
@.str.5 = [22 x i8] c"Invalid region type.\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @region_filename(i32 %0) {
%2 = icmp ugt i32 %0, 4
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 ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 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 ([5 x i32]* @reltable.region_filename to i8*), i64 %10)
ret i8* %11
}