#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int const);
int /*<<< orphan*/ stderr;
const char *planet(const int i) {
  static const char *names[] = {"Mercury", "Venus",  "Earth",  "Mars",
                                "Jupiter", "Saturn", "Uranus", "Neptune"};
  if (i < 0 || i > 7) {
    fprintf(stderr, "Bad index: %d\n", i);
    exit(1);
  }
  return names[i];
}


x86 assembly (clang, -O0):
<planet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     113f <planet+0x1f>
cmpl   $0x7,-0x4(%rbp)
jle    1161 <planet+0x41>
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xee5(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movslq -0x4(%rbp),%rcx
lea    0x2ed4(%rip),%rax
mov    (%rax,%rcx,8),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<planet>:
push   %rax
mov    %edi,%edx
cmp    $0x8,%edi
jae    113a <planet+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    0xf0d(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@planet.names = internal global [8 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i32 0, i32 0)]
@.str = [8 x i8] c"Mercury\00"
@.str.1 = [6 x i8] c"Venus\00"
@.str.2 = [6 x i8] c"Earth\00"
@.str.3 = [5 x i8] c"Mars\00"
@.str.4 = [8 x i8] c"Jupiter\00"
@.str.5 = [7 x i8] c"Saturn\00"
@.str.6 = [7 x i8] c"Uranus\00"
@.str.7 = [8 x i8] c"Neptune\00"
@stderr = global i32 0
@.str.8 = [15 x i8] c"Bad index: %d\0A\00"
define i8* @planet(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, 7
br i1 %7, label %8, label %13
8: ; preds = %5, %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %5
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [8 x i8*], [8 x i8*]* @planet.names, i64 0, i64 %15
%17 = load i8*, i8** %16
ret i8* %17
}

LLVM IR (-O2):
@reltable.planet = internal unnamed_addr constant [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.planet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.planet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.planet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.planet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.planet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.planet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.planet to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.planet to i64)) to i32)]
@.str = [8 x i8] c"Mercury\00"
@.str.1 = [6 x i8] c"Venus\00"
@.str.2 = [6 x i8] c"Earth\00"
@.str.3 = [5 x i8] c"Mars\00"
@.str.4 = [8 x i8] c"Jupiter\00"
@.str.5 = [7 x i8] c"Saturn\00"
@.str.6 = [7 x i8] c"Uranus\00"
@.str.7 = [8 x i8] c"Neptune\00"
@stderr = global i32 0
@.str.8 = [15 x i8] c"Bad index: %d\0A\00"
define i8* @planet(i32 %0) {
%2 = icmp ugt i32 %0, 7
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %0)
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = zext i32 %0 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.planet to i8*), i64 %9)
ret i8* %10
}