// File: /workspace/github_c_makefile_star2_O2/mmayer[P]pcal/src/pcalutil.c
// Function: cvt_escape
void cvt_escape (char *obuf, char *ibuf)
{
   char c, c2, *po, *pi, *p, *dfltfont;
   static char whitespace[] = "abnrtv"; /* see ANSI spec, 2.2.2 */
   static char no_cvt[] = "\"'\\";
   
   dfltfont = fontstyle[0] == BOLD   ? BOLD_FONT :
      fontstyle[0] == ITALIC ? ITALIC_FONT :
      ROMAN_FONT ;

   strcpy(currfont, dfltfont);   /* defaults for font style */
   strcpy(prevfont, dfltfont);
   
   for (po = obuf, pi = ibuf; (c = *pi) != '\0'; *po++ = c, pi++) {

      /* handle escape sequences here:
        
          escaped whitespace and ANSI escapes (except \f) are all converted to
          a single space;

          octal and hex constants are converted in place;

          escaped single/double quotes are left escaped for loadwords() to
          handle later on;
        
          if the output is PostScript:

            \f[BIR] is converted to " .[bir] ";
            \fP is converted to the previous " .[bir] ";
            <[BI]> is converted to " .[bi] ";
            </[BI]> is converted to the previous " .[bir] "
        
          if the output is HTML:

            \f[BI] is converted to "<[BI]>";
            \f[PR] is converted to the previous "</[BI]>";
            <[BI]> and </[BI]> are copied intact

       */
      if (c == '\\') {
         c2 = *++pi;
         if (isspace((int)c2) || strchr(whitespace, c2)) {
            c = ' ';
         }
         else if (isodigit(c2)) {   /* octal */
            pi = octal_esc(pi, &c);
         }
         else if (tolower(c2) == 'x') {   /* hex */
            pi = hex_esc(pi, &c);
         }
         else if (c2 == 'f') {   /* \f[BIPR] */
            c = output_type == OUTPUT_HTML ? '>' : ' ';
            if (*++pi == BOLD) po = set_fontstyle(po, BOLD_FONT);
            else if (*pi == ITALIC) po = set_fontstyle(po, ITALIC_FONT);
            else if (*pi == PREVFONT) po = set_fontstyle(po, prevfont);
            else if (*pi == ROMAN) po = set_fontstyle(po, ROMAN_FONT);
            else {   /* unrecognized \f escape */
               *po++ = ' ';
               c = *pi;
            }
         }
         else {
            if (strchr(no_cvt, c2)) *po++ = c;   /* leave escaped */
            c = c2;
         }
      }
      else if (output_type != OUTPUT_HTML && (p = html_esc(pi, &c2)) != pi) {
         /* convert special HTML character back to ASCII */
         pi = p;
         if (c2 == '"') *po++ = '\\';
         c = c2;
      }
      else if (HTML_ESCAPE(pi)) {
         /* convert HTML escape to PostScript */
         c2 = *++pi;
         if ((c2 = toupper(c2)) == BOLD) po = set_fontstyle(po, BOLD_FONT);
         else if (c2 == ITALIC) po = set_fontstyle(po, ITALIC_FONT);
         else po = set_fontstyle(po, prevfont); /* </[BI]> */

         while ((c = *++pi) != '>')
            ;

         c = output_type == OUTPUT_HTML ? '>' : ' ';
      }
   }
   
   /* if generating HTML, reset font at end of line if necessary */
   if (output_type == OUTPUT_HTML && currfont[1] != dfltfont[1]) {
      *po++ = '<';
      *po++ = '/';
      *po++ = currfont[1];
      *po++ = '>';
   }
   *po = '\0';

   return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x1e907(%rip), %rax     # 0x28c86
movb (%rax), %al
cmpb $0x49, %al
leaq 0x131aa(%rip), %rdx     # 0x1d534
leaq 0x131a6(%rip), %rcx     # 0x1d537
cmoveq %rdx, %rcx
cmpb $0x42, %al
leaq 0x13193(%rip), %rax     # 0x1d531
cmoveq %rax, %rcx
movzwl (%rcx), %eax
movw %ax, 0x2336e(%rip)      # 0x2d71a
movq %rcx, 0x10(%rsp)
movb 0x2(%rcx), %cl
movb %cl, 0x23362(%rip)      # 0x2d71c
movw %ax, 0x2334f(%rip)      # 0x2d710
movb %cl, 0x2334b(%rip)      # 0x2d712
movzbl (%r14), %r12d
cmpl $0x5c, %r12d
je 0xa44e
testl %r12d, %r12d
je 0xa741
cmpb $0x26, %r12b
jne 0xa4fc
leaq 0x222cd(%rip), %rax     # 0x2c6b8
cmpl $0x2, (%rax)
je 0xa4fc
cmpb $0x23, 0x1(%r14)
jne 0xa499
callq 0x5330
movq (%rax), %rax
movsbq 0x2(%r14), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0xa499
movsbq 0x3(%r14), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0xa499
movsbq 0x4(%r14), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0xa499
cmpb $0x3b, 0x5(%r14)
jne 0xa499
leaq 0x2(%r14), %rdi
addq $0x5, %r14
callq 0x52c0
movl %eax, %r12d
movq %r14, %rax
jmp 0xa4e5
movq %rbx, (%rsp)
leaq 0x1(%r14), %rbp
movb 0x1(%r14), %r12b
callq 0x5330
movq (%rax), %r15
movsbq %r12b, %rbx
testb $0x20, 0x1(%r15,%rbx,2)
jne 0xa48a
movsbl %r12b, %r13d
leaq 0x1f74b(%rip), %rdi     # 0x29bc4
movl %r13d, %esi
callq 0x5120
testq %rax, %rax
je 0xa5c1
movb $0x20, %r12b
movq %rbp, %r14
movq (%rsp), %rbx
jmp 0xa728
leaq 0x1f730(%rip), %rbp     # 0x29bd0
movq %rbp, 0x23351(%rip)     # 0x2d7f8
movq (%rbp), %r15
testq %r15, %r15
je 0xa4fc
movq %r15, %rdi
callq 0x5100
movq %rax, %r13
movq %r14, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x9665
testl %eax, %eax
je 0xa4d3
addq $0x10, %rbp
jmp 0xa4a0
movslq %r13d, %rax
addq %r14, %rax
decq %rax
cmpq %r14, %rax
je 0xa4fc
movb 0x8(%rbp), %r12b
cmpb $0x22, %r12b
jne 0xa4f4
movb $0x5c, (%rbx)
incq %rbx
movb $0x22, %r12b
movq %rax, %r14
jmp 0xa728
cmpb $0x3c, %r12b
jne 0xa728
movsbl 0x1(%r14), %eax
movslq %eax, %r13
leaq 0x13025(%rip), %rdi     # 0x1d53a
movl %r13d, %esi
pushq $0x5
popq %rdx
callq 0x51d0
testq %rax, %rax
je 0xa52c
cmpb $0x3e, 0x2(%r14)
je 0xa561
movb $0x3c, %r12b
cmpb $0x2f, %r13b
jne 0xa728
movsbl 0x2(%r14), %esi
leaq 0x12ff5(%rip), %rdi     # 0x1d53a
pushq $0x5
popq %rdx
callq 0x51d0
testq %rax, %rax
je 0xa728
cmpb $0x3e, 0x3(%r14)
jne 0xa728
incq %r14
callq 0x5030
movq (%rax), %rax
movb (%rax,%r13,4), %al
cmpb $0x49, %al
leaq 0x23197(%rip), %rsi     # 0x2d710
leaq 0x12fb4(%rip), %rcx     # 0x1d534
cmoveq %rcx, %rsi
cmpb $0x42, %al
leaq 0x12fa4(%rip), %rax     # 0x1d531
cmoveq %rax, %rsi
movq %rbx, %rdi
callq 0x99f1
movq %rax, %rbx
cmpb $0x3e, 0x1(%r14)
leaq 0x1(%r14), %r14
jne 0xa59c
leaq 0x2210a(%rip), %rax     # 0x2c6b8
cmpl $0x2, (%rax)
pushq $0x20
popq %r12
pushq $0x3e
popq %rax
cmovel %eax, %r12d
jmp 0xa728
movl %r13d, 0xc(%rsp)
movl %r12d, %eax
andb $-0x8, %al
cmpb $0x30, %al
jne 0xa603
xorl %eax, %eax
xorl %r12d, %r12d
movq (%rsp), %rbx
cmpq $0x3, %rax
je 0xa669
movb 0x1(%r14,%rax), %cl
movl %ecx, %edx
andb $-0x8, %dl
cmpb $0x30, %dl
jne 0xa669
shlb $0x3, %r12b
addb %r12b, %cl
addb $-0x30, %cl
incq %rax
movl %ecx, %r12d
jmp 0xa5d8
callq 0x5320
movq (%rax), %rax
cmpl $0x78, (%rax,%rbx,4)
jne 0xa671
addq $0x2, %r14
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rsp), %rbx
cmpq $0x2, %rax
je 0xa6f0
movsbq (%r14,%rax), %rdx
testq %rdx, %rdx
je 0xa6bd
movzwl (%r15,%rdx,2), %esi
btl $0xc, %esi
jae 0xa6bd
btl $0x9, %esi
movl $0xd0, %edi
jae 0xa650
movl $0xa9, %edi
shlb $0x4, %cl
btl $0x8, %esi
movl $0xc9, %esi
cmovbl %esi, %edi
addb %dl, %cl
addb %dil, %cl
incq %rax
jmp 0xa61d
addq %rax, %r14
jmp 0xa728
cmpb $0x66, %r12b
jne 0xa6cc
leaq 0x2203a(%rip), %rax     # 0x2c6b8
cmpl $0x2, (%rax)
pushq $0x20
popq %r12
pushq $0x3e
popq %rax
cmovel %eax, %r12d
movzbl 0x2(%r14), %eax
addq $0x2, %r14
cmpl $0x52, %eax
movq (%rsp), %rbx
je 0xa716
cmpl $0x49, %eax
je 0xa6fe
cmpl $0x50, %eax
je 0xa70a
cmpl $0x42, %eax
jne 0xa736
movq %rbx, %rdi
leaq 0x12e76(%rip), %rsi     # 0x1d531
jmp 0xa720
testq %rax, %rax
movzbl %r12b, %edx
movzbl %cl, %ecx
cmovel %edx, %ecx
jmp 0xa6f3
leaq 0x1f4f8(%rip), %rdi     # 0x29bcb
movl 0xc(%rsp), %esi
callq 0x5120
testq %rax, %rax
movq (%rsp), %rbx
je 0xa6eb
movb $0x5c, (%rbx)
incq %rbx
movq %rbp, %r14
jmp 0xa728
pushq $0x2
popq %rax
addq %rax, %r14
decq %r14
movl %ecx, %r12d
jmp 0xa728
movq %rbx, %rdi
leaq 0x12e2c(%rip), %rsi     # 0x1d534
jmp 0xa720
movq %rbx, %rdi
leaq 0x22ffc(%rip), %rsi     # 0x2d710
jmp 0xa720
movq %rbx, %rdi
leaq 0x12e17(%rip), %rsi     # 0x1d537
callq 0x99f1
movq %rax, %rbx
movb %r12b, (%rbx)
incq %rbx
incq %r14
jmp 0xa3c7
movb $0x20, (%rbx)
incq %rbx
movb (%r14), %r12b
jmp 0xa728
leaq 0x21f70(%rip), %rax     # 0x2c6b8
cmpl $0x2, (%rax)
jne 0xa773
movb 0x22fc8(%rip), %al      # 0x2d71b
movq 0x10(%rsp), %rcx
cmpb 0x1(%rcx), %al
je 0xa773
movw $0x2f3c, (%rbx)         # imm = 0x2F3C
movb 0x22fb3(%rip), %al      # 0x2d71b
movb %al, 0x2(%rbx)
movb $0x3e, 0x3(%rbx)
addq $0x4, %rbx
movb $0x0, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq