Fix compiler warnings if -O2 is specified

Also fix sparse warnings while at it.