#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 rand();
char *BotRandomWeaponName(void) {
  int rnd;
  rnd = ((rand() & 0x7fff) / ((float)0x7fff)) * 8.9;
  switch (rnd) {
  case 0:
    return "Phaser";
  case 1:
    return "Compression Rifle";
  case 2:
    return "Infinity Modulator";
  case 3:
    return "Scavenger Rifle";
  case 4:
    return "Stasis Weapon";
  case 5:
    return "Grenade Launcher";
  case 6:
    return "Tetryon Disruptor";
  case 7:
    return "Dermal Regenerator";
  default:
    return "Photon Burst Cannon";
  }
}


x86 assembly (clang, -O0):
<BotRandomWeaponName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
call   1030 <rand@plt>
and    $0x7fff,%eax
cvtsi2ss %eax,%xmm0
movss  0xed0(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xec8(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x7,%rax
ja     11f0 <BotRandomWeaponName+0xe0>
mov    -0x18(%rbp),%rax
lea    0xea9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeb9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <BotRandomWeaponName+0xeb>
lea    0xeb0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <BotRandomWeaponName+0xeb>
lea    0xeb2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <BotRandomWeaponName+0xeb>
lea    0xeb5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <BotRandomWeaponName+0xeb>
lea    0xeb5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <BotRandomWeaponName+0xeb>
lea    0xeb3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <BotRandomWeaponName+0xeb>
lea    0xeb4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <BotRandomWeaponName+0xeb>
lea    0xeb6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <BotRandomWeaponName+0xeb>
lea    0xeb9(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BotRandomWeaponName>:
push   %rax
xor    %eax,%eax
call   1030 <rand@plt>
and    $0x7fff,%eax
cvtsi2ss %eax,%xmm0
divss  0xed7(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xed3(%rip),%xmm0
cvttsd2si %xmm0,%eax
cmp    $0x7,%eax
ja     1150 <BotRandomWeaponName+0x40>
cltq
lea    0xf5d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
pop    %rcx
ret
lea    0xf39(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Phaser\00"
@.str.1 = [18 x i8] c"Compression Rifle\00"
@.str.2 = [19 x i8] c"Infinity Modulator\00"
@.str.3 = [16 x i8] c"Scavenger Rifle\00"
@.str.4 = [14 x i8] c"Stasis Weapon\00"
@.str.5 = [17 x i8] c"Grenade Launcher\00"
@.str.6 = [18 x i8] c"Tetryon Disruptor\00"
@.str.7 = [19 x i8] c"Dermal Regenerator\00"
@.str.8 = [20 x i8] c"Photon Burst Cannon\00"
define i8* @BotRandomWeaponName() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i32 (...) @rand()
%4 = and i32 %3, 32767
%5 = sitofp i32 %4 to float
%6 = fdiv float %5, 3.276700e+04
%7 = fpext float %6 to double
%8 = fmul double %7, 8.900000e+00
%9 = fptosi double %8 to i32
store i32 %9, i32* %2
%10 = load i32, i32* %2
switch i32 %10, label %19 [
i32 0, label %11
i32 1, label %12
i32 2, label %13
i32 3, label %14
i32 4, label %15
i32 5, label %16
i32 6, label %17
i32 7, label %18
]
11: ; preds = %0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %1
br label %20
12: ; preds = %0
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %20
13: ; preds = %0
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %20
14: ; preds = %0
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %20
15: ; preds = %0
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %1
br label %20
16: ; preds = %0
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %20
17: ; preds = %0
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8** %1
br label %20
18: ; preds = %0
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8** %1
br label %20
19: ; preds = %0
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8** %1
br label %20
20: ; preds = %19, %18, %17, %16, %15, %14, %13, %12, %11
%21 = load i8*, i8** %1
ret i8* %21
}

LLVM IR (-O2):
@.str = [7 x i8] c"Phaser\00"
@.str.1 = [18 x i8] c"Compression Rifle\00"
@.str.2 = [19 x i8] c"Infinity Modulator\00"
@.str.3 = [16 x i8] c"Scavenger Rifle\00"
@.str.4 = [14 x i8] c"Stasis Weapon\00"
@.str.5 = [17 x i8] c"Grenade Launcher\00"
@.str.6 = [18 x i8] c"Tetryon Disruptor\00"
@.str.7 = [19 x i8] c"Dermal Regenerator\00"
@.str.8 = [20 x i8] c"Photon Burst Cannon\00"
@reltable.BotRandomWeaponName = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.BotRandomWeaponName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.BotRandomWeaponName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.BotRandomWeaponName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.BotRandomWeaponName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.BotRandomWeaponName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.BotRandomWeaponName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.BotRandomWeaponName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.BotRandomWeaponName to i64)) to i32)]
define i8* @BotRandomWeaponName() {
%1 = tail call i32 (...) @rand()
%2 = and i32 %1, 32767
%3 = sitofp i32 %2 to float
%4 = fdiv float %3, 3.276700e+04
%5 = fpext float %4 to double
%6 = fmul double %5, 8.900000e+00
%7 = fptosi double %6 to i32
%8 = icmp ult i32 %7, 8
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = sext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.BotRandomWeaponName to i8*), i64 %11)
br label %13
13: ; preds = %0, %9
%14 = phi i8* [ %12, %9 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), %0 ]
ret i8* %14
}