def if_statement(printer, ast):
    """Prints "if (cond) {thenBody} [else {elseBody}]"."""
    cond_str = printer.ast_to_string(ast["cond"])
    then_body_str = printer.ast_to_string(ast["thenBody"])
    else_body_str = f'else {printer.ast_to_string(ast["elseBody"])}' if ast.get("elseBody") else ''
    return f'if ({cond_str}) {then_body_str} {else_body_str}'