binaryninja-api
binaryninja-api copied to clipboard
`do-while` loop simplification
What is the feature you'd like to have?
The following pattern is very common for loop thats left as a do-while
180010c7c if (i_7 != 0)
180010c7e int16_t* rdi_1 = arg1 - rbx
180010c81 uint64_t i_4 = zx.q(i_7)
180010c95 uint64_t i
180010c95 do
180010c8b *rbx = *rbx + (*(rdi_1 + rbx) & r8_3)
180010c8e rbx = &rbx[1]
180010c92 i = i_4
180010c92 i_4 = i_4 - 1
180010c95 while (i != 1)
This can be simplified to
if (i_7 != 0)
int16_t* rdi_1 = arg1 - rbx;
for (uint64_t i_4 = zx.q(i_7); i_4 > 1; i_4 -= 1)
*rbx = *rbx + (*(rdi_1 + rbx) & r8_3);
rbx = &rbx[1];
This example comes from the internally shared binary unicorn chess taco rainbow many many more examples of this can be found by searching for while (i != 1)