Compare u32 as u32 and not int

Set IDs to UINT32_MAX before qsorting to move them to the end
Adjust compare functions to return int without casting IDs to int