# Wrong switch decompilation

**URL:** <https://community.hex-rays.com/t/wrong-switch-decompilation/610>\
**Category:** IDA General\
**Created:** [November 26, 2025, 11:25pm UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610 "2025-11-26T23:25:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DiveriX](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@DiveriX](https://community.hex-rays.com/u/DiveriX)\
**Post date:** [November 26, 2025, 11:25pm UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610/1 "2025-11-26T23:25:52Z")

</div>

I have a problem with decompiling an obfuscated switch

After decompiling it, I get strange results like this:

![image](https://us1.discourse-cdn.com/flex002/uploads/rays_hex/original/1X/80389fbbb715ca007cce6ac775f37aab3325fba5.png)

Also, when I click _Other → Specify Switch Idiom_ and change the input register from the correct one (rax) to any other, I get good switch, but it uses the wrong variable for it.

I checked the microcode, and it’s simply optimizing it from a jtbl into a set of gotos at the stage from **MMAT\_PREOPTIMIZED** to **MMAT\_LOCOPT**

How to make IDA show the correct switch?

---

<div class="post-metadata">

**Author:** ![teresa\_hexrays](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/teresa_hexrays/32/11_2.png) [@teresa\_hexrays](https://community.hex-rays.com/u/teresa_hexrays)\
**Post date:** [November 28, 2025, 1:05pm UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610/2 "2025-11-28T13:05:57Z")

</div>

Hi @DiveriX,

Could you share the sample IDB with us? (You can send it through our [support channel](https://support.hex-rays.com/)).  
It would help us give you some more tailored advice.

---

<div class="post-metadata">

**Author:** ![ilfak](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/ilfak/32/49_2.png) [@ilfak](https://community.hex-rays.com/u/ilfak)\
**Post date:** [December 5, 2025, 10:46am UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610/3 "2025-12-05T10:46:37Z")

</div>

We cannot repro “while (1);”.  
There is “while(1) {…}” but it seems to be correct.  
Could you tell me if you have any plugins installed that may alter the decompiler output?

---

<div class="post-metadata">

**Author:** ![DiveriX](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@DiveriX](https://community.hex-rays.com/u/DiveriX)\
**Post date:** [December 6, 2025, 1:57pm UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610/4 "2025-12-06T13:57:24Z")

</div>

No, I absolutely have no plugins, except preinstalled

---

<div class="post-metadata">

**Author:** ![ilfak](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/ilfak/32/49_2.png) [@ilfak](https://community.hex-rays.com/u/ilfak)\
**Post date:** [December 6, 2025, 2:24pm UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610/6 "2025-12-06T14:24:49Z")

</div>

Could you post the decompiler output for the function in question? I wonder why we cannot repro your case.

---

<div class="post-metadata">

**Author:** ![DiveriX](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@DiveriX](https://community.hex-rays.com/u/DiveriX)\
**Post date:** [December 6, 2025, 2:29pm UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610/7 "2025-12-06T14:29:24Z")

</div>

For example this function, same problem, no switch

// attributes: thunk  
\_\_int64 \_\_fastcall sub\_661AACF0(\_\_int64 a1, \_\_int64 a2, \_\_int64 a3, unsigned \_\_int8 a4)  
{  
return a4 + 12LL;  
}

---

<div class="post-metadata">

**Author:** ![ilfak](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/ilfak/32/49_2.png) [@ilfak](https://community.hex-rays.com/u/ilfak)\
**Post date:** [January 21, 2026, 10:06am UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610/8 "2026-01-21T10:06:47Z")

</div>

Sorry for the delay. The problem occurs because of this instruction:

```auto
00000000661AAEDA 2F8 mov eax, 1Ah

```

Here EAX is overwritten with a constant value. On the other hand, EAX is marked as the input register for the table jump:

```auto
00000000661AAEE9 2F8 jmp r8 ; switch jump

```

Because of this the decompiler assumes that we always jump to the case 0x1A and removes all other code.

There is no solution to the problem now, but you can mark the instruction at 00000000661AAEDA as belonging to the switch and the switch statement will be visible in the output. You can do that with the following menu item: **Edit, Other, Toggle skippable instruction**. While not ideal, it seems to work.

---

<div class="post-metadata">

**Author:** ![igor](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/igor/32/35_2.png) [@igor](https://community.hex-rays.com/u/igor)\
**Post date:** [August 10, 2026, 1:28pm UTC](https://community.hex-rays.com/t/wrong-switch-decompilation/610/9 "2026-08-10T13:28:55Z")

</div>

We have improved switch handling so hopefully this pattern will be handled out of box in IDA 9.5.
