Ported get_layer_range() to C