refactor(util/sexpr/format): minimize the use of recursion, combine be and layout into a single procedure (without creating a temporary potentially big sexpr)

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>