#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*/ BUG();
int pers_to_level(int pers) {
  switch (pers) {
  case 7UL:
    return (-4);
  case 6UL:
    return -3;
  case 5UL:
    return -2;
  case 1UL:
    return (-1);
  case 2UL:
    return 0;
  case 3UL:
    return 1;
  case 4UL:
    return 5;
  case 8UL:
    return 6;
  }
  BUG();
  return 0UL;
}


x86 assembly (clang, -O0):
<pers_to_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x7,%eax
ja     11a4 <pers_to_level+0x94>
mov    -0x10(%rbp),%rax
lea    0xec5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xfffffffc,-0x4(%rbp)
jmp    11b2 <pers_to_level+0xa2>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11b2 <pers_to_level+0xa2>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b2 <pers_to_level+0xa2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <pers_to_level+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    11b2 <pers_to_level+0xa2>
movl   $0x1,-0x4(%rbp)
jmp    11b2 <pers_to_level+0xa2>
movl   $0x5,-0x4(%rbp)
jmp    11b2 <pers_to_level+0xa2>
movl   $0x6,-0x4(%rbp)
jmp    11b2 <pers_to_level+0xa2>
mov    $0x0,%al
call   1030 <BUG@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pers_to_level>:
push   %rbx
add    $0xffffffff,%edi
cmp    $0x8,%edi
jae    1128 <pers_to_level+0x18>
movslq %edi,%rax
lea    0xedd(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
jmp    1131 <pers_to_level+0x21>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <BUG@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @pers_to_level(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %13 [
i32 7, label %5
i32 6, label %6
i32 5, label %7
i32 1, label %8
i32 2, label %9
i32 3, label %10
i32 4, label %11
i32 8, label %12
]
5: ; preds = %1
store i32 -4, i32* %2
br label %15
6: ; preds = %1
store i32 -3, i32* %2
br label %15
7: ; preds = %1
store i32 -2, i32* %2
br label %15
8: ; preds = %1
store i32 -1, i32* %2
br label %15
9: ; preds = %1
store i32 0, i32* %2
br label %15
10: ; preds = %1
store i32 1, i32* %2
br label %15
11: ; preds = %1
store i32 5, i32* %2
br label %15
12: ; preds = %1
store i32 6, i32* %2
br label %15
13: ; preds = %1
%14 = call i32 (...) @BUG()
store i32 0, i32* %2
br label %15
15: ; preds = %13, %12, %11, %10, %9, %8, %7, %6, %5
%16 = load i32, i32* %2
ret i32 %16
}

LLVM IR (-O2):
@switch.table.pers_to_level = [8 x i32] [i32 -1, i32 0, i32 1, i32 5, i32 -2, i32 -3, i32 -4, i32 6]
define i32 @pers_to_level(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 8
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 (...) @BUG()
br label %10
6: ; preds = %1
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds [8 x i32], [8 x i32]* @switch.table.pers_to_level, i64 0, i64 %7
%9 = load i32, i32* %8
br label %10
10: ; preds = %6, %4
%11 = phi i32 [ 0, %4 ], [ %9, %6 ]
ret i32 %11
}