// File: /workspace/github_cpp_makefile_star2_O2/Nallantli[P]Rossa/main/rossa/node_parser/node_parser.cpp
// Function: node_parser_t::parseCallNode(std::vector<node_scope_t, std::allocator<node_scope_t>>*, std::shared_ptr<Node> const&)
ptr_node_t node_parser_t::parseCallNode(std::vector<node_scope_t> *scopes, const ptr_node_t &a)
{
	auto marker = tokens.at(index - 2);
	nextToken();
	std::vector<ptr_node_t> args;
	int i = 0;
	while (currentToken.type != NULL_TOK && currentToken.type != ')')
	{
		if (i > 0)
		{
			if (currentToken.type != ',')
				return logErrorN(util::format(_EXPECTED_ERROR_, {","}), currentToken);
			nextToken();
		}
		i++;
		if (auto b = parseEquNode(scopes))
			args.push_back(b);
		else
			return logErrorN(_EXPECTED_FUNCTION_PARAM_, currentToken);
		if (currentToken.type == NULL_TOK)
			return logErrorN(util::format(_EXPECTED_ERROR_, {")"}), currentToken);
	}

	nextToken();

	ptr_node_t ret;
	if (a->getType() == Node::type_t::INS_NODE)
	{
		auto a_a = reinterpret_cast<InsNode *>(a.get())->getCallee();
		auto a_b = reinterpret_cast<InsNode *>(a.get())->getArg();
		if (a_b->getType() == Node::type_t::BID_NODE)
		{
			auto nkey = reinterpret_cast<BIDNode *>(a_b.get());
			std::string key = nkey->getKey();
			/*if (!args.empty())
				return logErrorN("Built in functions take a single argument", currentToken);*/

			if (key == KEYWORD_LENGTH)
			{
				ret = std::make_shared<CallBuiltNode>(*scopes, TOK_LENGTH, a_a, marker);
			}
			if (key == KEYWORD_ALLOC)
			{
				ret = std::make_shared<CallBuiltNode>(*scopes, TOK_ALLOC, a_a, marker);
			}
			if (key == KEYWORD_PARSE)
			{
				ret = std::make_shared<CallBuiltNode>(*scopes, TOK_PARSE, a_a, marker);
			}
			if (key == KEYWORD_CHAR_N)
			{
				ret = std::make_shared<CallBuiltNode>(*scopes, TOK_CHARN, a_a, marker);
			}
			if (key == KEYWORD_CHAR_S)
			{
				ret = std::make_shared<CallBuiltNode>(*scopes, TOK_CHARS, a_a, marker);
			}

			ret = parseTrailingNode(scopes, ret, true);
		}
		else
		{
			ret = std::make_shared<CallNode>(*scopes, std::make_shared<InsNode>(*scopes, a_a, a_b, currentToken), args, marker);
		}
		return parseTrailingNode(scopes, ret, true);
	}

	ret = std::make_shared<CallNode>(*scopes, a, args, marker);
	return parseTrailingNode(scopes, ret, true);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rcx, 0xa0(%rsp)
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, 0xa8(%rsp)
leaq 0x10(%rsi), %rdi
movl 0x50(%rsi), %esi
addl $-0x2, %esi
callq 0x2e6c6
leaq 0xc8(%rsp), %rdi
movq %rax, %rsi
callq 0x1f71a
movq %rbx, %rdi
callq 0x22e24
xorps %xmm0, %xmm0
leaq 0xb0(%rsp), %rbp
movaps %xmm0, (%rbp)
andq $0x0, 0x10(%rbp)
leaq 0x48(%rsp), %r13
movl 0xd0(%rbx), %eax
xorl %r12d, %r12d
leaq 0x40(%rsp), %r14
testl %eax, %eax
je 0x24d8c
cmpl $0x29, %eax
je 0x24d8c
subl $0x1, %r12d
jb 0x24ce7
cmpl $0x2c, %eax
jne 0x2513d
movq %rbx, %rdi
callq 0x22e24
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x25798
cmpq $0x0, 0x40(%rsp)
je 0x25116
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2e880
movq %r13, %rdi
callq 0x1d786
movl 0xd0(%rbx), %eax
testl %eax, %eax
jne 0x24cbf
leaq 0x51b7f(%rip), %rsi     # 0x768a4
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x1c814
leaq 0x535f6(%rip), %rsi     # 0x78331
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x1c814
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
pushq $0x1
popq %rdx
leaq 0xf(%rsp), %rcx
callq 0x1f298
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x3f724
leaq 0x58(%rbx), %rcx
leaq 0x20(%rsp), %rdx
movq %rbx, %rsi
callq 0x25932
movq %rbx, %rdi
callq 0x22e24
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0xa0(%rsp), %r14
movq (%r14), %rdi
callq 0x4ec06
movq 0xa8(%rsp), %r13
cmpl $0x5, %eax
jne 0x24fe7
movq (%r14), %rsi
leaq 0x68(%rsp), %rdi
callq 0x55074
movq (%r14), %rsi
leaq 0x88(%rsp), %rdi
callq 0x5508a
movq 0x88(%rsp), %rdi
callq 0x4ec06
cmpl $0x19, %eax
jne 0x25047
movq 0x88(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x4fbb2
leaq 0x5155f(%rip), %rsi     # 0x76368
leaq 0x20(%rsp), %rdi
callq 0x1c7a0
testb %al, %al
je 0x24e55
leaq 0x8(%rsp), %rdx
movl $0xffffffe6, (%rdx)     # imm = 0xFFFFFFE6
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rcx
leaq 0xc8(%rsp), %r8
movq %r15, %rsi
callq 0x2e8ac
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x30b54
leaq 0x18(%rsp), %rdi
callq 0x1d786
leaq 0x51734(%rip), %rsi     # 0x76590
leaq 0x20(%rsp), %rdi
callq 0x1c7a0
testb %al, %al
je 0x24ea8
leaq 0x8(%rsp), %rdx
movl $0xffffffda, (%rdx)     # imm = 0xFFFFFFDA
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rcx
leaq 0xc8(%rsp), %r8
movq %r15, %rsi
callq 0x2e8ac
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x30b54
leaq 0x18(%rsp), %rdi
callq 0x1d786
leaq 0x51733(%rip), %rsi     # 0x765e2
leaq 0x20(%rsp), %rdi
callq 0x1c7a0
testb %al, %al
je 0x24efb
leaq 0x8(%rsp), %rdx
movl $0xffffffc7, (%rdx)     # imm = 0xFFFFFFC7
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rcx
leaq 0xc8(%rsp), %r8
movq %r15, %rsi
callq 0x2e8ac
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x30b54
leaq 0x18(%rsp), %rdi
callq 0x1d786
leaq 0x516cf(%rip), %rsi     # 0x765d1
leaq 0x20(%rsp), %rdi
callq 0x1c7a0
testb %al, %al
je 0x24f4e
leaq 0x8(%rsp), %rdx
movl $0xffffffcc, (%rdx)     # imm = 0xFFFFFFCC
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rcx
leaq 0xc8(%rsp), %r8
movq %r15, %rsi
callq 0x2e8ac
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x30b54
leaq 0x18(%rsp), %rdi
callq 0x1d786
leaq 0x51682(%rip), %rsi     # 0x765d7
leaq 0x20(%rsp), %rdi
callq 0x1c7a0
testb %al, %al
je 0x24fa1
leaq 0x8(%rsp), %rdx
movl $0xffffffcb, (%rdx)     # imm = 0xFFFFFFCB
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rcx
leaq 0xc8(%rsp), %r8
movq %r15, %rsi
callq 0x2e8ac
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x30b54
leaq 0x18(%rsp), %rdi
callq 0x1d786
leaq 0x8(%rsp), %r8
movb $0x1, (%r8)
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x24b08
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x30b82
leaq 0x18(%rsp), %rdi
callq 0x1d786
leaq 0x20(%rsp), %rdi
callq 0x101d0
jmp 0x250aa
leaq 0x20(%rsp), %rdi
leaq 0xb0(%rsp), %rcx
leaq 0xc8(%rsp), %r8
movq %r15, %rsi
movq %r14, %rdx
callq 0x2e921
leaq 0x40(%rsp), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x30fc0
leaq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x1d786
movb $0x1, -0x8(%r12)
leaq 0x20(%rsp), %r8
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x24b08
jmp 0x250dd
leaq 0x58(%rbx), %r8
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rdx
leaq 0x88(%rsp), %rcx
movq %r15, %rsi
callq 0x2e8fa
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
leaq 0xc8(%rsp), %r8
movq %r15, %rsi
callq 0x2e8d3
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x30fc0
leaq 0x28(%rsp), %rdi
callq 0x1d786
leaq 0x18(%rsp), %rdi
callq 0x1d786
leaq 0x20(%rsp), %r8
movb $0x1, (%r8)
leaq 0x40(%rsp), %rcx
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x24b08
leaq 0x90(%rsp), %rdi
callq 0x1d786
leaq 0x70(%rsp), %rdi
callq 0x1d786
leaq 0x48(%rsp), %rdi
callq 0x1d786
leaq 0xb0(%rsp), %rdi
callq 0x2e838
leaq 0xc8(%rsp), %rdi
callq 0x1df38
movq %r13, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x51796(%rip), %rsi     # 0x768b3
leaq 0x20(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x1c814
leaq 0x58(%rbx), %rcx
leaq 0x20(%rsp), %rdx
movq %rbx, %rsi
callq 0x25932
leaq 0x51760(%rip), %rsi     # 0x768a4
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x1c814
leaq 0x519aa(%rip), %rsi     # 0x76b04
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x1c814
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
pushq $0x1
popq %rdx
leaq 0xf(%rsp), %rcx
callq 0x1f298
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x3f724
leaq 0x58(%rbx), %rcx
leaq 0x20(%rsp), %rdx
movq %rbx, %rsi
callq 0x25932
jmp 0x251b5
jmp 0x251b5
jmp 0x251b5
jmp 0x251b5
jmp 0x251b5
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x101d0
jmp 0x251e0
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x1d786
jmp 0x251e0
jmp 0x251dd
jmp 0x251dd
jmp 0x25204
jmp 0x25213
jmp 0x251dd
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x1d786
leaq 0x70(%rsp), %rdi
callq 0x1d786
jmp 0x2522a
jmp 0x25227
movq %rax, %rbx
jmp 0x251ed
jmp 0x25227
jmp 0x25227
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x101d0
jmp 0x25216
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x1cea0
jmp 0x2523b
jmp 0x25238
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x2527a
jmp 0x2526f
movq %rax, %rbx
jmp 0x2528c
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x101d0
jmp 0x2524c
jmp 0x25249
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x101d0
jmp 0x2527f
jmp 0x2526f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x101d0
jmp 0x25277
jmp 0x25274
jmp 0x2526f
jmp 0x2526f
movq %rax, %rbx
jmp 0x2527f
movq %rax, %rbx
movq %r13, %rdi
callq 0x1d786
leaq 0xb0(%rsp), %rdi
callq 0x2e838
leaq 0xc8(%rsp), %rdi
callq 0x1df38
movq %rbx, %rdi
callq 0x106f0
nop