Fixed a merge failure of mine
Moved some prototypes from misc.c to misc.h to be used in debug.c
Added missing headers and fixed the type signedness issues.