TImsort implementation in C