Converted md_support.c to C++

Removed some unused variables. Converted min to std::min.
Added some static_cast<int> to keep gcc-4.1 happy.

Change-Id: I45823c40a0058a74469d8da1f95a0c65fe6c602c