C alloc implementation for learning purposes