int getJoystick(unsigned char player) {
  if (player & (1 << 2)) {
    if (player & (1 << 5)) {
      return 8;
    }
    if (player & (1 << 1)) {
      return 2;
    }
    return 1;
  }
  if (player & (1 << 4)) {
    if (player & (1 << 5)) {
      return 6;
    }
    if (player & (1 << 1)) {
      return 4;
    }
    return 5;
  }
  if (player & (1 << 1)) {
    return 3;
  }
  if (player & (1 << 5)) {
    return 7;
  }
  return 0;
}


x86 assembly (clang, -O0):
<getJoystick>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     115e <getJoystick+0x5e>
movzbl -0x5(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1136 <getJoystick+0x36>
movl   $0x8,-0x4(%rbp)
jmp    11f1 <getJoystick+0xf1>
movzbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1152 <getJoystick+0x52>
movl   $0x2,-0x4(%rbp)
jmp    11f1 <getJoystick+0xf1>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <getJoystick+0xf1>
movzbl -0x5(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     11b2 <getJoystick+0xb2>
movzbl -0x5(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     118a <getJoystick+0x8a>
movl   $0x6,-0x4(%rbp)
jmp    11f1 <getJoystick+0xf1>
movzbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11a6 <getJoystick+0xa6>
movl   $0x4,-0x4(%rbp)
jmp    11f1 <getJoystick+0xf1>
movl   $0x5,-0x4(%rbp)
jmp    11f1 <getJoystick+0xf1>
movzbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11ce <getJoystick+0xce>
movl   $0x3,-0x4(%rbp)
jmp    11f1 <getJoystick+0xf1>
movzbl -0x5(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     11ea <getJoystick+0xea>
movl   $0x7,-0x4(%rbp)
jmp    11f1 <getJoystick+0xf1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getJoystick>:
test   $0x4,%dil
jne    1123 <getJoystick+0x23>
test   $0x10,%dil
jne    113d <getJoystick+0x3d>
mov    $0x3,%eax
test   $0x2,%dil
jne    1122 <getJoystick+0x22>
shl    $0x1a,%edi
sar    $0x1f,%edi
and    $0x7,%edi
mov    %edi,%eax
ret
mov    $0x8,%eax
test   $0x20,%dil
jne    1122 <getJoystick+0x22>
and    $0x2,%edi
cmp    $0x1,%edi
mov    $0x2,%eax
sbb    $0x0,%eax
ret
mov    $0x6,%eax
test   $0x20,%dil
jne    1122 <getJoystick+0x22>
xor    %eax,%eax
test   $0x2,%dil
sete   %al
or     $0x4,%eax
ret

LLVM IR (-O0):
define i32 @getJoystick(i8 zeroext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = zext i8 %4 to i32
%6 = and i32 %5, 4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %1
%9 = load i8, i8* %3
%10 = zext i8 %9 to i32
%11 = and i32 %10, 32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 8, i32* %2
br label %52
14: ; preds = %8
%15 = load i8, i8* %3
%16 = zext i8 %15 to i32
%17 = and i32 %16, 2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 2, i32* %2
br label %52
20: ; preds = %14
store i32 1, i32* %2
br label %52
21: ; preds = %1
%22 = load i8, i8* %3
%23 = zext i8 %22 to i32
%24 = and i32 %23, 16
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %21
%27 = load i8, i8* %3
%28 = zext i8 %27 to i32
%29 = and i32 %28, 32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 6, i32* %2
br label %52
32: ; preds = %26
%33 = load i8, i8* %3
%34 = zext i8 %33 to i32
%35 = and i32 %34, 2
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 4, i32* %2
br label %52
38: ; preds = %32
store i32 5, i32* %2
br label %52
39: ; preds = %21
%40 = load i8, i8* %3
%41 = zext i8 %40 to i32
%42 = and i32 %41, 2
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
store i32 3, i32* %2
br label %52
45: ; preds = %39
%46 = load i8, i8* %3
%47 = zext i8 %46 to i32
%48 = and i32 %47, 32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 7, i32* %2
br label %52
51: ; preds = %45
store i32 0, i32* %2
br label %52
52: ; preds = %51, %50, %44, %38, %37, %31, %20, %19, %13
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
define i32 @getJoystick(i8 zeroext %0) {
%2 = zext i8 %0 to i32
%3 = and i32 %2, 4
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = and i32 %2, 32
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = and i32 %2, 2
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 1, i32 2
br label %29
12: ; preds = %1
%13 = and i32 %2, 16
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = and i32 %2, 32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = and i32 %2, 2
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 5, i32 4
br label %29
22: ; preds = %12
%23 = and i32 %2, 2
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = and i32 %2, 32
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i32 0, i32 7
br label %29
29: ; preds = %25, %22, %18, %15, %8, %5
%30 = phi i32 [ 8, %5 ], [ %11, %8 ], [ 6, %15 ], [ %21, %18 ], [ 3, %22 ], [ %28, %25 ]
ret i32 %30
}