[PATCH 2/4] detstats.c: move detstats() and its helper functions into separate file