// File: Alcaro[P]bridges/arlib/json.cpp
// Function: JSON::construct(jsonparser&, jsonparser::event&, bool*, unsigned long)
void JSON::construct(jsonparser& p, jsonparser::event& ev, bool* ok, size_t maxdepth)
{
	m_action = ev.action;
	if(0);
	else if (ev.action == jsonparser::str) m_str = ev.str;
	else if (ev.action == jsonparser::num) fromstring(ev.str, m_num);
	else if (ev.action == jsonparser::error) *ok = false;
	else if (maxdepth == 0)
	{
		*ok = false;
		m_action = jsonparser::error;
		if (ev.action == jsonparser::enter_list || ev.action == jsonparser::enter_map)
		{
			// it would be faster to reset the jsonparser somehow,
			// but performance on hostile inputs isn't really a priority
			size_t xdepth = 1;
			while (xdepth)
			{
				jsonparser::event next = p.next();
				if (next.action == jsonparser::enter_list) xdepth++;
				if (next.action == jsonparser::enter_map) xdepth++;
				if (next.action == jsonparser::exit_list) xdepth--;
				if (next.action == jsonparser::exit_map) xdepth--;
			}
		}
		return;
	}
	else if (ev.action == jsonparser::enter_list)
	{
		while (true)
		{
			jsonparser::event next = p.next();
			if (next.action == jsonparser::exit_list) break;
			if (next.action == jsonparser::error) *ok = false;
			m_chld_list.append().construct(p, next, ok, maxdepth-1);
		}
	}
	else if (ev.action == jsonparser::enter_map)
	{
		while (true)
		{
			jsonparser::event next = p.next();
			if (next.action == jsonparser::exit_map) break;
			if (next.action == jsonparser::map_key)
			{
				jsonparser::event ev = p.next();
				m_chld_map.insert(next.str).construct(p, ev, ok, maxdepth-1);
			}
			if (next.action == jsonparser::error) *ok = false;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x40(%rbp)
movq %rsi, -0x48(%rbp)
movq %rdx, -0x50(%rbp)
movq %rcx, -0x58(%rbp)
movq %r8, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x50(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x2a6cf
movq -0x100(%rbp), %rcx
movq -0x50(%rbp), %rax
addq $0x8, %rax
addq $0x8, %rcx
movq %rcx, -0x20(%rbp)
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0xa370
jmp 0x2a94f
movq -0x50(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x2a709
movq -0x100(%rbp), %rdx
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
addq $0x18, %rdx
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x3dce0
jmp 0x2a94d
movq -0x50(%rbp), %rax
cmpl $0xb, (%rax)
jne 0x2a71e
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
jmp 0x2a94b
cmpq $0x0, -0x60(%rbp)
jne 0x2a7cb
movq -0x100(%rbp), %rax
movq -0x58(%rbp), %rcx
movb $0x0, (%rcx)
movl $0xb, (%rax)
movq -0x50(%rbp), %rax
cmpl $0x6, (%rax)
je 0x2a74f
movq -0x50(%rbp), %rax
cmpl $0x8, (%rax)
jne 0x2a7c6
movq $0x1, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x2a7c4
movq -0x48(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x286a0
cmpl $0x6, -0x90(%rbp)
jne 0x2a783
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
cmpl $0x8, -0x90(%rbp)
jne 0x2a798
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
cmpl $0x7, -0x90(%rbp)
jne 0x2a7ad
movq -0x78(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
cmpl $0xa, -0x90(%rbp)
jne 0x2a7c2
movq -0x78(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x2a757
jmp 0x2a7c6
jmp 0x2a94f
movq -0x50(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x2a837
jmp 0x2a7d6
movq -0x48(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x286a0
cmpl $0x7, -0xa8(%rbp)
jne 0x2a7f1
jmp 0x2a832
cmpl $0xb, -0xa8(%rbp)
jne 0x2a801
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
movq -0x100(%rbp), %rdi
addq $0x20, %rdi
callq 0x2ad70
movq %rax, %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %r8
subq $0x1, %r8
leaq -0xa8(%rbp), %rdx
callq 0x2a650
jmp 0x2a7d6
jmp 0x2a947
movq -0x50(%rbp), %rax
cmpl $0x8, (%rax)
jne 0x2a945
jmp 0x2a846
movq -0x48(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x286a0
cmpl $0xa, -0xc0(%rbp)
jne 0x2a864
jmp 0x2a943
cmpl $0x9, -0xc0(%rbp)
jne 0x2a92e
movq -0x48(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x286a0
movq -0x100(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x108(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xf8(%rbp), %rcx
movq -0xf0(%rbp), %rax
movq %rcx, -0x10(%rbp)
movq %rax, -0x8(%rbp)
leaq -0xe8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x5c00
movq -0x110(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x37020
movq -0x108(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x2ad90
movq %rax, %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %r8
subq $0x1, %r8
leaq -0xd8(%rbp), %rdx
callq 0x2a650
leaq -0xe8(%rbp), %rdi
callq 0x5870
cmpl $0xb, -0xc0(%rbp)
jne 0x2a93e
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
jmp 0x2a846
jmp 0x2a945
jmp 0x2a947
jmp 0x2a949
jmp 0x2a94b
jmp 0x2a94d
jmp 0x2a94f
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)