// File: /workspace/github_c_makefile_star2_O1/TurkeyMcMac[P]ts3d/src/json-util.c
// Function: parse_node
static void parse_node(json_reader *rdr, struct json_node *nd, char **keyp)
{
	size_t cap;
	struct json_item item;
	nd->taken = false;
	if (json_read_item(rdr, &item) < 0) {
		print_json_error(rdr, &item);
		nd->kind = JN_ERROR;
		return;
	}
	*keyp = item.key.bytes;
	switch (item.type) {
	case JSON_EMPTY:
		nd->kind = JN_EMPTY;
		break;
	case JSON_NULL:
		nd->kind = JN_NULL;
		break;
	case JSON_MAP:
		nd->kind = JN_MAP;
		table_init(&nd->d.map, 8);
		for (;;) {
			char *key = NULL;
			struct json_node *entry = xmalloc(sizeof(*entry));
			parse_node(rdr, entry, &key);
			if (entry->kind == JN_END_) {
				free_json_pair(key, entry);
				break;
			} else if (entry->kind == JN_ERROR) {
				free_json_pair(key, entry);
				const char *k;
				void **v;
				TABLE_FOR_EACH(&nd->d.map, k, v) {
					free_json_pair(k, *v);
				}
				table_free(&nd->d.map);
				nd->kind = JN_ERROR;
				return;
			}
			if (!key || table_add(&nd->d.map, key, entry))
				// With duplicate keys, the first is kept:
				free_json_pair(key, entry);
		}
		table_freeze(&nd->d.map);
		break;
	case JSON_LIST:
		nd->kind = JN_LIST;
		cap = 8;
		nd->d.list.n_vals = 0;
		nd->d.list.vals = xmalloc(cap * sizeof(*nd->d.list.vals));
		for (;;) {
			char *key = NULL;
			struct json_node *entry = GROWE(nd->d.list.vals,
				nd->d.list.n_vals, cap);
			parse_node(rdr, entry, &key);
			if (entry->kind == JN_END_) {
				--nd->d.list.n_vals;
				break;
			} else if (entry->kind == JN_ERROR) {
				free(key);
				for (size_t i = 0; i < nd->d.list.n_vals; ++i) {
					free_json_tree(&nd->d.list.vals[i]);
				}
				free(nd->d.list.vals);
				nd->kind = JN_ERROR;
				return;
			}
		}
		break;
	case JSON_STRING:
		nd->kind = JN_STRING;
		nd->d.str = item.val.str.bytes;
		break;
	case JSON_NUMBER:
		nd->kind = JN_NUMBER;
		nd->d.num = item.val.num;
		break;
	case JSON_BOOLEAN:
		nd->kind = JN_BOOLEAN;
		nd->d.boolean = item.val.boolean;
		break;
	case JSON_END_MAP:
	case JSON_END_LIST:
		nd->kind = JN_END_;
		break;
	default:
		break;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movb $0x0, 0x4(%rsi)
leaq 0x20(%rsp), %rsi
callq 0x56ae
testl %eax, %eax
js 0x4e9b
movq 0x20(%rsp), %rax
movq %rax, (%r15)
movl 0x30(%rsp), %eax
cmpq $0x8, %rax
ja 0x5213
leaq 0x7519(%rip), %rcx      # 0xc3a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x8, (%rbx)
jmp 0x5213
movq %r14, %rdi
callq 0x5674
movq (%rax), %r12
movl 0x2010(%r12), %ebp
leaq 0x18(%rsp), %rsi
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x5660
movq 0x38(%rsp), %rdi
movq (%r15), %r14
cmpq %r14, %rdi
jae 0x4f00
movq 0x18(%rsp), %rax
addq %rax, %rdi
addq %rax, %r14
movq %r14, %rdx
subq %rdi, %rdx
movl $0xa, %esi
callq 0x20d0
testq %rax, %rax
je 0x4f00
decl %ebp
incq %rax
movq %r14, %rdx
subq %rax, %rdx
movq %rax, %rdi
jmp 0x4ee1
movl 0x30(%rsp), %eax
addl $-0x9, %eax
cmpl $0xb, %eax
ja 0x51e0
leaq 0x74ad(%rip), %rcx      # 0xc3c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x751d(%rip), %r9       # 0xc444
jmp 0x51e7
movl $0x2, (%rbx)
leaq 0x8(%rbx), %rdi
movl $0x8, %esi
movq %rdi, 0x10(%rsp)
callq 0xa720
leaq 0x8(%rsp), %r15
movq $0x0, 0x8(%rsp)
movl $0x20, %edi
callq 0xb1ac
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x4e41
movl (%r13), %eax
movq 0x8(%rsp), %rbp
cmpl $0x7, %eax
je 0x4fa7
cmpl $0x8, %eax
jne 0x5018
movq %rbp, %rdi
callq 0x2570
movq %r13, %rdi
callq 0x5222
movq %r13, %rdi
callq 0x2570
movl $0x3, %eax
jmp 0x504b
movq %rbp, %rdi
callq 0x2570
movq %r13, %rdi
callq 0x5222
movq %r13, %rdi
callq 0x2570
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
je 0x5001
movl $0x8, %ebp
xorl %r12d, %r12d
movq 0x18(%rbx), %rax
movq -0x8(%rax,%rbp), %rdi
movq (%rax,%rbp), %r13
callq 0x2570
movq %r13, %rdi
callq 0x5222
movq %r13, %rdi
callq 0x2570
incq %r12
addq $0x10, %rbp
cmpq 0x8(%rbx), %r12
jb 0x4fd2
movq 0x10(%rsp), %rdi
callq 0xa915
movl $0x7, (%rbx)
movl $0x1, %eax
jmp 0x504b
testq %rbp, %rbp
je 0x5031
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xa741
testl %eax, %eax
je 0x5049
movq %rbp, %rdi
callq 0x2570
movq %r13, %rdi
callq 0x5222
movq %r13, %rdi
callq 0x2570
xorl %eax, %eax
testl %eax, %eax
je 0x4f4a
cmpl $0x3, %eax
jne 0x5213
movq 0x10(%rsp), %rdi
callq 0xa871
jmp 0x5213
movl $0x0, (%rbx)
jmp 0x5213
movl $0x1, (%rbx)
jmp 0x5213
movl $0x5, (%rbx)
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x8(%rbx)
jmp 0x5213
movl $0x3, (%rbx)
leaq 0x8(%rsp), %rax
movq $0x8, (%rax)
leaq 0x8(%rbx), %r15
movq $0x0, 0x8(%rbx)
movl $0x100, %edi            # imm = 0x100
callq 0xb1ac
leaq 0x10(%rbx), %r12
movq %rax, 0x10(%rbx)
leaq 0x18(%rsp), %rbp
movq $0x0, 0x18(%rsp)
movl $0x20, %ecx
movq %r12, %rdi
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
callq 0x4c08
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x4e41
movl (%r13), %eax
cmpl $0x7, %eax
je 0x5139
cmpl $0x8, %eax
jne 0x50cc
decq (%r15)
jmp 0x5213
movl $0x4, (%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rbx)
jmp 0x5213
movl $0x6, (%rbx)
cmpl $0x0, 0x38(%rsp)
setne 0x8(%rbx)
jmp 0x5213
movq 0x18(%rsp), %rdi
callq 0x2570
cmpq $0x0, (%r15)
je 0x5167
xorl %r14d, %r14d
xorl %r13d, %r13d
movq (%r12), %rdi
addq %r14, %rdi
callq 0x5222
incq %r13
addq $0x20, %r14
cmpq (%r15), %r13
jb 0x514f
movq 0x10(%rbx), %rdi
callq 0x2570
jmp 0x520d
callq 0x2320
movl (%rax), %edi
callq 0x2260
movq %rax, %r9
jmp 0x51e7
leaq 0x7301(%rip), %r9       # 0xc48e
jmp 0x51e7
leaq 0x736a(%rip), %r9       # 0xc500
jmp 0x51e7
leaq 0x72c9(%rip), %r9       # 0xc468
jmp 0x51e7
leaq 0x72ce(%rip), %r9       # 0xc476
jmp 0x51e7
leaq 0x730f(%rip), %r9       # 0xc4c0
jmp 0x51e7
leaq 0x7298(%rip), %r9       # 0xc452
jmp 0x51e7
leaq 0x72da(%rip), %r9       # 0xc49d
jmp 0x51e7
leaq 0x72e5(%rip), %r9       # 0xc4b1
jmp 0x51e7
leaq 0x733a(%rip), %r9       # 0xc50f
jmp 0x51e7
leaq 0x72fa(%rip), %r9       # 0xc4d8
jmp 0x51e7
leaq 0x733d(%rip), %r9       # 0xc524
movq 0x2000(%r12), %rcx
movq 0x2018(%r12), %rdi
leaq 0x7334(%rip), %rdx      # 0xc532
movl $0x4, %esi
movl %ebp, %r8d
xorl %eax, %eax
callq 0x6e97
movl $0x7, (%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq