optimized buddy.c