percent_change as written and as decompiled
Two blocks. The top block is the four-line C source of percent_change from ledger.c. The bottom block is the fourteen-line Ghidra pseudocode of _percent_change from the analyze_function record. Three lines are marked in rose: the ulong return type where the ABI returns four bytes, the second test of iVar2 that repeats a value tested once, and the return of param_1, the whole register, where the source returns an int.
LEDGER.C · WHAT YOU WROTE
int percent_change(int before, int after) {
if (before == 0) return 0;
return (after - before) * 100 / before;
}
GHIDRA 12.1.4 PSEUDOCODE · _PERCENT_CHANGE
ulong _percent_change(ulong param_1,int param_2)
{
uint uVar1;
int iVar2;
iVar2 = (int)param_1;
if (iVar2 != 0) {
uVar1 = 0;
if (iVar2 != 0) {
uVar1 = ((param_2 - iVar2) * 100) / iVar2;
}
param_1 = (ulong)uVar1;
}
return param_1;
}
ulong return, the ABI says 4 bytes
second test of a value tested once
returns param_1, source returns int