}
 }
 
+#ifdef ASSEMBLER_DIALECT
+/* Helper function to parse assembler dialects in the asm string.
+   This is called from output_asm_insn and asm_fprintf.  */
+static const char *
+do_assembler_dialects (const char *p, int *dialect)
+{
+  char c = *(p - 1);
+
+  switch (c)
+    {
+    case '{':
+      {
+        int i;
+
+        if (*dialect)
+          output_operand_lossage ("nested assembly dialect alternatives");
+        else
+          *dialect = 1;
+
+        /* If we want the first dialect, do nothing.  Otherwise, skip
+           DIALECT_NUMBER of strings ending with '|'.  */
+        for (i = 0; i < dialect_number; i++)
+          {
+            while (*p && *p != '}' && *p++ != '|')
+             ;
+            if (*p == '}')
+             break;
+          }
+
+        if (*p == '\0')
+          output_operand_lossage ("unterminated assembly dialect alternative");
+      }
+      break;
+
+    case '|':
+      if (*dialect)
+        {
+          /* Skip to close brace.  */
+          do
+            {
+             if (*p == '\0')
+               {
+                 output_operand_lossage ("unterminated assembly dialect alternative");
+                 break;
+               }
+            }
+          while (*p++ != '}');
+          *dialect = 0;
+        }
+      else
+        putc (c, asm_out_file);
+      break;
+
+    case '}':
+      if (! *dialect)
+        putc (c, asm_out_file);
+      *dialect = 0;
+      break;
+    default:
+      gcc_unreachable ();
+    }
+
+  return p;
+}
+#endif
+
 /* Output text from TEMPLATE to the assembler output file,
    obeying %-directions to substitute operands taken from
    the vector OPERANDS.
 
 #ifdef ASSEMBLER_DIALECT
       case '{':
-       {
-         int i;
-
-         if (dialect)
-           output_operand_lossage ("nested assembly dialect alternatives");
-         else
-           dialect = 1;
-
-         /* If we want the first dialect, do nothing.  Otherwise, skip
-            DIALECT_NUMBER of strings ending with '|'.  */
-         for (i = 0; i < dialect_number; i++)
-           {
-             while (*p && *p != '}' && *p++ != '|')
-               ;
-             if (*p == '}')
-               break;
-             if (*p == '|')
-               p++;
-           }
-
-         if (*p == '\0')
-           output_operand_lossage ("unterminated assembly dialect alternative");
-       }
-       break;
-
-      case '|':
-       if (dialect)
-         {
-           /* Skip to close brace.  */
-           do
-             {
-               if (*p == '\0')
-                 {
-                   output_operand_lossage ("unterminated assembly dialect alternative");
-                   break;
-                 }
-             }
-           while (*p++ != '}');
-           dialect = 0;
-         }
-       else
-         putc (c, asm_out_file);
-       break;
-
       case '}':
-       if (! dialect)
-         putc (c, asm_out_file);
-       dialect = 0;
+      case '|':
+       p = do_assembler_dialects (p, &dialect);
        break;
 #endif
 
 {
   char buf[10];
   char *q, c;
+#ifdef ASSEMBLER_DIALECT
+  int dialect = 0;
+#endif
   va_list argptr;
 
   va_start (argptr, p);
       {
 #ifdef ASSEMBLER_DIALECT
       case '{':
-       {
-         int i;
-
-         /* If we want the first dialect, do nothing.  Otherwise, skip
-            DIALECT_NUMBER of strings ending with '|'.  */
-         for (i = 0; i < dialect_number; i++)
-           {
-             while (*p && *p++ != '|')
-               ;
-
-             if (*p == '|')
-               p++;
-           }
-       }
-       break;
-
-      case '|':
-       /* Skip to close brace.  */
-       while (*p && *p++ != '}')
-         ;
-       break;
-
       case '}':
+      case '|':
+       p = do_assembler_dialects (p, &dialect);
        break;
 #endif