// File: /workspace/github_c_makefile_star2_O0/cktan[P]tomlc99/toml.c
// Function: toml_parse
toml_table_t *toml_parse(char *conf, char *errbuf, int errbufsz) {
  context_t ctx;

  // clear errbuf
  if (errbufsz <= 0)
    errbufsz = 0;
  if (errbufsz > 0)
    errbuf[0] = 0;

  // init context
  memset(&ctx, 0, sizeof(ctx));
  ctx.start = conf;
  ctx.stop = ctx.start + strlen(conf);
  ctx.errbuf = errbuf;
  ctx.errbufsz = errbufsz;

  // start with an artificial newline of length 0
  ctx.tok.tok = NEWLINE;
  ctx.tok.lineno = 1;
  ctx.tok.ptr = conf;
  ctx.tok.len = 0;

  // make a root table
  if (0 == (ctx.root = CALLOC(1, sizeof(*ctx.root)))) {
    e_outofmemory(&ctx, FLINE);
    // Do not goto fail, root table not set up yet
    return 0;
  }

  // set root as default table
  ctx.curtab = ctx.root;

  /* Scan forward until EOF */
  for (token_t tok = ctx.tok; !tok.eof; tok = ctx.tok) {
    switch (tok.tok) {

    case NEWLINE:
      if (next_token(&ctx, 1))
        goto fail;
      break;

    case STRING:
      if (parse_keyval(&ctx, ctx.curtab))
        goto fail;

      if (ctx.tok.tok != NEWLINE) {
        e_syntax(&ctx, ctx.tok.lineno, "extra chars after value");
        goto fail;
      }

      if (eat_token(&ctx, NEWLINE, 1, FLINE))
        goto fail;
      break;

    case LBRACKET: /* [ x.y.z ] or [[ x.y.z ]] */
      if (parse_select(&ctx))
        goto fail;
      break;

    default:
      e_syntax(&ctx, tok.lineno, "syntax error");
      goto fail;
    }
  }

  /* success */
  for (int i = 0; i < ctx.tpath.top; i++)
    xfree(ctx.tpath.key[i]);
  return ctx.root;

fail:
  // Something bad has happened. Free resources and return error.
  for (int i = 0; i < ctx.tpath.top; i++)
    xfree(ctx.tpath.key[i]);
  toml_free(ctx.root);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jg 0x25c3
movl $0x0, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x25d0
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
leaq -0x1b0(%rbp), %rdi
xorl %esi, %esi
movl $0x190, %edx            # imm = 0x190
callq 0x1100
movq -0x10(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x1b0(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq -0x1d8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x1a8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x198(%rbp)
movl $0x6, -0x190(%rbp)
movl $0x1, -0x18c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x188(%rbp)
movl $0x0, -0x180(%rbp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x28b0
movq %rax, %rcx
movq %rcx, -0x178(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x2696
leaq -0x1b0(%rbp), %rdi
leaq 0x5bdc(%rip), %rsi      # 0x8260
callq 0x2910
movq $0x0, -0x8(%rbp)
jmp 0x28a3
movq -0x178(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x190(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpl $0x0, -0x1b4(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x26e3
jmp 0x2808
movl -0x1c8(%rbp), %eax
movl %eax, -0x1dc(%rbp)
subl $0x6, %eax
je 0x2717
jmp 0x26f6
movl -0x1dc(%rbp), %eax
subl $0x7, %eax
je 0x27a4
jmp 0x2707
movl -0x1dc(%rbp), %eax
subl $0x9, %eax
je 0x2737
jmp 0x27bc
leaq -0x1b0(%rbp), %rdi
movl $0x1, %esi
callq 0x2950
cmpl $0x0, %eax
je 0x2732
jmp 0x2852
jmp 0x27d7
movq -0x170(%rbp), %rsi
leaq -0x1b0(%rbp), %rdi
callq 0x2c30
cmpl $0x0, %eax
je 0x2754
jmp 0x2852
cmpl $0x6, -0x190(%rbp)
je 0x277b
movl -0x18c(%rbp), %esi
leaq -0x1b0(%rbp), %rdi
leaq 0x5afb(%rip), %rdx      # 0x826c
callq 0x3010
jmp 0x2852
leaq -0x1b0(%rbp), %rdi
movl $0x6, %esi
movl $0x1, %edx
leaq 0x5af1(%rip), %rcx      # 0x8284
callq 0x3060
cmpl $0x0, %eax
je 0x27a2
jmp 0x2852
jmp 0x27d7
leaq -0x1b0(%rbp), %rdi
callq 0x30c0
cmpl $0x0, %eax
je 0x27ba
jmp 0x2852
jmp 0x27d7
movl -0x1c4(%rbp), %esi
leaq -0x1b0(%rbp), %rdi
leaq 0x5ac0(%rip), %rdx      # 0x8290
callq 0x3010
jmp 0x2852
jmp 0x27d9
movq -0x190(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x1b8(%rbp)
jmp 0x26ce
movl $0x0, -0x1cc(%rbp)
movl -0x1cc(%rbp), %eax
cmpl -0x168(%rbp), %eax
jge 0x2845
movslq -0x1cc(%rbp), %rax
movq -0x160(%rbp,%rax,8), %rdi
callq 0x3500
movl -0x1cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1cc(%rbp)
jmp 0x2812
movq -0x178(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x28a3
movl $0x0, -0x1d0(%rbp)
movl -0x1d0(%rbp), %eax
cmpl -0x168(%rbp), %eax
jge 0x288f
movslq -0x1d0(%rbp), %rax
movq -0x160(%rbp,%rax,8), %rdi
callq 0x3500
movl -0x1d0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d0(%rbp)
jmp 0x285c
movq -0x178(%rbp), %rdi
callq 0x3530
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq