#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 *randbard0lvl();
char *randcleric0lvl();
char *randdruid0lvl();
char *randsorcerer0lvl();
char *randwarlock0lvl();
char *randwizard0lvl();
char *rand0lvl(void) {
  int d6;
  d6 = d(6);
  switch (d6) {
  case 1:
    return randbard0lvl();
  case 2:
    return randcleric0lvl();
  case 3:
    return randdruid0lvl();
  case 4:
    return randsorcerer0lvl();
  case 5:
    return randwarlock0lvl();
  case 6:
    return randwizard0lvl();
  default:
    printf("Impossible random level 0 spell %d\n", d6);
    exit(EXIT_FAILURE);
  }
  return "";
}


x86 assembly (clang, -O0):
<rand0lvl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x6,%edi
call   1030 <d@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     122e <rand0lvl+0x9e>
mov    -0x18(%rbp),%rax
lea    0xe3b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1070 <randbard0lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    124b <rand0lvl+0xbb>
mov    $0x0,%al
call   1050 <randcleric0lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    124b <rand0lvl+0xbb>
mov    $0x0,%al
call   10b0 <randdruid0lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    124b <rand0lvl+0xbb>
mov    $0x0,%al
call   1080 <randsorcerer0lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    124b <rand0lvl+0xbb>
mov    $0x0,%al
call   1040 <randwarlock0lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    124b <rand0lvl+0xbb>
mov    $0x0,%al
call   10a0 <randwizard0lvl@plt>
mov    %rax,-0x8(%rbp)
jmp    124b <rand0lvl+0xbb>
mov    -0xc(%rbp),%esi
lea    0xde0(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand0lvl>:
push   %rax
mov    $0x6,%edi
call   1030 <d@plt>
lea    -0x1(%rax),%ecx
cmp    $0x5,%ecx
ja     11e3 <rand0lvl+0x53>
lea    0xe56(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %eax,%eax
pop    %rcx
jmp    1070 <randbard0lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    1050 <randcleric0lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    10b0 <randdruid0lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    1080 <randsorcerer0lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    1040 <randwarlock0lvl@plt>
xor    %eax,%eax
pop    %rcx
jmp    10a0 <randwizard0lvl@plt>
lea    0xe2e(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Impossible random level 0 spell %d\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @rand0lvl() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i32 @d(i32 6)
store i32 %3, i32* %2
%4 = load i32, i32* %2
switch i32 %4, label %17 [
i32 1, label %5
i32 2, label %7
i32 3, label %9
i32 4, label %11
i32 5, label %13
i32 6, label %15
]
5: ; preds = %0
%6 = call i8* (...) @randbard0lvl()
store i8* %6, i8** %1
br label %22
7: ; preds = %0
%8 = call i8* (...) @randcleric0lvl()
store i8* %8, i8** %1
br label %22
9: ; preds = %0
%10 = call i8* (...) @randdruid0lvl()
store i8* %10, i8** %1
br label %22
11: ; preds = %0
%12 = call i8* (...) @randsorcerer0lvl()
store i8* %12, i8** %1
br label %22
13: ; preds = %0
%14 = call i8* (...) @randwarlock0lvl()
store i8* %14, i8** %1
br label %22
15: ; preds = %0
%16 = call i8* (...) @randwizard0lvl()
store i8* %16, i8** %1
br label %22
17: ; preds = %0
%18 = load i32, i32* %2
%19 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %15, %13, %11, %9, %7, %5
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
@.str = [36 x i8] c"Impossible random level 0 spell %d\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @rand0lvl() {
%1 = tail call i32 @d(i32 6)
switch i32 %1, label %14 [
i32 1, label %2
i32 2, label %4
i32 3, label %6
i32 4, label %8
i32 5, label %10
i32 6, label %12
]
2: ; preds = %0
%3 = tail call i8* (...) @randbard0lvl()
br label %18
4: ; preds = %0
%5 = tail call i8* (...) @randcleric0lvl()
br label %18
6: ; preds = %0
%7 = tail call i8* (...) @randdruid0lvl()
br label %18
8: ; preds = %0
%9 = tail call i8* (...) @randsorcerer0lvl()
br label %18
10: ; preds = %0
%11 = tail call i8* (...) @randwarlock0lvl()
br label %18
12: ; preds = %0
%13 = tail call i8* (...) @randwizard0lvl()
br label %18
14: ; preds = %0
%15 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %1)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %12, %10, %8, %6, %4, %2
%19 = phi i8* [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ], [ %3, %2 ]
ret i8* %19
}