#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 d(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
char *randbard2lvl();
char *randcleric2lvl();
char *randdruid2lvl();
char *randpaladin2lvl();
char *randranger2lvl();
char *randsorcerer2lvl();
char *randwarlock2lvl();
char *randwizard2lvl();
char *rand2lvl(void) {
  int d8;
  d8 = d(8);
  switch (d8) {
  case 1:
    return randbard2lvl();
  case 2:
    return randcleric2lvl();
  case 3:
    return randdruid2lvl();
  case 4:
    return randpaladin2lvl();
  case 5:
    return randranger2lvl();
  case 6:
    return randsorcerer2lvl();
  case 7:
    return randwarlock2lvl();
  case 8:
    return randwizard2lvl();
  default:
    printf("Impossible random level 2 spell %d\n", d8);
    exit(EXIT_FAILURE);
  }
  return "";
}


x86 assembly (clang, -O0):
<rand2lvl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x8,%edi
call   1030 <d@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x7,%eax
ja     126e <rand2lvl+0xbe>
mov    -0x18(%rbp),%rax
lea    0xe1b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   10d0 <randbard2lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    128b <rand2lvl+0xdb>
mov    $0x0,%al
call   1070 <randcleric2lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    128b <rand2lvl+0xdb>
mov    $0x0,%al
call   10b0 <randdruid2lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    128b <rand2lvl+0xdb>
mov    $0x0,%al
call   1050 <randpaladin2lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    128b <rand2lvl+0xdb>
mov    $0x0,%al
call   1080 <randranger2lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    128b <rand2lvl+0xdb>
mov    $0x0,%al
call   1060 <randsorcerer2lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    128b <rand2lvl+0xdb>
mov    $0x0,%al
call   1090 <randwarlock2lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    128b <rand2lvl+0xdb>
mov    $0x0,%al
call   10a0 <randwizard2lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    128b <rand2lvl+0xdb>
mov    -0xc(%rbp),%esi
lea    0xda8(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand2lvl>:
push   %rax
mov    $0x8,%edi
call   1030 <d@plt>
lea    -0x1(%rax),%ecx
cmp    $0x7,%ecx
ja     1213 <rand2lvl+0x63>
lea    0xe36(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %eax,%eax
pop    %rcx
jmp    10d0 <randbard2lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    10b0 <randdruid2lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    1050 <randpaladin2lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    1080 <randranger2lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    1070 <randcleric2lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    1060 <randsorcerer2lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    1090 <randwarlock2lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    10a0 <randwizard2lvl@plt>
lea    0xe06(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Impossible random level 2 spell %d\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @rand2lvl() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i32 @d(i32 8)
store i32 %3, i32* %2
%4 = load i32, i32* %2
switch i32 %4, label %21 [
i32 1, label %5
i32 2, label %7
i32 3, label %9
i32 4, label %11
i32 5, label %13
i32 6, label %15
i32 7, label %17
i32 8, label %19
]
5: ; preds = %0
%6 = call i8* (...) @randbard2lvl()
store i8* %6, i8** %1
br label %26
7: ; preds = %0
%8 = call i8* (...) @randcleric2lvl()
store i8* %8, i8** %1
br label %26
9: ; preds = %0
%10 = call i8* (...) @randdruid2lvl()
store i8* %10, i8** %1
br label %26
11: ; preds = %0
%12 = call i8* (...) @randpaladin2lvl()
store i8* %12, i8** %1
br label %26
13: ; preds = %0
%14 = call i8* (...) @randranger2lvl()
store i8* %14, i8** %1
br label %26
15: ; preds = %0
%16 = call i8* (...) @randsorcerer2lvl()
store i8* %16, i8** %1
br label %26
17: ; preds = %0
%18 = call i8* (...) @randwarlock2lvl()
store i8* %18, i8** %1
br label %26
19: ; preds = %0
%20 = call i8* (...) @randwizard2lvl()
store i8* %20, i8** %1
br label %26
21: ; preds = %0
%22 = load i32, i32* %2
%23 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %19, %17, %15, %13, %11, %9, %7, %5
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
@.str = [36 x i8] c"Impossible random level 2 spell %d\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @rand2lvl() {
%1 = tail call i32 @d(i32 8)
switch i32 %1, label %18 [
i32 1, label %2
i32 2, label %4
i32 3, label %6
i32 4, label %8
i32 5, label %10
i32 6, label %12
i32 7, label %14
i32 8, label %16
]
2: ; preds = %0
%3 = tail call i8* (...) @randbard2lvl()
br label %22
4: ; preds = %0
%5 = tail call i8* (...) @randcleric2lvl()
br label %22
6: ; preds = %0
%7 = tail call i8* (...) @randdruid2lvl()
br label %22
8: ; preds = %0
%9 = tail call i8* (...) @randpaladin2lvl()
br label %22
10: ; preds = %0
%11 = tail call i8* (...) @randranger2lvl()
br label %22
12: ; preds = %0
%13 = tail call i8* (...) @randsorcerer2lvl()
br label %22
14: ; preds = %0
%15 = tail call i8* (...) @randwarlock2lvl()
br label %22
16: ; preds = %0
%17 = tail call i8* (...) @randwizard2lvl()
br label %22
18: ; preds = %0
%19 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %1)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %16, %14, %12, %10, %8, %6, %4, %2
%23 = phi i8* [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ], [ %3, %2 ]
ret i8* %23
}