It's a compiler optimization used to implement switch
statements that have many cases leading to one location. Note that the weird output is not Hex-Rays' doing, but rather, a more-or-less direct translation of what's in the assembly language. You didn't show the assembly for your snippet, but here's similar disassembly from a database I have open:
.text:0000000061FEA1C8 lea eax, [rdi-33h]
.text:0000000061FEA1CB cmp eax, 0Eh
.text:0000000061FEA1CE ja short loc_61FEA1F8
.text:0000000061FEA1CE
.text:0000000061FEA1D0 mov edx, 6381h
.text:0000000061FEA1D5 bt edx, eax ; <- this becomes _bittest
.text:0000000061FEA1D8 jnb short loc_61FEA1F8
And here's its Hex-Rays decompilation:
if ( (vChildOp - 51) > 0xE )
return /* ... */;
v6 = 25473;
if ( !_bittest(&v6, vChildOp - 51) )
return /* ... */;
Let's take a closer look at your snippet. You said that kBluetoothIntelHardwareVariantJfP = 0x11
and kBluetoothIntelHardwareVariantSlrF = 0x19
. Now look at the constant, 0x39E0000LL
. This is 11100111100000000000000000b
in binary:
11 1001 1110 0000 0000 0000 0000
|| | | |||- bits 0-16 clear
|| | | ||-- bit 17 (i.e., 0x11): first bit set
|| | | |--- bit 0x12 set
|| | | ---- bit 0x13 set
|| | ------ bit 0x14 set
|| --------- bit 0x17 set
|----------- bit 0x18 set
------------ bit 0x19: last bit set
Notice that the switch
statement in your example has 7 cases leading to the same label, and that two of the cases correspond to bits 0x19
and 0x11
? It is not a coincidence that the constant in the snippet has 7 bits set, including bits 0x11
and 0x19
! The bt
instruction, translated as the _bittest
intrinsic, is just checking to see whether hardwareVariant
, or a2
in the decompilation, is one of the values 0x11
-0x14
or 0x17-0x19
. It performs all 7 comparisons at the same time.
The if
-statement on the outside is the default
check: it ensures that the value of a2
is at most 0x19
-- if it's not, it jumps to the default
location, i.e., does nothing.