// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movb $0x0, 0x4(%rsi)
leaq 0x10(%rsp), %rsi
callq 0x5304
testl %eax, %eax
js 0x4bbb
movq 0x10(%rsp), %rax
movq %rax, (%r15)
movl 0x20(%rsp), %eax
cmpq $0x8, %rax
ja 0x4ea0
leaq 0x6839(%rip), %rcx      # 0xb3e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x8, (%rbx)
jmp 0x4ea0
movq %r14, %rdi
callq 0x52cc
movq (%rax), %r12
movl 0x2010(%r12), %ebp
leaq 0x8(%rsp), %rsi
movq %rsp, %r15
movq %r14, %rdi
movq %r15, %rdx
callq 0x52b8
movq 0x28(%rsp), %rax
movq (%r15), %r15
cmpq %r15, %rax
jae 0x4c1a
movq 0x8(%rsp), %rcx
addq %rcx, %rax
addq %rcx, %r15
pushq $0xa
popq %r14
movq %r15, %rdx
subq %rax, %rdx
movq %rax, %rdi
movl %r14d, %esi
callq 0x20d0
testq %rax, %rax
je 0x4c1a
decl %ebp
incq %rax
jmp 0x4bfd
movl 0x20(%rsp), %eax
addl $-0x9, %eax
cmpl $0xb, %eax
ja 0x4e6f
leaq 0x67d3(%rip), %rcx      # 0xb404
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x6843(%rip), %r9       # 0xb484
jmp 0x4e76
movl $0x2, (%rbx)
leaq 0x8(%rbx), %r15
pushq $0x8
popq %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x9e28
andq $0x0, (%rsp)
pushq $0x20
popq %rdi
callq 0xa7d0
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rsp, %rdx
callq 0x4b61
movl (%r13), %eax
movq (%rsp), %rbp
cmpl $0x8, %eax
je 0x4db8
cmpl $0x7, %eax
je 0x4d7d
testq %rbp, %rbp
je 0x4cae
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x9e46
testl %eax, %eax
je 0x4c5f
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4f50
jmp 0x4c5f
andl $0x0, (%rbx)
jmp 0x4ea0
movl $0x1, (%rbx)
jmp 0x4ea0
movl $0x5, (%rbx)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x8(%rbx)
jmp 0x4ea0
movl $0x3, (%rbx)
movq %rsp, %rax
movq $0x8, (%rax)
leaq 0x8(%rbx), %r15
andq $0x0, 0x8(%rbx)
movl $0x100, %edi            # imm = 0x100
callq 0xa7d0
leaq 0x10(%rbx), %r12
movq %rax, 0x10(%rbx)
leaq 0x8(%rsp), %r13
andq $0x0, 0x8(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %rsp, %rdx
pushq $0x20
popq %rcx
callq 0x4954
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x4b61
movl (%rbp), %eax
cmpl $0x7, %eax
je 0x4dd0
cmpl $0x8, %eax
jne 0x4d14
decq (%r15)
jmp 0x4ea0
movl $0x4, (%rbx)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rbx)
jmp 0x4ea0
movl $0x6, (%rbx)
cmpl $0x0, 0x28(%rsp)
setne 0x8(%rbx)
jmp 0x4ea0
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4f50
xorl %r14d, %r14d
cmpq (%r15), %r14
jae 0x4dab
movq 0x18(%rbx), %rax
movq -0x8(%rax,%r12), %rdi
movq (%rax,%r12), %rsi
callq 0x4f50
incq %r14
addq $0x10, %r12
jmp 0x4d8b
movq %r15, %rdi
callq 0x9ff4
jmp 0x4e9a
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4f50
movq %r15, %rdi
callq 0x9f50
jmp 0x4ea0
movq 0x8(%rsp), %rdi
callq 0x2580
xorl %r14d, %r14d
xorl %r13d, %r13d
movq (%r12), %rdi
cmpq (%r15), %r13
jae 0x4dfa
addq %r14, %rdi
callq 0x4eaf
incq %r13
addq $0x20, %r14
jmp 0x4de0
callq 0x2580
jmp 0x4e9a
callq 0x2330
movl (%rax), %edi
callq 0x2260
movq %rax, %r9
jmp 0x4e76
leaq 0x66b2(%rip), %r9       # 0xb4ce
jmp 0x4e76
leaq 0x671b(%rip), %r9       # 0xb540
jmp 0x4e76
leaq 0x667a(%rip), %r9       # 0xb4a8
jmp 0x4e76
leaq 0x667f(%rip), %r9       # 0xb4b6
jmp 0x4e76
leaq 0x66c0(%rip), %r9       # 0xb500
jmp 0x4e76
leaq 0x6649(%rip), %r9       # 0xb492
jmp 0x4e76
leaq 0x668b(%rip), %r9       # 0xb4dd
jmp 0x4e76
leaq 0x6696(%rip), %r9       # 0xb4f1
jmp 0x4e76
leaq 0x66eb(%rip), %r9       # 0xb54f
jmp 0x4e76
leaq 0x66ab(%rip), %r9       # 0xb518
jmp 0x4e76
leaq 0x66ee(%rip), %r9       # 0xb564
movq 0x2000(%r12), %rcx
movq 0x2018(%r12), %rdi
leaq 0x66e5(%rip), %rdx      # 0xb572
pushq $0x4
popq %rsi
movl %ebp, %r8d
xorl %eax, %eax
callq 0x691c
movl $0x7, (%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq