// File: /workspace/github_c_makefile_star2_O3/cktan[P]tomlc99/toml.c
// Function: norm_basic_str
static char *norm_basic_str(const char *src, int srclen, int multiline,
                            char *errbuf, int errbufsz) {
  char *dst = 0; /* will write to dst[] and return it */
  int max = 0;   /* max size of dst[] */
  int off = 0;   /* cur offset in dst[] */
  const char *sp = src;
  const char *sq = src + srclen;
  int ch;

  /* scan forward on src */
  for (;;) {
    if (off >= max - 10) { /* have some slack for misc stuff */
      int newmax = max + 50;
      char *x = expand(dst, max, newmax);
      if (!x) {
        xfree(dst);
        snprintf(errbuf, errbufsz, "out of memory");
        return 0;
      }
      dst = x;
      max = newmax;
    }

    /* finished? */
    if (sp >= sq)
      break;

    ch = *sp++;
    if (ch != '\\') {
      /* these chars must be escaped: U+0000 to U+0008, U+000A to U+001F, U+007F
       */
      if ((0 <= ch && ch <= 0x08) || (0x0a <= ch && ch <= 0x1f) ||
          (ch == 0x7f)) {
        if (!(multiline && (ch == '\r' || ch == '\n'))) {
          xfree(dst);
          snprintf(errbuf, errbufsz, "invalid char U+%04x", ch);
          return 0;
        }
      }

      // a plain copy suffice
      dst[off++] = ch;
      continue;
    }

    /* ch was backslash. we expect the escape char. */
    if (sp >= sq) {
      snprintf(errbuf, errbufsz, "last backslash is invalid");
      xfree(dst);
      return 0;
    }

    /* for multi-line, we want to kill line-ending-backslash ... */
    if (multiline) {

      // if there is only whitespace after the backslash ...
      if (sp[strspn(sp, " \t\r")] == '\n') {
        /* skip all the following whitespaces */
        sp += strspn(sp, " \t\r\n");
        continue;
      }
    }

    /* get the escaped char */
    ch = *sp++;
    switch (ch) {
    case 'u':
    case 'U': {
      int64_t ucs = 0;
      int nhex = (ch == 'u' ? 4 : 8);
      for (int i = 0; i < nhex; i++) {
        if (sp >= sq) {
          snprintf(errbuf, errbufsz, "\\%c expects %d hex chars", ch, nhex);
          xfree(dst);
          return 0;
        }
        ch = *sp++;
        int v = ('0' <= ch && ch <= '9')
                    ? ch - '0'
                    : (('A' <= ch && ch <= 'F') ? ch - 'A' + 10 : -1);
        if (-1 == v) {
          snprintf(errbuf, errbufsz, "invalid hex chars for \\u or \\U");
          xfree(dst);
          return 0;
        }
        ucs = ucs * 16 + v;
      }
      int n = toml_ucs_to_utf8(ucs, &dst[off]);
      if (-1 == n) {
        snprintf(errbuf, errbufsz, "illegal ucs code in \\u or \\U");
        xfree(dst);
        return 0;
      }
      off += n;
    }
      continue;

    case 'b':
      ch = '\b';
      break;
    case 't':
      ch = '\t';
      break;
    case 'n':
      ch = '\n';
      break;
    case 'f':
      ch = '\f';
      break;
    case 'r':
      ch = '\r';
      break;
    case '"':
      ch = '"';
      break;
    case '\\':
      ch = '\\';
      break;
    default:
      snprintf(errbuf, errbufsz, "illegal escape char \\%c", ch);
      xfree(dst);
      return 0;
    }

    dst[off++] = ch;
  }

  // Cap with NUL and return it.
  dst[off++] = 0;
  return dst;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, 0x4(%rsp)
movq %rcx, 0x10(%rsp)
movl %edx, 0x1c(%rsp)
movq %rdi, %rbp
movslq %esi, %r15
addq %rdi, %r15
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rbp, 0x20(%rsp)
movq %rbp, %r14
movl %r13d, %ebp
movq %rbx, %r12
leal -0xa(%rbp), %eax
cmpl %eax, 0x8(%rsp)
jge 0x41ac
movl %ebp, %r13d
movq %r12, %rbx
jmp 0x41ed
leal 0x32(%rbp), %r13d
movslq %r13d, %rdi
callq *0x4f57(%rip)           # 0x9110
movq %rax, %rbx
testq %rax, %rax
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
je 0x41d6
testq %rbx, %rbx
jne 0x41ed
jmp 0x4408
movslq %ebp, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1180
movq %r12, %rdi
callq *0x4f2b(%rip)           # 0x9118
cmpq %r15, %r14
jae 0x43c4
leaq 0x1(%r14), %rbp
movzbl (%r14), %r12d
cmpl $0x5c, %r12d
jne 0x4244
cmpq %r15, %rbp
jae 0x43cf
cmpl $0x0, 0x1c(%rsp)
je 0x4292
movq %rbp, %rdi
leaq 0x2351(%rip), %rsi      # 0x656f
callq 0x1120
cmpb $0xa, (%rbp,%rax)
jne 0x4299
movq %rbp, %rdi
leaq 0x2437(%rip), %rsi      # 0x666b
callq 0x1120
movq %rax, %r14
addq %rbp, %r14
jmp 0x4195
cmpb $0x9, %r12b
jb 0x425f
leal -0xa(%r12), %eax
cmpb $0x16, %al
setae %al
cmpb $0x7f, %r12b
setne %cl
testb %al, %cl
jne 0x427a
cmpl $0x0, 0x1c(%rsp)
je 0x4457
cmpl $0xa, %r12d
je 0x427a
cmpl $0xd, %r12d
jne 0x4457
movq 0x8(%rsp), %rcx
movslq %ecx, %rax
incl %ecx
movq %rcx, 0x8(%rsp)
movb %r12b, (%rbx,%rax)
jmp 0x418d
movq 0x20(%rsp), %r12
jmp 0x429c
movq %r14, %r12
leaq 0x2(%r12), %rbp
movb 0x1(%r14), %al
movsbl %al, %ecx
movzbl %cl, %edx
cmpl $0x61, %edx
jg 0x42d1
cmpl $0x22, %edx
movq 0x8(%rsp), %rdi
je 0x4383
cmpl $0x55, %edx
je 0x42f9
cmpl $0x5c, %edx
je 0x4383
jmp 0x4486
leal -0x6e(%rdx), %esi
cmpl $0x7, %esi
movq 0x8(%rsp), %rdi
ja 0x4369
leaq 0x1e67(%rip), %r8       # 0x6150
movslq (%r8,%rsi,4), %rdx
addq %r8, %rdx
jmpq *%rdx
movb $0xa, %al
jmp 0x4383
xorl %edx, %edx
cmpb $0x75, %al
setne %dl
leal 0x4(,%rdx,4), %r8d
cmpq %r15, %rbp
jae 0x443e
movl %r8d, %eax
negl %eax
incq %rax
xorl %r14d, %r14d
xorl %edi, %edi
movsbl (%rbp), %ecx
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x432f
leal -0x30(%rcx), %edx
jmp 0x433e
leal -0x41(%rcx), %edx
cmpb $0x5, %dl
ja 0x4431
leal -0x37(%rcx), %edx
cmpl $-0x1, %edx
je 0x4431
movq %rdi, %rsi
shlq $0x4, %rsi
movslq %edx, %rdi
addq %rsi, %rdi
cmpl %r14d, %eax
je 0x4395
incq %rbp
decq %r14
cmpq %r15, %rbp
jb 0x431e
jmp 0x443e
movb $0x8, %al
cmpl $0x62, %edx
je 0x4383
cmpl $0x66, %edx
jne 0x4486
movb $0xc, %al
jmp 0x4383
movb $0x9, %al
jmp 0x4383
movb $0xd, %al
movslq %edi, %rcx
incl %edi
movq %rdi, 0x8(%rsp)
movb %al, (%rbx,%rcx)
jmp 0x418d
movq 0x8(%rsp), %rbp
movslq %ebp, %rsi
addq %rbx, %rsi
callq 0x1efb
cmpl $-0x1, %eax
je 0x44a2
subq %r14, %r12
addq $0x3, %r12
addl %eax, %ebp
movq %rbp, 0x8(%rsp)
movq %r12, %rbp
jmp 0x418d
movslq 0x8(%rsp), %rax
movb $0x0, (%rbx,%rax)
jmp 0x43f6
movl 0x4(%rsp), %esi
leaq 0x2277(%rip), %rdx      # 0x6651
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x10e0
testq %rbx, %rbx
je 0x43f4
movq %rbx, %rdi
callq *0x4d24(%rip)           # 0x9118
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r12, %r12
je 0x4416
movq %r12, %rdi
callq *0x4d02(%rip)           # 0x9118
movl 0x4(%rsp), %esi
leaq 0x1d98(%rip), %rdx      # 0x61b9
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x10e0
jmp 0x43f6
movl 0x4(%rsp), %esi
leaq 0x224d(%rip), %rdx      # 0x6689
jmp 0x43da
movl 0x4(%rsp), %esi
leaq 0x2227(%rip), %rdx      # 0x6670
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x10e0
jmp 0x43e6
testq %rbx, %rbx
je 0x4465
movq %rbx, %rdi
callq *0x4cb3(%rip)           # 0x9118
movl 0x4(%rsp), %esi
leaq 0x21cd(%rip), %rdx      # 0x663d
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x10e0
jmp 0x43f6
movl 0x4(%rsp), %esi
leaq 0x2234(%rip), %rdx      # 0x66c5
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x10e0
jmp 0x43e6
movl 0x4(%rsp), %esi
leaq 0x21fb(%rip), %rdx      # 0x66a8
jmp 0x43da