Incorrect modulo decompilation (when modulo is optimized by compiler)
- Dominant language
- C++
- Stars
- 8.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Hi, seems retdec incorrectly decompiles functions with modulo operation.
For example, function like this:
```c
uint64_t test(uint64_t i) {
return (0x5deece66d * i + 11) % 0xffffffffffff;
}
```
Decompiled as
```c
int64_t test(int64_t a1) {
// 0x6d0
return 0x5deece66d * a1 + 11;
}
```
Here's assembly (generated by gcc with `-O2`):
```asm
; function: test at 0x6d0 -- 0x70e
0x6d0: 48 b8 6d e6 ec de 05 00 00 00 movabs rax, 0x5deece66d
0x6da: ba 01 00 01 00 mov edx, 0x10001
0x6df: 48 0f af f8 imul rdi, rax
0x6e3: 48 83 c7 0b add rdi, 0xb
0x6e7: 48 89 f8 mov rax, rdi
0x6ea: 48 f7 e2 mul rdx
0x6ed: 48 89 f8 mov rax, rdi
0x6f0: 48 29 d0 sub rax, rdx
0x6f3: 48 d1 e8 shr rax, 1
0x6f6: 48 01 d0 add rax, rdx
0x6f9: 48 c1 e8 2f shr rax, 0x2f
0x6fd: 48 89 c2 mov rdx, rax
0x700: 48 c1 e2 30 shl rdx, 0x30
0x704: 48 29 c2 sub rdx, rax
0x707: 48 89 f8 mov rax, rdi
0x70a: 48 29 d0 sub rax, rdx
0x70d: c3 ret
```
and LLVM IR:
```llvm
define i64 @test(i64 %arg1) local_unnamed_addr {
dec_label_pc_6d0:
%v4_6df = mul i64 %arg1, 25214903917
%v1_6e3 = add i64 %v4_6df, 11
ret i64 %v1_6e3
}
```
As you can see LLVM IR code is incorrect.
I tested both latest master version and latest stable release (v3.3). This issue isn't unique to gcc and happens with any compiler that optimizes modulo operation.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.