If you allow a null parameter, I would pull out 2 methods:

int compare(Comparator c, O o1, O o2){
     if(c == null) compareWithoutComparator(o1, o2)
     else compareWithComparator(c,o1,o2)
}

This way this method becomes a lot less complex and each submethod has a single responsibility. This reduces size/complexity/bugs.