// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0xa, %ecx
cmpl %ecx, %eax
jl 0x4fe4
movl -0x34(%rbp), %eax
addl $0x32, %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x50(%rbp), %edx
callq 0x3750
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x4fd6
movq -0x30(%rbp), %rdi
callq 0x3500
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
leaq 0x32db(%rip), %rdx      # 0x829d
movb $0x0, %al
callq 0x10e0
movq $0x0, -0x8(%rbp)
jmp 0x5395
movq -0x58(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jb 0x4ff3
jmp 0x5377
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movsbl (%rax), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x5c, -0x4c(%rbp)
je 0x5097
xorl %eax, %eax
cmpl -0x4c(%rbp), %eax
jg 0x501f
cmpl $0x8, -0x4c(%rbp)
jle 0x5035
movl $0xa, %eax
cmpl -0x4c(%rbp), %eax
jg 0x502f
cmpl $0x1f, -0x4c(%rbp)
jle 0x5035
cmpl $0x7f, -0x4c(%rbp)
jne 0x5078
cmpl $0x0, -0x18(%rbp)
je 0x5047
cmpl $0xd, -0x4c(%rbp)
je 0x5076
cmpl $0xa, -0x4c(%rbp)
je 0x5076
movq -0x30(%rbp), %rdi
callq 0x3500
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
movl -0x4c(%rbp), %ecx
leaq 0x36ee(%rip), %rdx      # 0x8750
movb $0x0, %al
callq 0x10e0
movq $0x0, -0x8(%rbp)
jmp 0x5395
jmp 0x5078
movl -0x4c(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x38(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x4f7a
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jb 0x50cd
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
leaq 0x36b4(%rip), %rdx      # 0x8764
movb $0x0, %al
callq 0x10e0
movq -0x30(%rbp), %rdi
callq 0x3500
movq $0x0, -0x8(%rbp)
jmp 0x5395
cmpl $0x0, -0x18(%rbp)
je 0x511a
movq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rdi
leaq 0x359c(%rip), %rsi      # 0x8682
callq 0x1120
movq %rax, %rcx
movq -0x78(%rbp), %rax
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x5118
movq -0x40(%rbp), %rdi
leaq 0x3678(%rip), %rsi      # 0x877e
callq 0x1120
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x4f7a
jmp 0x511a
movq -0x40(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x40(%rbp)
movsbl (%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
addl $-0x22, %eax
movl %eax, %ecx
movq %rcx, -0x80(%rbp)
subl $0x53, %eax
ja 0x532c
movq -0x80(%rbp), %rax
leaq 0x2fc2(%rip), %rcx      # 0x8110
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq $0x0, -0x60(%rbp)
movl -0x4c(%rbp), %edx
movl $0x8, %eax
movl $0x4, %ecx
cmpl $0x75, %edx
cmovel %ecx, %eax
movl %eax, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x5292
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jb 0x51c5
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
movl -0x4c(%rbp), %ecx
movl -0x64(%rbp), %r8d
leaq 0x35db(%rip), %rdx      # 0x8783
movb $0x0, %al
callq 0x10e0
movq -0x30(%rbp), %rdi
callq 0x3500
movq $0x0, -0x8(%rbp)
jmp 0x5395
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movsbl (%rax), %eax
movl %eax, -0x4c(%rbp)
movl $0x30, %eax
cmpl -0x4c(%rbp), %eax
jg 0x51f8
cmpl $0x39, -0x4c(%rbp)
jg 0x51f8
movl -0x4c(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x84(%rbp)
jmp 0x5232
movl $0x41, %eax
cmpl -0x4c(%rbp), %eax
jg 0x5219
cmpl $0x46, -0x4c(%rbp)
jg 0x5219
movl -0x4c(%rbp), %eax
subl $0x41, %eax
addl $0xa, %eax
movl %eax, -0x88(%rbp)
jmp 0x5226
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x88(%rbp)
jmp 0x5226
movl -0x88(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x6c(%rbp), %eax
jne 0x5271
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
leaq 0x3548(%rip), %rdx      # 0x879c
movb $0x0, %al
callq 0x10e0
movq -0x30(%rbp), %rdi
callq 0x3500
movq $0x0, -0x8(%rbp)
jmp 0x5395
movq -0x60(%rbp), %rax
shlq $0x4, %rax
movslq -0x6c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x517c
movq -0x60(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x38(%rbp), %rax
addq %rax, %rsi
callq 0x22b0
movl %eax, -0x70(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x70(%rbp), %eax
jne 0x52df
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
leaq 0x34f9(%rip), %rdx      # 0x87bb
movb $0x0, %al
callq 0x10e0
movq -0x30(%rbp), %rdi
callq 0x3500
movq $0x0, -0x8(%rbp)
jmp 0x5395
movl -0x70(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x4f7a
movl $0x8, -0x4c(%rbp)
jmp 0x5358
movl $0x9, -0x4c(%rbp)
jmp 0x5358
movl $0xa, -0x4c(%rbp)
jmp 0x5358
movl $0xc, -0x4c(%rbp)
jmp 0x5358
movl $0xd, -0x4c(%rbp)
jmp 0x5358
movl $0x22, -0x4c(%rbp)
jmp 0x5358
movl $0x5c, -0x4c(%rbp)
jmp 0x5358
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
movl -0x4c(%rbp), %ecx
leaq 0x349a(%rip), %rdx      # 0x87d8
movb $0x0, %al
callq 0x10e0
movq -0x30(%rbp), %rdi
callq 0x3500
movq $0x0, -0x8(%rbp)
jmp 0x5395
movl -0x4c(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x38(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x4f7a
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x38(%rbp)
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)