Here is an MIT implementation in C: https://github.com/OSGeo/gdal/tree/master/alg/marching_squares
Here is an MIT implementation in C: https://github.com/OSGeo/gdal/tree/master/alg/marching_squares