// File: Alcaro[P]bridges/arlib/json.cpp
// Function: void JSON::serialize<true>(jsonwriter&) const
void JSON::serialize(jsonwriter& w) const
{
	switch (m_action)
	{
	case jsonparser::unset:
	case jsonparser::error:
	case jsonparser::jnull:
		w.null();
		break;
	case jsonparser::jtrue:
		w.boolean(true);
		break;
	case jsonparser::jfalse:
		w.boolean(false);
		break;
	case jsonparser::str:
		w.str(m_str);
		break;
	case jsonparser::num:
		if (m_num == (int)m_num) w.num((int)m_num);
		else w.num(m_num);
		break;
	case jsonparser::enter_list:
		w.list_enter();
		for (const JSON& j : m_chld_list) j.serialize<sort>(w);
		w.list_exit();
		break;
	case jsonparser::enter_map:
		w.map_enter();
		if (sort)
		{
			array<const map<string,JSON>::node*> items;
			for (const map<string,JSON>::node& e : m_chld_map)
			{
				items.append(&e);
			}
			items.ssort([](const map<string,JSON>::node* a, const map<string,JSON>::node* b) { return string::less(a->key, b->key); });
			for (const map<string,JSON>::node* e : items)
			{
				w.map_key(e->key);
				e->value.serialize<sort>(w);
			}
		}
		else
		{
			for (auto& e : m_chld_map)
			{
				w.map_key(e.key);
				e.value.serialize<sort>(w);
			}
		}
		w.map_exit();
		break;
	default: abort(); // unreachable
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl (%rax), %eax
movq %rax, -0xc8(%rbp)
subq $0xb, %rax
ja 0x2b53b
movq -0xc8(%rbp), %rax
leaq 0x387c1(%rip), %rcx     # 0x63a80
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
callq 0x2c450
jmp 0x2b540
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2c480
jmp 0x2b540
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2c480
jmp 0x2b540
movq -0xd0(%rbp), %rax
movq -0x10(%rbp), %rdi
movq 0x8(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2c4d0
jmp 0x2b540
movq -0xd0(%rbp), %rax
movsd 0x18(%rax), %xmm0
cvttsd2si 0x18(%rax), %eax
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2b35a
jp 0x2b35a
movq -0xd0(%rbp), %rax
movq -0x10(%rbp), %rdi
cvttsd2si 0x18(%rax), %esi
callq 0x2c550
jmp 0x2b36f
movq -0xd0(%rbp), %rax
movq -0x10(%rbp), %rdi
movsd 0x18(%rax), %xmm0
callq 0x2c5b0
jmp 0x2b540
movq -0x10(%rbp), %rdi
callq 0x2c610
movq -0xd0(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2c660
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2c680
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x2b3d3
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2b280
movq -0x30(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x30(%rbp)
jmp 0x2b3a6
movq -0x10(%rbp), %rdi
callq 0x2c6a0
jmp 0x2b540
movq -0x10(%rbp), %rdi
callq 0x2c6e0
leaq -0x50(%rbp), %rdi
callq 0x2cc20
movq -0xd0(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2c720
movq %rax, -0x68(%rbp)
movq %rdx, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2c760
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2c7a0
testb $0x1, %al
jne 0x2b437
jmp 0x2b46a
leaq -0x68(%rbp), %rdi
callq 0x2c7d0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x2cc40
leaq -0x68(%rbp), %rdi
callq 0x2c860
jmp 0x2b424
leaq -0x50(%rbp), %rdi
leaq -0x89(%rbp), %rsi
callq 0x2cc70
leaq -0x50(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x2ce50
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x2ce70
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0xa8(%rbp), %rax
je 0x2b527
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
movq -0xb0(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0xc0(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
callq 0x2c7f0
movq -0xb0(%rbp), %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rsi
callq 0x2b280
movq -0xa0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xa0(%rbp)
jmp 0x2b4ab
leaq -0x50(%rbp), %rdi
callq 0x2ce90
movq -0x10(%rbp), %rdi
callq 0x2c890
jmp 0x2b540
callq 0x4180
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)