// File: Nallantli[P]Rossa/main/rossa/node/node.cpp
// Function: InsNode::fold(std::vector<std::pair<std::vector<unsigned long long, std::allocator<unsigned long long>>, symbol_t>, std::allocator<std::pair<std::vector<unsigned long long, std::allocator<unsigned long long>>, symbol_t>>> const&) const
const ptr_node_t InsNode::fold(const std::vector<std::pair<std::vector<hash_ull>, symbol_t>> &consts) const
{
	if (arg->getType() == ID_NODE)
	{
		std::vector<hash_ull> apath;
		auto curr = callee;
		while (true)
		{
			if (curr->getType() == ID_NODE)
			{
				apath.push_back(reinterpret_cast<IDNode *>(curr.get())->getKey());
				break;
			}
			else if (curr->getType() == INS_NODE)
			{
				InsNode *inn = reinterpret_cast<InsNode *>(curr.get());
				if (inn->getArg()->getType() == ID_NODE)
				{
					apath.push_back(reinterpret_cast<IDNode *>(inn->getArg().get())->getKey());
					curr = inn->getCallee();
				}
				else
				{
					return std::make_shared<InsNode>(path, callee->fold(consts), arg->fold(consts), token);
				}
			}
			else
			{
				return std::make_shared<InsNode>(path, callee->fold(consts), arg->fold(consts), token);
			}
		}
		std::vector<hash_ull> fpath;
		while (!apath.empty())
		{
			fpath.push_back(apath.back());
			apath.pop_back();
		}
		fpath.push_back(reinterpret_cast<IDNode *>(arg.get())->getKey());

		for (auto &c : consts)
		{
			std::vector<hash_ull> tpath;
			for (auto &p : path)
				tpath.push_back(p.id);
			while (true)
			{
				auto temp = tpath;
				for (auto &p : fpath)
					temp.push_back(p);

				if (c.first == temp)
					return std::make_shared<ContainerNode>(path, c.second, token);
				if (tpath.empty())
					break;
				tpath.pop_back();
			}
		}
	}

	return std::make_shared<InsNode>(path, callee->fold(consts), arg->fold(consts), token);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x208(%rbp)
movq %rdi, %rax
movq %rax, -0x200(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
addq $0xb8, %rdi
callq 0x2d030
movq %rax, %rdi
callq 0xd2b20
cmpl $0xc, %eax
jne 0xdf918
leaq -0x30(%rbp), %rdi
callq 0x2ccf0
movq -0x1f8(%rbp), %rsi
addq $0xa8, %rsi
leaq -0x40(%rbp), %rdi
callq 0x57520
jmp 0xdf1d2
leaq -0x40(%rbp), %rdi
callq 0x2d030
movq %rax, %rdi
callq 0xd2b20
cmpl $0xc, %eax
jne 0xdf222
leaq -0x40(%rbp), %rdi
callq 0x327c0
movq %rax, %rdi
callq 0xd3d80
movq %rax, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x58120
jmp 0xdf20c
jmp 0xdf54b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdf901
leaq -0x40(%rbp), %rdi
callq 0x2d030
movq %rax, %rdi
callq 0xd2b20
cmpl $0x5, %eax
jne 0xdf433
leaq -0x40(%rbp), %rdi
callq 0x327c0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0xdee90
leaq -0x70(%rbp), %rdi
callq 0x2d030
movq %rax, %rdi
callq 0xd2b20
movl %eax, -0x20c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x24b20
movl -0x20c(%rbp), %eax
cmpl $0xc, %eax
jne 0xdf31d
movq -0x60(%rbp), %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0xdee90
movq -0x218(%rbp), %rdi
callq 0x327c0
movq %rax, %rdi
callq 0xd3d80
movq %rax, -0x78(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x58120
jmp 0xdf2c3
leaq -0x88(%rbp), %rdi
callq 0x24b20
movq -0x60(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xdee50
leaq -0x40(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x58f60
leaq -0x98(%rbp), %rdi
callq 0x24b20
jmp 0xdf42e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x24b20
jmp 0xdf901
movq -0x1f8(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x220(%rbp)
addq $0xa8, %rdi
callq 0x2d030
movq %rax, %rsi
movq -0x18(%rbp), %rdx
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq -0xb8(%rbp), %rdi
callq *%rax
jmp 0xdf357
movq -0x1f8(%rbp), %rdi
addq $0xb8, %rdi
callq 0x2d030
movq %rax, %rsi
movq -0x18(%rbp), %rdx
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq -0xc8(%rbp), %rdi
callq *%rax
jmp 0xdf383
movq -0x220(%rbp), %rsi
movq -0x1f8(%rbp), %r8
addq $0x28, %r8
leaq -0xa8(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0xe9330
jmp 0xdf3b1
movq -0x208(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x64110
leaq -0xa8(%rbp), %rdi
callq 0x57940
leaq -0xc8(%rbp), %rdi
callq 0x24b20
leaq -0xb8(%rbp), %rdi
callq 0x24b20
movl $0x1, -0xcc(%rbp)
jmp 0xdf8d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdf41d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x24b20
leaq -0xb8(%rbp), %rdi
callq 0x24b20
jmp 0xdf901
jmp 0xdf544
movq -0x1f8(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x228(%rbp)
addq $0xa8, %rdi
callq 0x2d030
movq %rax, %rsi
movq -0x18(%rbp), %rdx
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq -0xf0(%rbp), %rdi
callq *%rax
jmp 0xdf46d
movq -0x1f8(%rbp), %rdi
addq $0xb8, %rdi
callq 0x2d030
movq %rax, %rsi
movq -0x18(%rbp), %rdx
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq -0x100(%rbp), %rdi
callq *%rax
jmp 0xdf499
movq -0x228(%rbp), %rsi
movq -0x1f8(%rbp), %r8
addq $0x28, %r8
leaq -0xe0(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
leaq -0x100(%rbp), %rcx
callq 0xe9330
jmp 0xdf4c7
movq -0x208(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x64110
leaq -0xe0(%rbp), %rdi
callq 0x57940
leaq -0x100(%rbp), %rdi
callq 0x24b20
leaq -0xf0(%rbp), %rdi
callq 0x24b20
movl $0x1, -0xcc(%rbp)
jmp 0xdf8d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdf533
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x24b20
leaq -0xf0(%rbp), %rdi
callq 0x24b20
jmp 0xdf901
jmp 0xdf546
jmp 0xdf1d0
leaq -0x118(%rbp), %rdi
callq 0x2ccf0
leaq -0x30(%rbp), %rdi
callq 0xe5ba0
xorb $-0x1, %al
testb $0x1, %al
jne 0xdf568
jmp 0xdf59e
leaq -0x30(%rbp), %rdi
callq 0x67f60
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x5a2f0
jmp 0xdf582
leaq -0x30(%rbp), %rdi
callq 0xe5be0
jmp 0xdf557
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdf8f5
movq -0x1f8(%rbp), %rdi
addq $0xb8, %rdi
callq 0x327c0
movq %rax, %rdi
callq 0xd3d80
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x58120
jmp 0xdf5d5
movq -0x18(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rdi
callq 0xe5a60
movq %rax, -0x130(%rbp)
movq -0x128(%rbp), %rdi
callq 0xe5a90
movq %rax, -0x138(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xe5ac0
testb $0x1, %al
jne 0xdf622
jmp 0xdf8ba
leaq -0x130(%rbp), %rdi
callq 0xe5b00
movq %rax, -0x140(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x2ccf0
movq -0x1f8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rdi
callq 0xe4e60
movq %rax, -0x168(%rbp)
movq -0x160(%rbp), %rdi
callq 0xe4e90
movq %rax, -0x170(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0xe4ec0
testb $0x1, %al
jne 0xdf692
jmp 0xdf6db
leaq -0x168(%rbp), %rdi
callq 0xe4f00
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0x5a2f0
jmp 0xdf6ba
jmp 0xdf6bc
leaq -0x168(%rbp), %rdi
callq 0xe4fa0
jmp 0xdf679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdf8ac
jmp 0xdf6dd
jmp 0xdf6df
leaq -0x190(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x2e3e0
jmp 0xdf6f4
leaq -0x118(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rdi
callq 0x2d1b0
movq %rax, -0x1a0(%rbp)
movq -0x198(%rbp), %rdi
callq 0x2d1e0
movq %rax, -0x1a8(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x2d210
testb $0x1, %al
jne 0xdf741
jmp 0xdf796
leaq -0x1a0(%rbp), %rdi
callq 0x2d250
movq %rax, -0x1b0(%rbp)
movq -0x1b0(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x5a2f0
jmp 0xdf769
jmp 0xdf76b
leaq -0x1a0(%rbp), %rdi
callq 0x2d2c0
jmp 0xdf728
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x2ce90
jmp 0xdf8ac
movq -0x140(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xe5b20
movb %al, -0x229(%rbp)
jmp 0xdf7b1
movb -0x229(%rbp), %al
testb $0x1, %al
jne 0xdf7bd
jmp 0xdf813
movq -0x1f8(%rbp), %rcx
movq %rcx, %rsi
addq $0x8, %rsi
movq -0x140(%rbp), %rdx
addq $0x18, %rdx
addq $0x28, %rcx
leaq -0x1c0(%rbp), %rdi
callq 0xe5180
jmp 0xdf7e8
movq -0x208(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x571a0
leaq -0x1c0(%rbp), %rdi
callq 0x571d0
movl $0x1, -0xcc(%rbp)
jmp 0xdf847
leaq -0x158(%rbp), %rdi
callq 0xe5ba0
testb $0x1, %al
jne 0xdf825
jmp 0xdf831
movl $0xb, -0xcc(%rbp)
jmp 0xdf847
leaq -0x158(%rbp), %rdi
callq 0xe5be0
movl $0x0, -0xcc(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x2ce90
movl -0xcc(%rbp), %eax
movl %eax, -0x230(%rbp)
testl %eax, %eax
je 0xdf872
jmp 0xdf865
movl -0x230(%rbp), %eax
subl $0xb, %eax
je 0xdf877
jmp 0xdf881
jmp 0xdf6dd
movl $0x0, -0xcc(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x2ce90
movl -0xcc(%rbp), %eax
testl %eax, %eax
jne 0xdf8c4
jmp 0xdf899
jmp 0xdf89b
leaq -0x130(%rbp), %rdi
callq 0xe5c10
jmp 0xdf606
leaq -0x158(%rbp), %rdi
callq 0x2ce90
jmp 0xdf8f5
movl $0x0, -0xcc(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x2ce90
leaq -0x40(%rbp), %rdi
callq 0x24b20
leaq -0x30(%rbp), %rdi
callq 0x2ce90
movl -0xcc(%rbp), %eax
testl %eax, %eax
je 0xdf8f3
jmp 0xdf8ee
jmp 0xdfa17
jmp 0xdf918
leaq -0x118(%rbp), %rdi
callq 0x2ce90
leaq -0x40(%rbp), %rdi
callq 0x24b20
leaq -0x30(%rbp), %rdi
callq 0x2ce90
jmp 0xdfa27
movq -0x1f8(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x238(%rbp)
addq $0xa8, %rdi
callq 0x2d030
movq %rax, %rsi
movq -0x18(%rbp), %rdx
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq -0x1e0(%rbp), %rdi
callq *%rax
movq -0x1f8(%rbp), %rdi
addq $0xb8, %rdi
callq 0x2d030
movq %rax, %rsi
movq -0x18(%rbp), %rdx
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq -0x1f0(%rbp), %rdi
callq *%rax
jmp 0xdf97c
movq -0x238(%rbp), %rsi
movq -0x1f8(%rbp), %r8
addq $0x28, %r8
leaq -0x1d0(%rbp), %rdi
leaq -0x1e0(%rbp), %rdx
leaq -0x1f0(%rbp), %rcx
callq 0xe9330
jmp 0xdf9aa
movq -0x208(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x64110
leaq -0x1d0(%rbp), %rdi
callq 0x57940
leaq -0x1f0(%rbp), %rdi
callq 0x24b20
leaq -0x1e0(%rbp), %rdi
callq 0x24b20
jmp 0xdfa17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xdfa09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x24b20
leaq -0x1e0(%rbp), %rdi
callq 0x24b20
jmp 0xdfa27
movq -0x200(%rbp), %rax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x119c0