// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq 0xb8(%rsi), %rax
cmpl $0xc, 0x20(%rax)
jne 0x55622
movq %r15, 0x48(%rsp)
movq %rbx, 0x38(%rsp)
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq %r14, 0x40(%rsp)
leaq 0xa8(%r14), %rsi
leaq 0x68(%rsp), %rdi
callq 0x2f676
movq %rsp, %r12
leaq 0x20(%rsp), %r14
movq 0x68(%rsp), %rbp
movl 0x20(%rbp), %eax
cmpl $0x5, %eax
jne 0x55330
leaq 0xb8(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x2f676
movq (%rsp), %rax
movl 0x20(%rax), %r15d
leaq 0x8(%rsp), %rdi
callq 0x1d786
cmpl $0xc, %r15d
jne 0x55557
movq %r12, %rdi
movq %r13, %rsi
callq 0x2f676
movq (%rsp), %rax
movq 0xa8(%rax), %rax
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x31afa
leaq 0x8(%rsp), %rdi
callq 0x1d786
addq $0xa8, %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2f676
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x2fc8e
leaq 0x8(%rsp), %rdi
callq 0x1d786
jmp 0x55293
cmpl $0xc, %eax
jne 0x5538c
movq 0xa8(%rbp), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
leaq 0x50(%rsp), %rdi
callq 0x31afa
movq 0x40(%rsp), %r14
movq 0x48(%rsp), %r15
xorps %xmm0, %xmm0
movq %rsp, %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq 0x58(%rsp), %rsi
cmpq %rsi, 0x50(%rsp)
je 0x553e7
addq $-0x8, %rsi
movq %rbx, %rdi
callq 0x2f2f0
movq 0x58(%rsp), %rsi
addq $-0x8, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x55369
movq 0x40(%rsp), %r14
movq 0xa8(%r14), %rsi
movq (%rsi), %rax
leaq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rbx
movq %rbx, %rdx
callq *0x18(%rax)
movq 0xb8(%r14), %rsi
movq (%rsi), %rax
leaq 0x78(%rsp), %rdi
movq %rbx, %rdx
callq *0x18(%rax)
movq 0x38(%rsp), %rbx
leaq 0x8(%r14), %rsi
addq $0x28, %r14
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
leaq 0x78(%rsp), %rcx
movq %r14, %r8
callq 0x59608
jmp 0x555ad
movq 0xb8(%r14), %rax
movq 0xa8(%rax), %rax
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movq %rsp, %rdi
callq 0x31afa
movq (%r15), %r12
movq 0x8(%r15), %r13
leaq 0x8(%r14), %rax
movq %rax, 0xb0(%rsp)
leaq 0x28(%r14), %rax
movq %rax, 0xa8(%rsp)
leaq 0x78(%rsp), %rbx
leaq 0x20(%rsp), %r15
cmpq %r13, %r12
je 0x555f7
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rbp
cmpq %rbp, %r14
je 0x55479
movq %r15, %rdi
movq %r14, %rsi
callq 0x2f2f0
addq $0x20, %r14
jmp 0x55452
addq $-0x8, %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
callq 0x1f5c4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1f576
movq (%rsp), %r14
movq 0x8(%rsp), %rbp
cmpq %rbp, %r14
je 0x554a3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2f2f0
addq $0x8, %r14
jmp 0x5548d
movq %r12, %rdi
movq %rbx, %rsi
callq 0x58b34
movl %eax, %r14d
testb %al, %al
jne 0x554c3
movq 0x28(%rsp), %rax
cmpq %rax, 0x20(%rsp)
jne 0x55468
jmp 0x55514
leaq 0x18(%r12), %rdx
leaq 0x90(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rcx
callq 0x5898a
movaps 0x90(%rsp), %xmm0
andq $0x0, 0x98(%rsp)
movq 0x38(%rsp), %rax
movups %xmm0, (%rax)
andq $0x0, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x1d786
movq %rbx, %rdi
callq 0x1f5c4
movq %r15, %rdi
callq 0x1f5c4
addq $0x28, %r12
testb %r14b, %r14b
je 0x5542e
movq %rsp, %rdi
callq 0x1f5c4
leaq 0x70(%rsp), %rdi
callq 0x1d786
leaq 0x50(%rsp), %rdi
callq 0x1f5c4
movq 0x38(%rsp), %rbx
jmp 0x55695
movq 0x40(%rsp), %r14
movq 0xa8(%r14), %rsi
movq (%rsi), %rax
leaq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rbx
movq %rbx, %rdx
callq *0x18(%rax)
movq 0xb8(%r14), %rsi
movq (%rsi), %rax
leaq 0x78(%rsp), %rdi
movq %rbx, %rdx
callq *0x18(%rax)
movq 0x38(%rsp), %rbx
leaq 0x8(%r14), %rsi
addq $0x28, %r14
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
leaq 0x78(%rsp), %rcx
movq %r14, %r8
callq 0x59608
leaq 0x8(%rsp), %rdi
movaps -0x8(%rdi), %xmm0
andq $0x0, (%rdi)
movups %xmm0, (%rbx)
andq $0x0, -0x8(%rdi)
callq 0x1d786
leaq 0x80(%rsp), %rdi
callq 0x1d786
leaq 0x28(%rsp), %rdi
callq 0x1d786
leaq 0x70(%rsp), %rdi
callq 0x1d786
leaq 0x50(%rsp), %rdi
callq 0x1f5c4
jmp 0x55695
movq %rsp, %rdi
callq 0x1f5c4
leaq 0x70(%rsp), %rdi
callq 0x1d786
leaq 0x50(%rsp), %rdi
callq 0x1f5c4
movq 0x38(%rsp), %rbx
movq 0x40(%rsp), %r14
movq 0x48(%rsp), %r15
movq 0xa8(%r14), %rsi
movq (%rsi), %rax
movq %rsp, %rdi
movq %r15, %rdx
callq *0x18(%rax)
movq 0xb8(%r14), %rsi
movq (%rsi), %rax
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
callq *0x18(%rax)
leaq 0x8(%r14), %rsi
addq $0x28, %r14
leaq 0x50(%rsp), %rdi
movq %rsp, %rdx
leaq 0x20(%rsp), %rcx
movq %r14, %r8
callq 0x59608
leaq 0x58(%rsp), %rdi
movaps -0x8(%rdi), %xmm0
andq $0x0, (%rdi)
movups %xmm0, (%rbx)
andq $0x0, -0x8(%rdi)
callq 0x1d786
leaq 0x28(%rsp), %rdi
callq 0x1d786
leaq 0x8(%rsp), %rdi
callq 0x1d786
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x556b2
jmp 0x556c4
jmp 0x556d0
jmp 0x55704
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x1d786
jmp 0x556c7
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x556fd
jmp 0x556d0
movq %rax, %rbx
jmp 0x55731
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x1d786
jmp 0x556e7
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1d786
jmp 0x55745
jmp 0x55712
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1d786
jmp 0x55731
movq %rax, %rbx
jmp 0x55729
jmp 0x55712
jmp 0x5570d
movq %rax, %rbx
jmp 0x5571f
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x1f5c4
leaq 0x20(%rsp), %rdi
callq 0x1f5c4
movq %rsp, %rdi
callq 0x1f5c4
leaq 0x70(%rsp), %rdi
callq 0x1d786
leaq 0x50(%rsp), %rdi
callq 0x1f5c4
movq %rbx, %rdi
callq 0x106f0
nop