unsigned long PFN_TO_NID(unsigned long pfn) {
  unsigned long block = (pfn >> 12);
  switch (block) {
  case 0x0:
    return 0;
  case 0x1:
    return 1;
  case 0x2:
    return 2;
  case 0x3:
    return 3;
  case 0x4:
    return 4;
  case 0x5:
    return 5;
  case 0x6:
    return 6;
  case 0x7:
    return 7;
  case 0xc0:
    return 8;
  case 0xc1:
    return 9;
  case 0xc2:
    return 10;
  case 0xc3:
    return 11;
  case 0xc4:
    return 12;
  case 0xc5:
    return 13;
  case 0xc6:
    return 14;
  case 0xc7:
    return 15;
  case 0xd0:
    return 16;
  case 0xd1:
    return 17;
  case 0xd2:
    return 18;
  case 0xd3:
    return 19;
  case 0xd4:
    return 20;
  case 0xd5:
    return 21;
  case 0xd6:
    return 22;
  case 0xd7:
    return 23;
  case 0xe0:
    return 24;
  case 0xe1:
    return 25;
  case 0xe2:
    return 26;
  case 0xe3:
    return 27;
  case 0xe4:
    return 28;
  case 0xe5:
    return 29;
  case 0xe6:
    return 30;
  case 0xe7:
    return 31;
  default:
    return 0xff;
  }
}


x86 assembly (clang, -O0):
<PFN_TO_NID>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0xc,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
sub    $0xe7,%rax
ja     12dc <PFN_TO_NID+0x1dc>
mov    -0x20(%rbp),%rax
lea    0xecd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x0,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x1,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x2,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x3,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x4,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x5,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x6,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x7,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x8,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x9,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0xa,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0xb,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0xc,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0xd,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0xe,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0xf,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x10,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x11,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x12,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x13,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x14,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x15,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x16,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x17,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x18,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x19,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x1a,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x1b,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x1c,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x1d,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x1e,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0x1f,-0x8(%rbp)
jmp    12e4 <PFN_TO_NID+0x1e4>
movq   $0xff,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<PFN_TO_NID>:
mov    %rdi,%rax
shr    $0xc,%rax
cmp    $0xe7,%rax
ja     1120 <PFN_TO_NID+0x20>
lea    0xeea(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
ret
mov    $0xff,%eax
ret
mov    $0x8,%eax
ret
mov    $0x9,%eax
ret
mov    $0xa,%eax
ret
mov    $0xb,%eax
ret
mov    $0xc,%eax
ret
mov    $0xd,%eax
ret
mov    $0xe,%eax
ret
mov    $0xf,%eax
ret
mov    $0x10,%eax
ret
mov    $0x11,%eax
ret
mov    $0x12,%eax
ret
mov    $0x13,%eax
ret
mov    $0x14,%eax
ret
mov    $0x15,%eax
ret
mov    $0x16,%eax
ret
mov    $0x17,%eax
ret
mov    $0x18,%eax
ret
mov    $0x19,%eax
ret
mov    $0x1a,%eax
ret
mov    $0x1b,%eax
ret
mov    $0x1c,%eax
ret
mov    $0x1d,%eax
ret
mov    $0x1e,%eax
ret
mov    $0x1f,%eax
ret

LLVM IR (-O0):
define i64 @PFN_TO_NID(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = lshr i64 %5, 12
store i64 %6, i64* %4
%7 = load i64, i64* %4
switch i64 %7, label %40 [
i64 0, label %8
i64 1, label %9
i64 2, label %10
i64 3, label %11
i64 4, label %12
i64 5, label %13
i64 6, label %14
i64 7, label %15
i64 192, label %16
i64 193, label %17
i64 194, label %18
i64 195, label %19
i64 196, label %20
i64 197, label %21
i64 198, label %22
i64 199, label %23
i64 208, label %24
i64 209, label %25
i64 210, label %26
i64 211, label %27
i64 212, label %28
i64 213, label %29
i64 214, label %30
i64 215, label %31
i64 224, label %32
i64 225, label %33
i64 226, label %34
i64 227, label %35
i64 228, label %36
i64 229, label %37
i64 230, label %38
i64 231, label %39
]
8: ; preds = %1
store i64 0, i64* %2
br label %41
9: ; preds = %1
store i64 1, i64* %2
br label %41
10: ; preds = %1
store i64 2, i64* %2
br label %41
11: ; preds = %1
store i64 3, i64* %2
br label %41
12: ; preds = %1
store i64 4, i64* %2
br label %41
13: ; preds = %1
store i64 5, i64* %2
br label %41
14: ; preds = %1
store i64 6, i64* %2
br label %41
15: ; preds = %1
store i64 7, i64* %2
br label %41
16: ; preds = %1
store i64 8, i64* %2
br label %41
17: ; preds = %1
store i64 9, i64* %2
br label %41
18: ; preds = %1
store i64 10, i64* %2
br label %41
19: ; preds = %1
store i64 11, i64* %2
br label %41
20: ; preds = %1
store i64 12, i64* %2
br label %41
21: ; preds = %1
store i64 13, i64* %2
br label %41
22: ; preds = %1
store i64 14, i64* %2
br label %41
23: ; preds = %1
store i64 15, i64* %2
br label %41
24: ; preds = %1
store i64 16, i64* %2
br label %41
25: ; preds = %1
store i64 17, i64* %2
br label %41
26: ; preds = %1
store i64 18, i64* %2
br label %41
27: ; preds = %1
store i64 19, i64* %2
br label %41
28: ; preds = %1
store i64 20, i64* %2
br label %41
29: ; preds = %1
store i64 21, i64* %2
br label %41
30: ; preds = %1
store i64 22, i64* %2
br label %41
31: ; preds = %1
store i64 23, i64* %2
br label %41
32: ; preds = %1
store i64 24, i64* %2
br label %41
33: ; preds = %1
store i64 25, i64* %2
br label %41
34: ; preds = %1
store i64 26, i64* %2
br label %41
35: ; preds = %1
store i64 27, i64* %2
br label %41
36: ; preds = %1
store i64 28, i64* %2
br label %41
37: ; preds = %1
store i64 29, i64* %2
br label %41
38: ; preds = %1
store i64 30, i64* %2
br label %41
39: ; preds = %1
store i64 31, i64* %2
br label %41
40: ; preds = %1
store i64 255, i64* %2
br label %41
41: ; preds = %40, %39, %38, %37, %36, %35, %34, %33, %32, %31, %30, %29, %28, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8
%42 = load i64, i64* %2
ret i64 %42
}

LLVM IR (-O2):
define i64 @PFN_TO_NID(i64 %0) {
%2 = lshr i64 %0, 12
switch i64 %2, label %27 [
i64 0, label %28
i64 1, label %28
i64 2, label %28
i64 3, label %28
i64 4, label %28
i64 5, label %28
i64 6, label %28
i64 7, label %28
i64 192, label %3
i64 193, label %4
i64 194, label %5
i64 195, label %6
i64 196, label %7
i64 197, label %8
i64 198, label %9
i64 199, label %10
i64 208, label %11
i64 209, label %12
i64 210, label %13
i64 211, label %14
i64 212, label %15
i64 213, label %16
i64 214, label %17
i64 215, label %18
i64 224, label %19
i64 225, label %20
i64 226, label %21
i64 227, label %22
i64 228, label %23
i64 229, label %24
i64 230, label %25
i64 231, label %26
]
3: ; preds = %1
br label %28
4: ; preds = %1
br label %28
5: ; preds = %1
br label %28
6: ; preds = %1
br label %28
7: ; preds = %1
br label %28
8: ; preds = %1
br label %28
9: ; preds = %1
br label %28
10: ; preds = %1
br label %28
11: ; preds = %1
br label %28
12: ; preds = %1
br label %28
13: ; preds = %1
br label %28
14: ; preds = %1
br label %28
15: ; preds = %1
br label %28
16: ; preds = %1
br label %28
17: ; preds = %1
br label %28
18: ; preds = %1
br label %28
19: ; preds = %1
br label %28
20: ; preds = %1
br label %28
21: ; preds = %1
br label %28
22: ; preds = %1
br label %28
23: ; preds = %1
br label %28
24: ; preds = %1
br label %28
25: ; preds = %1
br label %28
26: ; preds = %1
br label %28
27: ; preds = %1
br label %28
28: ; preds = %1, %1, %1, %1, %1, %1, %1, %1, %27, %26, %25, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5, %4, %3
%29 = phi i64 [ 255, %27 ], [ 31, %26 ], [ 30, %25 ], [ 29, %24 ], [ 28, %23 ], [ 27, %22 ], [ 26, %21 ], [ 25, %20 ], [ 24, %19 ], [ 23, %18 ], [ 22, %17 ], [ 21, %16 ], [ 20, %15 ], [ 19, %14 ], [ 18, %13 ], [ 17, %12 ], [ 16, %11 ], [ 15, %10 ], [ 14, %9 ], [ 13, %8 ], [ 12, %7 ], [ 11, %6 ], [ 10, %5 ], [ 9, %4 ], [ 8, %3 ], [ %2, %1 ], [ %2, %1 ], [ %2, %1 ], [ %2, %1 ], [ %2, %1 ], [ %2, %1 ], [ %2, %1 ], [ %2, %1 ]
ret i64 %29
}