rewrite as C code