Optimized implementation of "findleaves.py" (Android's build tool)