// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/JsonParse.cpp
// Function: t2::JsonParseArray(t2::JsonState*)
static const JsonValue* JsonParseArray(JsonState* json_state)
{
  JsonLexerState* lexer = &json_state->m_Lexer;

  if (!JsonLexerExpect(lexer, kJsonLexBeginArray))
    return JsonError(json_state, "expected '['");

  MemAllocLinearScope scratch_scope(json_state->m_Scratch);

  struct ListElem
  {
    const JsonValue *m_Value;
    ListElem        *m_Next;
  };

  struct ValueList
  {
    MemAllocLinear *m_Scratch;
    ListElem       *m_Head;
    ListElem       *m_Tail;
    size_t          m_Count;

    void Init(MemAllocLinear* scratch)
    {
      m_Scratch = scratch;
      m_Head    = nullptr;
      m_Tail    = nullptr;
      m_Count   = 0;
    }

    void Add(const JsonValue* value)
    {
      if (1 == ++m_Count)
      {
        m_Head = m_Tail = LinearAllocate<ListElem>(m_Scratch);
        m_Head->m_Value = value;
        m_Head->m_Next  = nullptr;
      }
      else
      {
        ListElem* tail = m_Tail;
        m_Tail          = LinearAllocate<ListElem>(m_Scratch);
        m_Tail->m_Value = value;
        m_Tail->m_Next  = nullptr;
        tail->m_Next    = m_Tail;
      }
    }
  };

  ValueList value_list;

  value_list.Init(json_state->m_Scratch);

  for (;;)
  {
    JsonLexeme l = JsonLexerPeek(lexer);

    if (kJsonLexEndArray == l.m_Type)
    {
      JsonLexerSkip(lexer);
      break;
    }

    if (value_list.m_Count > 0)
    {
      if (kJsonLexValueSeparator != l.m_Type)
      {
        return JsonError(json_state, "expected ','");
      }

      JsonLexerSkip(lexer);
    }

    const JsonValue* value = JsonParseValue(json_state);
    if (!value)
      return nullptr;

    value_list.Add(value);
  }

  MemAllocLinear* alloc = json_state->m_Allocator;

  size_t            count  = value_list.m_Count;
  const JsonValue **values = LinearAllocateArray<const JsonValue*>(alloc, count);

  size_t index = 0;
  for (ListElem* p = value_list.m_Head; p; p = p->m_Next, ++index)
  {
    values[index] = p->m_Value;
  }

  JsonArrayValue* result = LinearAllocate<JsonArrayValue>(alloc);
  result->m_Type   = JsonValue::kArray;
  result->m_Count  = count;
  result->m_Values = values;

  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0x5, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x175b0
testb $0x1, %al
jne 0x17b76
movq -0x10(%rbp), %rdi
leaq 0xd59a(%rip), %rsi      # 0x25102
callq 0x17610
movq %rax, -0x8(%rbp)
jmp 0x17dab
movq -0x10(%rbp), %rax
movq 0x828(%rax), %rsi
leaq -0x28(%rbp), %rdi
callq 0x6e40
movq -0x10(%rbp), %rax
movq 0x828(%rax), %rsi
leaq -0x48(%rbp), %rdi
callq 0x18710
jmp 0x17ba0
jmp 0x17ba2
movq -0x18(%rbp), %rdi
callq 0x176a0
movq %rdx, -0xb8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x17bba
movq -0xb8(%rbp), %rax
movl -0xac(%rbp), %ecx
movl %ecx, -0x68(%rbp)
movq %rax, -0x60(%rbp)
movl $0x7, %eax
cmpl -0x68(%rbp), %eax
jne 0x17c02
movq -0x18(%rbp), %rdi
callq 0x17dd0
jmp 0x17be3
jmp 0x17c9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6f50
jmp 0x17db8
cmpq $0x0, -0x30(%rbp)
jbe 0x17c50
movl $0x2, %eax
cmpl -0x68(%rbp), %eax
je 0x17c43
movq -0x10(%rbp), %rdi
leaq 0xd48c(%rip), %rsi      # 0x250aa
callq 0x17610
movq %rax, -0xc0(%rbp)
jmp 0x17c2c
movq -0xc0(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x17da2
movq -0x18(%rbp), %rdi
callq 0x17dd0
jmp 0x17c4e
jmp 0x17c50
movq -0x10(%rbp), %rdi
callq 0x17460
movq %rax, -0xc8(%rbp)
jmp 0x17c62
movq -0xc8(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x17c88
movq $0x0, -0x8(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x17da2
movq -0x78(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x18750
jmp 0x17c97
jmp 0x17ba2
movq -0x10(%rbp), %rax
movq 0x820(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x18890
movq %rax, -0xd0(%rbp)
jmp 0x17ccf
movq -0xd0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x17d3f
movq -0xa0(%rbp), %rax
movq (%rax), %rdx
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x17cf3
movq -0x80(%rbp), %rdi
callq 0x188f0
movq %rax, -0xd8(%rbp)
jmp 0x17d51
movq -0xd8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movl $0x3, (%rax)
movq -0x88(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x90(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0xa8(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x6c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6f50
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x35c0
nopw %cs:(%rax,%rax)