// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rcx, 0x18(%rsp)
movl %edx, 0x24(%rsp)
movslq %esi, %rbp
addq %rdi, %rbp
movl %r8d, %eax
movq %rax, 0x10(%rsp)
movq %rdi, %rax
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %ebx, %ebx
movl %r12d, 0x4(%rsp)
movq %rax, 0x8(%rsp)
movq %rax, %r12
leal -0xa(%r15), %eax
cmpl %eax, 0x4(%rsp)
jl 0x442a
leal 0x32(%r15), %r13d
movslq %r13d, %rdi
callq *0x4d5a(%rip)           # 0x9118
testq %rax, %rax
je 0x43e4
movq %rax, %r14
testq %rbx, %rbx
je 0x43e7
movslq %r15d, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movq %rbx, %rdi
callq *0x4d3e(%rip)           # 0x9120
jmp 0x43e7
xorl %r14d, %r14d
movq %r14, %rax
testq %r14, %r14
jne 0x441b
testq %rbx, %rbx
je 0x43fd
movq %rbx, %rdi
callq *0x4d23(%rip)           # 0x9120
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x1d87(%rip), %rdx      # 0x6195
xorl %eax, %eax
callq 0x10f0
movl %r15d, %r13d
movq %rbx, %rax
movl %r13d, %r15d
movq %rax, %rbx
testq %r14, %r14
je 0x4715
cmpq %rbp, %r12
jae 0x46e4
leaq 0x1(%r12), %r14
movsbl (%r12), %r13d
cmpl $0x5c, %r13d
jne 0x4483
cmpq %rbp, %r14
jae 0x46ef
cmpl $0x0, 0x24(%rsp)
je 0x44cc
movq %r14, %rdi
leaq 0x20ee(%rip), %rsi      # 0x654b
callq 0x1130
cmpb $0xa, (%r14,%rax)
jne 0x44d3
movq %r14, %rdi
leaq 0x21d4(%rip), %rsi      # 0x6647
callq 0x1130
movq %rax, %r12
addq %r14, %r12
jmp 0x43a7
cmpb $0x9, %r13b
jb 0x44a1
leal -0xa(%r13), %eax
cmpb $0x16, %al
setae %al
cmpb $0x7f, %r13b
setne %cl
testb %al, %cl
jne 0x461c
cmpl $0x0, 0x24(%rsp)
movl 0x4(%rsp), %r12d
je 0x4729
movzbl %r13b, %eax
cmpl $0xa, %eax
je 0x4666
cmpl $0xd, %eax
je 0x4666
jmp 0x4729
movq 0x8(%rsp), %r14
jmp 0x44d6
movq %r12, %r14
addq $0x2, %r14
movb 0x1(%r12), %r13b
movsbl %r13b, %ecx
movzbl %cl, %eax
cmpl $0x61, %eax
jg 0x450c
cmpl $0x22, %eax
movl 0x4(%rsp), %r12d
je 0x4666
cmpl $0x55, %eax
je 0x4535
cmpl $0x5c, %eax
je 0x4666
jmp 0x4756
leal -0x6e(%rax), %esi
cmpl $0x7, %esi
movl 0x4(%rsp), %r12d
ja 0x4606
leaq 0x1c08(%rip), %rdx      # 0x612c
movslq (%rdx,%rsi,4), %rax
addq %rdx, %rax
jmpq *%rax
movb $0xa, %r13b
jmp 0x4666
xorl %eax, %eax
cmpb $0x75, %r13b
setne %al
leal 0x4(,%rax,4), %r8d
movb $0x1, %dl
cmpq %rbp, %r14
jae 0x4623
movl $0x1, %r13d
xorl %edi, %edi
movl %r8d, 0x20(%rsp)
movsbl (%r14), %ecx
leal -0x30(%rcx), %eax
cmpb $0x9, %al
ja 0x456f
leal -0x30(%rcx), %r12d
jmp 0x4581
leal -0x41(%rcx), %eax
leal -0x37(%rcx), %r12d
cmpb $0x6, %al
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovael %eax, %r12d
cmpl $-0x1, %r12d
je 0x4593
shlq $0x4, %rdi
movslq %r12d, %rax
addq %rax, %rdi
jmp 0x45da
movb %dl, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x20b3(%rip), %rdx      # 0x6665
xorl %eax, %eax
callq 0x10f0
testq %rbx, %rbx
je 0x45c7
movq %rbx, %rdi
callq *0x4b59(%rip)           # 0x9120
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rdi
movb 0x8(%rsp), %dl
movl 0x20(%rsp), %r8d
incq %r14
cmpl $-0x1, %r12d
je 0x4678
cmpl %r8d, %r13d
setb %dl
movl 0x4(%rsp), %r12d
je 0x4682
incl %r13d
cmpq %rbp, %r14
jb 0x455e
jmp 0x4625
movb $0x8, %r13b
cmpl $0x62, %eax
je 0x4666
cmpl $0x66, %eax
jne 0x4756
movb $0xc, %r13b
jmp 0x4666
movl 0x4(%rsp), %r12d
jmp 0x4666
xorl %edi, %edi
movb %dl, 0x8(%rsp)
movq %rdi, %r13
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x200f(%rip), %rdx      # 0x664c
xorl %eax, %eax
callq 0x10f0
testq %rbx, %rbx
je 0x4652
movq %rbx, %rdi
callq *0x4ace(%rip)           # 0x9120
movq %r14, %rax
movq %r13, %rdi
movb 0x8(%rsp), %dl
jmp 0x4685
movb $0x9, %r13b
jmp 0x4666
movb $0xd, %r13b
movslq %r12d, %rax
incl %r12d
movb %r13b, (%rbx,%rax)
movq %r14, %rax
jmp 0x439a
movq %r14, %rax
movl 0x4(%rsp), %r12d
jmp 0x4685
movq %r14, %rax
testb $0x1, %dl
je 0x468f
xorl %r14d, %r14d
jmp 0x46d9
movq %rax, %r13
movslq %r12d, %rsi
addq %rbx, %rsi
callq 0x1fed
cmpl $-0x1, %eax
je 0x46aa
addl %eax, %r12d
movb $0x1, %r14b
jmp 0x46d6
xorl %r14d, %r14d
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x1fc6(%rip), %rdx      # 0x6684
xorl %eax, %eax
callq 0x10f0
testq %rbx, %rbx
je 0x46d6
movq %rbx, %rdi
callq *0x4a4d(%rip)           # 0x9120
xorl %r14d, %r14d
movq %r13, %rax
testb %r14b, %r14b
jne 0x439a
jmp 0x4715
movslq 0x4(%rsp), %rax
movb $0x0, (%rbx,%rax)
jmp 0x4717
leaq 0x1f37(%rip), %rdx      # 0x662d
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x10f0
testq %rbx, %rbx
je 0x4715
movq %rbx, %rdi
callq *0x4a0b(%rip)           # 0x9120
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
je 0x4737
movq %rbx, %rdi
callq *0x49e9(%rip)           # 0x9120
leaq 0x1edb(%rip), %rdx      # 0x6619
xorl %ebx, %ebx
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x10f0
jmp 0x4717
leaq 0x1f44(%rip), %rdx      # 0x66a1
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x10f0
jmp 0x4707