unsigned long reg2xset(int reg_sz, unsigned long reg) {
  if (reg_sz == 1)
    return reg == 0   ? 0x00000001
           : reg == 1 ? 0x00000010
           : reg == 2 ? 0x00000100
           : reg == 3 ? 0x00001000
           : reg == 4 ? 0x00000002
           : reg == 5 ? 0x00000020
           : reg == 6 ? 0x00000200
                      : 0x00002000;
  else if (reg_sz == 2)
    return reg == 0   ? (0x00000003 | 0x00000001 | 0x00000002)
           : reg == 1 ? (0x00000030 | 0x00000010 | 0x00000020)
           : reg == 2 ? (0x00000300 | 0x00000100 | 0x00000200)
           : reg == 3 ? (0x00003000 | 0x00001000 | 0x00002000)
           : reg == 4 ? 0x00010000
           : reg == 5 ? 0x00100000
           : reg == 6 ? 0x01000000
                      : 0x10000000;
  else
    return reg == 0   ? (0x0000000F | 0x00000003 | 0x00000001 | 0x00000002)
           : reg == 1 ? (0x000000F0 | 0x00000030 | 0x00000010 | 0x00000020)
           : reg == 2 ? (0x00000F00 | 0x00000300 | 0x00000100 | 0x00000200)
           : reg == 3 ? (0x0000F000 | 0x00003000 | 0x00001000 | 0x00002000)
           : reg == 4 ? (0x00030000 | 0x00010000)
           : reg == 5 ? (0x00300000 | 0x00100000)
           : reg == 6 ? (0x03000000 | 0x01000000)
                      : (0x30000000 | 0x10000000);
}


x86 assembly (clang, -O0):
<reg2xset>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11e9 <reg2xset+0xe9>
cmpq   $0x0,-0x18(%rbp)
jne    112d <reg2xset+0x2d>
mov    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11db <reg2xset+0xdb>
cmpq   $0x1,-0x18(%rbp)
jne    1145 <reg2xset+0x45>
mov    $0x10,%eax
mov    %eax,-0x20(%rbp)
jmp    11d5 <reg2xset+0xd5>
cmpq   $0x2,-0x18(%rbp)
jne    115d <reg2xset+0x5d>
mov    $0x100,%eax
mov    %eax,-0x24(%rbp)
jmp    11cf <reg2xset+0xcf>
cmpq   $0x3,-0x18(%rbp)
jne    1175 <reg2xset+0x75>
mov    $0x1000,%eax
mov    %eax,-0x28(%rbp)
jmp    11c9 <reg2xset+0xc9>
cmpq   $0x4,-0x18(%rbp)
jne    118d <reg2xset+0x8d>
mov    $0x2,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c3 <reg2xset+0xc3>
cmpq   $0x5,-0x18(%rbp)
jne    11a5 <reg2xset+0xa5>
mov    $0x20,%eax
mov    %eax,-0x30(%rbp)
jmp    11bd <reg2xset+0xbd>
mov    -0x18(%rbp),%rdx
mov    $0x2000,%eax
mov    $0x200,%ecx
cmp    $0x6,%rdx
cmove  %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    1396 <reg2xset+0x296>
cmpl   $0x2,-0xc(%rbp)
jne    12c7 <reg2xset+0x1c7>
cmpq   $0x0,-0x18(%rbp)
jne    120b <reg2xset+0x10b>
mov    $0x3,%eax
mov    %eax,-0x34(%rbp)
jmp    12b9 <reg2xset+0x1b9>
cmpq   $0x1,-0x18(%rbp)
jne    1223 <reg2xset+0x123>
mov    $0x30,%eax
mov    %eax,-0x38(%rbp)
jmp    12b3 <reg2xset+0x1b3>
cmpq   $0x2,-0x18(%rbp)
jne    123b <reg2xset+0x13b>
mov    $0x300,%eax
mov    %eax,-0x3c(%rbp)
jmp    12ad <reg2xset+0x1ad>
cmpq   $0x3,-0x18(%rbp)
jne    1253 <reg2xset+0x153>
mov    $0x3000,%eax
mov    %eax,-0x40(%rbp)
jmp    12a7 <reg2xset+0x1a7>
cmpq   $0x4,-0x18(%rbp)
jne    126b <reg2xset+0x16b>
mov    $0x10000,%eax
mov    %eax,-0x44(%rbp)
jmp    12a1 <reg2xset+0x1a1>
cmpq   $0x5,-0x18(%rbp)
jne    1283 <reg2xset+0x183>
mov    $0x100000,%eax
mov    %eax,-0x48(%rbp)
jmp    129b <reg2xset+0x19b>
mov    -0x18(%rbp),%rdx
mov    $0x10000000,%eax
mov    $0x1000000,%ecx
cmp    $0x6,%rdx
cmove  %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    1396 <reg2xset+0x296>
cmpq   $0x0,-0x18(%rbp)
jne    12df <reg2xset+0x1df>
mov    $0xf,%eax
mov    %eax,-0x4c(%rbp)
jmp    138d <reg2xset+0x28d>
cmpq   $0x1,-0x18(%rbp)
jne    12f7 <reg2xset+0x1f7>
mov    $0xf0,%eax
mov    %eax,-0x50(%rbp)
jmp    1387 <reg2xset+0x287>
cmpq   $0x2,-0x18(%rbp)
jne    130f <reg2xset+0x20f>
mov    $0xf00,%eax
mov    %eax,-0x54(%rbp)
jmp    1381 <reg2xset+0x281>
cmpq   $0x3,-0x18(%rbp)
jne    1327 <reg2xset+0x227>
mov    $0xf000,%eax
mov    %eax,-0x58(%rbp)
jmp    137b <reg2xset+0x27b>
cmpq   $0x4,-0x18(%rbp)
jne    133f <reg2xset+0x23f>
mov    $0x30000,%eax
mov    %eax,-0x5c(%rbp)
jmp    1375 <reg2xset+0x275>
cmpq   $0x5,-0x18(%rbp)
jne    1357 <reg2xset+0x257>
mov    $0x300000,%eax
mov    %eax,-0x60(%rbp)
jmp    136f <reg2xset+0x26f>
mov    -0x18(%rbp),%rdx
mov    $0x30000000,%eax
mov    $0x3000000,%ecx
cmp    $0x6,%rdx
cmove  %ecx,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<reg2xset>:
cmp    $0x2,%edi
je     111c <reg2xset+0x1c>
cmp    $0x1,%edi
jne    112e <reg2xset+0x2e>
cmp    $0x6,%rsi
jae    1140 <reg2xset+0x40>
lea    0xee9(%rip),%rax
mov    (%rax,%rsi,8),%rax
ret
cmp    $0x6,%rsi
jae    114f <reg2xset+0x4f>
lea    0xf07(%rip),%rax
mov    (%rax,%rsi,8),%rax
ret
cmp    $0x6,%rsi
jae    115e <reg2xset+0x5e>
lea    0xf25(%rip),%rax
mov    (%rax,%rsi,8),%rax
ret
mov    $0x200,%ecx
mov    $0x2000,%eax
cmove  %rcx,%rax
ret
mov    $0x1000000,%ecx
mov    $0x10000000,%eax
cmove  %rcx,%rax
ret
mov    $0x3000000,%ecx
mov    $0x30000000,%eax
cmove  %rcx,%rax
ret

LLVM IR (-O0):
define i64 @reg2xset(i32 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %50
8: ; preds = %2
%9 = load i64, i64* %5
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8
br label %47
12: ; preds = %8
%13 = load i64, i64* %5
%14 = icmp eq i64 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12
br label %45
16: ; preds = %12
%17 = load i64, i64* %5
%18 = icmp eq i64 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %16
br label %43
20: ; preds = %16
%21 = load i64, i64* %5
%22 = icmp eq i64 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %20
br label %41
24: ; preds = %20
%25 = load i64, i64* %5
%26 = icmp eq i64 %25, 4
br i1 %26, label %27, label %28
27: ; preds = %24
br label %39
28: ; preds = %24
%29 = load i64, i64* %5
%30 = icmp eq i64 %29, 5
br i1 %30, label %31, label %32
31: ; preds = %28
br label %37
32: ; preds = %28
%33 = load i64, i64* %5
%34 = icmp eq i64 %33, 6
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 512, i32 8192
br label %37
37: ; preds = %32, %31
%38 = phi i32 [ 32, %31 ], [ %36, %32 ]
br label %39
39: ; preds = %37, %27
%40 = phi i32 [ 2, %27 ], [ %38, %37 ]
br label %41
41: ; preds = %39, %23
%42 = phi i32 [ 4096, %23 ], [ %40, %39 ]
br label %43
43: ; preds = %41, %19
%44 = phi i32 [ 256, %19 ], [ %42, %41 ]
br label %45
45: ; preds = %43, %15
%46 = phi i32 [ 16, %15 ], [ %44, %43 ]
br label %47
47: ; preds = %45, %11
%48 = phi i32 [ 1, %11 ], [ %46, %45 ]
%49 = sext i32 %48 to i64
store i64 %49, i64* %3
br label %137
50: ; preds = %2
%51 = load i32, i32* %4
%52 = icmp eq i32 %51, 2
br i1 %52, label %53, label %95
53: ; preds = %50
%54 = load i64, i64* %5
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %53
br label %92
57: ; preds = %53
%58 = load i64, i64* %5
%59 = icmp eq i64 %58, 1
br i1 %59, label %60, label %61
60: ; preds = %57
br label %90
61: ; preds = %57
%62 = load i64, i64* %5
%63 = icmp eq i64 %62, 2
br i1 %63, label %64, label %65
64: ; preds = %61
br label %88
65: ; preds = %61
%66 = load i64, i64* %5
%67 = icmp eq i64 %66, 3
br i1 %67, label %68, label %69
68: ; preds = %65
br label %86
69: ; preds = %65
%70 = load i64, i64* %5
%71 = icmp eq i64 %70, 4
br i1 %71, label %72, label %73
72: ; preds = %69
br label %84
73: ; preds = %69
%74 = load i64, i64* %5
%75 = icmp eq i64 %74, 5
br i1 %75, label %76, label %77
76: ; preds = %73
br label %82
77: ; preds = %73
%78 = load i64, i64* %5
%79 = icmp eq i64 %78, 6
%80 = zext i1 %79 to i64
%81 = select i1 %79, i32 16777216, i32 268435456
br label %82
82: ; preds = %77, %76
%83 = phi i32 [ 1048576, %76 ], [ %81, %77 ]
br label %84
84: ; preds = %82, %72
%85 = phi i32 [ 65536, %72 ], [ %83, %82 ]
br label %86
86: ; preds = %84, %68
%87 = phi i32 [ 12288, %68 ], [ %85, %84 ]
br label %88
88: ; preds = %86, %64
%89 = phi i32 [ 768, %64 ], [ %87, %86 ]
br label %90
90: ; preds = %88, %60
%91 = phi i32 [ 48, %60 ], [ %89, %88 ]
br label %92
92: ; preds = %90, %56
%93 = phi i32 [ 3, %56 ], [ %91, %90 ]
%94 = sext i32 %93 to i64
store i64 %94, i64* %3
br label %137
95: ; preds = %50
%96 = load i64, i64* %5
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %95
br label %134
99: ; preds = %95
%100 = load i64, i64* %5
%101 = icmp eq i64 %100, 1
br i1 %101, label %102, label %103
102: ; preds = %99
br label %132
103: ; preds = %99
%104 = load i64, i64* %5
%105 = icmp eq i64 %104, 2
br i1 %105, label %106, label %107
106: ; preds = %103
br label %130
107: ; preds = %103
%108 = load i64, i64* %5
%109 = icmp eq i64 %108, 3
br i1 %109, label %110, label %111
110: ; preds = %107
br label %128
111: ; preds = %107
%112 = load i64, i64* %5
%113 = icmp eq i64 %112, 4
br i1 %113, label %114, label %115
114: ; preds = %111
br label %126
115: ; preds = %111
%116 = load i64, i64* %5
%117 = icmp eq i64 %116, 5
br i1 %117, label %118, label %119
118: ; preds = %115
br label %124
119: ; preds = %115
%120 = load i64, i64* %5
%121 = icmp eq i64 %120, 6
%122 = zext i1 %121 to i64
%123 = select i1 %121, i32 50331648, i32 805306368
br label %124
124: ; preds = %119, %118
%125 = phi i32 [ 3145728, %118 ], [ %123, %119 ]
br label %126
126: ; preds = %124, %114
%127 = phi i32 [ 196608, %114 ], [ %125, %124 ]
br label %128
128: ; preds = %126, %110
%129 = phi i32 [ 61440, %110 ], [ %127, %126 ]
br label %130
130: ; preds = %128, %106
%131 = phi i32 [ 3840, %106 ], [ %129, %128 ]
br label %132
132: ; preds = %130, %102
%133 = phi i32 [ 240, %102 ], [ %131, %130 ]
br label %134
134: ; preds = %132, %98
%135 = phi i32 [ 15, %98 ], [ %133, %132 ]
%136 = sext i32 %135 to i64
store i64 %136, i64* %3
br label %137
137: ; preds = %134, %92, %47
%138 = load i64, i64* %3
ret i64 %138
}

LLVM IR (-O2):
@switch.table.reg2xset = [6 x i64] [i64 1, i64 16, i64 256, i64 4096, i64 2, i64 32]
@switch.table.reg2xset.1 = [6 x i64] [i64 3, i64 48, i64 768, i64 12288, i64 65536, i64 1048576]
@switch.table.reg2xset.2 = [6 x i64] [i64 15, i64 240, i64 3840, i64 61440, i64 196608, i64 3145728]
define i64 @reg2xset(i32 %0, i64 %1) {
switch i32 %0, label %13 [
i32 1, label %3
i32 2, label %8
]
3: ; preds = %2
%4 = icmp ult i64 %1, 6
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = icmp eq i64 %1, 6
%7 = select i1 %6, i64 512, i64 8192
br label %27
8: ; preds = %2
%9 = icmp ult i64 %1, 6
br i1 %9, label %21, label %10
10: ; preds = %8
%11 = icmp eq i64 %1, 6
%12 = select i1 %11, i64 16777216, i64 268435456
br label %27
13: ; preds = %2
%14 = icmp ult i64 %1, 6
br i1 %14, label %24, label %15
15: ; preds = %13
%16 = icmp eq i64 %1, 6
%17 = select i1 %16, i64 50331648, i64 805306368
br label %27
18: ; preds = %3
%19 = getelementptr inbounds [6 x i64], [6 x i64]* @switch.table.reg2xset, i64 0, i64 %1
%20 = load i64, i64* %19
br label %27
21: ; preds = %8
%22 = getelementptr inbounds [6 x i64], [6 x i64]* @switch.table.reg2xset.1, i64 0, i64 %1
%23 = load i64, i64* %22
br label %27
24: ; preds = %13
%25 = getelementptr inbounds [6 x i64], [6 x i64]* @switch.table.reg2xset.2, i64 0, i64 %1
%26 = load i64, i64* %25
br label %27
27: ; preds = %24, %21, %18, %15, %10, %5
%28 = phi i64 [ %7, %5 ], [ %12, %10 ], [ %17, %15 ], [ %20, %18 ], [ %23, %21 ], [ %26, %24 ]
ret i64 %28
}