rewrite of Jotlin in C.