JIT-compiled implementation of gth_solve