i think this line would probably answer your problem.
basically it calculates the base HP
then subtracts 1,000,000 hp
checks if it is within the min and max hp supported by the emulator.
all the bonuses will be checked afterwards.
my suggestion is that instead of subtracting a raw 1000000 hp, why not lessen it by %?
for example 20% of max hp
i = sd->status.max_hp + (int)status->max_hp;
+ i = i - i*20/100
status->max_hp = cap_value(i, 0, INT_MAX);