Join optimization: rewrite a pattern match into if/else.