ANSI'fy function declarations. Constify some globals and function paramters. Remove unsused arguments. Fix (rename) shadowed variables.