int toHex(int num) {
  switch (num) {
  case 0:
    return 0b0111111;
    break;
  case 1:
    return 0b0000110;
    break;
  case 2:
    return 0b1011011;
    break;
  case 3:
    return 0b1001111;
    break;
  case 4:
    return 0b1100110;
    break;
  case 5:
    return 0b1101101;
    break;
  case 6:
    return 0b1111101;
    break;
  case 7:
    return 0b0000111;
    break;
  case 8:
    return 0b1111111;
    break;
  case 9:
    return 0b1101111;
    break;
  case 10:
    return 0b1110111;
    break;
  case 11:
    return 0b1111100;
    break;
  case 12:
    return 0b0111001;
    break;
  case 13:
    return 0b1011110;
    break;
  case 14:
    return 0b1111001;
    break;
  case 15:
    return 0b1110001;
    break;
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<toHex>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0xf,%rax
ja     11ec <toHex+0xec>
mov    -0x10(%rbp),%rax
lea    0xedd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x3f,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x6,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x5b,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x4f,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x66,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x6d,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x7d,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x7,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x7f,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x6f,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x77,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x7c,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x39,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x5e,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x79,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x71,-0x4(%rbp)
jmp    11f3 <toHex+0xf3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<toHex>:
xor    %eax,%eax
cmp    $0xf,%edi
ja     1114 <toHex+0x14>
movslq %edi,%rax
lea    0xeef(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
define i32 @toHex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %21 [
i32 0, label %5
i32 1, label %6
i32 2, label %7
i32 3, label %8
i32 4, label %9
i32 5, label %10
i32 6, label %11
i32 7, label %12
i32 8, label %13
i32 9, label %14
i32 10, label %15
i32 11, label %16
i32 12, label %17
i32 13, label %18
i32 14, label %19
i32 15, label %20
]
5: ; preds = %1
store i32 63, i32* %2
br label %22
6: ; preds = %1
store i32 6, i32* %2
br label %22
7: ; preds = %1
store i32 91, i32* %2
br label %22
8: ; preds = %1
store i32 79, i32* %2
br label %22
9: ; preds = %1
store i32 102, i32* %2
br label %22
10: ; preds = %1
store i32 109, i32* %2
br label %22
11: ; preds = %1
store i32 125, i32* %2
br label %22
12: ; preds = %1
store i32 7, i32* %2
br label %22
13: ; preds = %1
store i32 127, i32* %2
br label %22
14: ; preds = %1
store i32 111, i32* %2
br label %22
15: ; preds = %1
store i32 119, i32* %2
br label %22
16: ; preds = %1
store i32 124, i32* %2
br label %22
17: ; preds = %1
store i32 57, i32* %2
br label %22
18: ; preds = %1
store i32 94, i32* %2
br label %22
19: ; preds = %1
store i32 121, i32* %2
br label %22
20: ; preds = %1
store i32 113, i32* %2
br label %22
21: ; preds = %1
store i32 0, i32* %2
br label %22
22: ; preds = %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@switch.table.toHex = [16 x i32] [i32 63, i32 6, i32 91, i32 79, i32 102, i32 109, i32 125, i32 7, i32 127, i32 111, i32 119, i32 124, i32 57, i32 94, i32 121, i32 113]
define i32 @toHex(i32 %0) {
%2 = icmp ult i32 %0, 16
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = sext i32 %0 to i64
%5 = getelementptr inbounds [16 x i32], [16 x i32]* @switch.table.toHex, i64 0, i64 %4
%6 = load i32, i32* %5
br label %7
7: ; preds = %1, %3
%8 = phi i32 [ %6, %3 ], [ 0, %1 ]
ret i32 %8
}