// File: /workspace/github_cpp_makefile_star2_O3/RuiDGPires[P]CrimLang/src/generator.cpp
// Function: gc_Tracker::func_call(crl::Node*, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char>>&)
void _gc_Tracker::func_call(crl::Node *node, std::stringstream &stream){
	ASSERT(node->get_child(0)->type == crl::Node::Type::LEAF, "Func declaration must have a type as first token");
	std::string name = get_token(node->get_child(0)).str;

	u32 ret_size = size_of(node->annotation);

	stream << 
		"MVI R1 " << ret_size << "\n" <<
		"SUB RS R1\n"; // ALLOCATE MEMORY FOR RETURN VALUE

	for (u32 i = 1; i <= node->argc; i ++){
		crl::Node *arg = node->get_child(i);
		bool is_mut = arg->annotation == "ref";

		if (is_mut){
			std::string arg_name = get_token(arg->get_child(0)).str;
			if (symb_tracker.has_local(arg_name)){
				stream << "MVI R1 " << symb_tracker.get_local(arg_name).first << "\n" <<
					"MOV R2 RF\n" << 
					"SUB R2 R1\n" <<
					"PSH R2\n";
			}else{
				stream << "MVI R1 " << symb_tracker.get_global(arg_name) << "\n" <<
					"PSH R1\n";
			}
		}else this->expression(arg->get_child(0), stream_funcs);
	}

	stream << "JMP " << name << "\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, -0x60(%rbp)
movq (%rsi), %rax
movq %rsi, %rdi
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0x10, 0x8(%rax)
jne 0x6b15
movq (%r14), %rax
movq %r14, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq %rax, %r15
leaq -0xc0(%rbp), %r13
movq %r13, -0x10(%r13)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %r12
movq %r12, %rdi
callq 0x4d52
movq %r13, %rdx
movl 0x80(%r15), %eax
movl %eax, 0x28(%r12)
movq 0x78(%r15), %rax
movq %rax, 0x20(%r12)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq (%r12), %rax
cmpq %r13, %rax
je 0x66cc
movq %rax, -0x80(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x66d2
movups (%rdx), %xmm0
movups %xmm0, (%rcx)
leaq -0xd0(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0x78(%rbp)
movq %rdx, (%rdi)
movq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
callq 0x191f8
leaq -0x130(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x30(%r14), %rsi
movq 0x38(%r14), %rdx
addq %rsi, %rdx
leaq -0x140(%rbp), %rdi
callq 0x4d52
leaq -0x140(%rbp), %rdi
callq 0x9395
movl %eax, %r15d
movq -0x140(%rbp), %rdi
cmpq %r12, %rdi
je 0x6742
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x3230
addq $0x10, %rbx
leaq 0x14c30(%rip), %rsi     # 0x1b37d
movl $0x7, %edx
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
callq 0x3280
movl %r15d, %esi
movq -0x30(%rbp), %rdi
callq 0x3170
movq %rax, %r15
leaq 0x14d6f(%rip), %rsi     # 0x1b4e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq 0x14d2a(%rip), %rsi     # 0x1b4b2
movl $0xa, %edx
movq %r15, %rdi
callq 0x3280
cmpl $0x0, 0x50(%r14)
je 0x6ab0
movq -0x60(%rbp), %rax
leaq 0x318(%rax), %rcx
movq %rcx, -0x100(%rbp)
leaq -0x40(%rbp), %r12
leaq 0x530(%rax), %rcx
movq %rcx, -0x58(%rbp)
addq $0x560, %rax            # imm = 0x560
movq %rax, -0xf8(%rbp)
movl $0x1, %r15d
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0x18(%rax)
movq %rax, %r13
movq %rax, %rdi
addq $0x30, %rdi
leaq 0x14d2f(%rip), %rsi     # 0x1b520
callq 0x30a0
testl %eax, %eax
je 0x681e
movq (%r13), %rax
movq %r13, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq -0x60(%rbp), %rdi
movq %rax, %rsi
movq -0x100(%rbp), %rdx
callq 0x8c5c
jmp 0x6aa3
movq %r12, %rbx
movq (%r13), %rax
movq %r13, %rdi
xorl %esi, %esi
callq *0x18(%rax)
leaq -0xc0(%rbp), %r12
movq %rax, %r13
movq %r12, -0xd0(%rbp)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x4d52
movl 0x80(%r13), %eax
leaq -0xb0(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq 0x78(%r13), %rax
movq %rax, (%rcx)
movq %rbx, -0x50(%rbp)
movq -0xd0(%rbp), %rax
cmpq %r12, %rax
je 0x688e
movq %rax, -0x50(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x6896
movups (%r12), %xmm0
movups %xmm0, (%rbx)
movq -0xc8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %r12, -0xd0(%rbp)
movq $0x0, -0xc8(%rbp)
movb $0x0, -0xc0(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x191f8
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
movq %rbx, %r12
callq 0x4d52
movq -0x58(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xde60
movl %eax, %r13d
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x6923
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x3230
testb %r13b, %r13b
je 0x69ed
movl $0x7, %edx
movq -0x30(%rbp), %rdi
leaq 0x14a41(%rip), %rsi     # 0x1b37d
callq 0x3280
leaq -0x110(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x120(%rbp), %r13
movq %r13, %rdi
callq 0x4d52
movq -0xf8(%rbp), %rdi
movq %r13, %rsi
callq 0xe8ec
movq (%rax), %rax
movl 0x10(%rax), %esi
movq -0x30(%rbp), %rdi
callq 0x3170
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x14b4a(%rip), %rsi     # 0x1b4e3
callq 0x3280
movl $0xa, %edx
movq %r13, %rdi
leaq 0x14b77(%rip), %rsi     # 0x1b524
callq 0x3280
movl $0xa, %edx
movq %r13, %rdi
leaq 0x14b6e(%rip), %rsi     # 0x1b52f
callq 0x3280
movl $0x7, %edx
movq %r13, %rdi
leaq 0x14b65(%rip), %rsi     # 0x1b53a
callq 0x3280
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rcx
jmp 0x6a7b
movl $0x7, %edx
movq -0x30(%rbp), %rdi
leaq 0x14980(%rip), %rsi     # 0x1b37d
callq 0x3280
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x4d52
movq -0x58(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xea36
movl (%rax), %esi
movq -0x30(%rbp), %rdi
callq 0x3170
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x14a8f(%rip), %rsi     # 0x1b4e3
callq 0x3280
movl $0x7, %edx
movq %r13, %rdi
leaq 0x14ada(%rip), %rsi     # 0x1b542
callq 0x3280
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rcx
movq %rcx, %rax
cmpq %rcx, %rdi
je 0x6a8e
movq (%rax), %rsi
incq %rsi
callq 0x3230
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x6aa3
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3230
incl %r15d
cmpl 0x50(%r14), %r15d
jbe 0x67d4
leaq 0x14a5e(%rip), %rsi     # 0x1b515
movl $0x4, %edx
movq -0x30(%rbp), %rdi
callq 0x3280
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x3280
leaq 0x14a06(%rip), %rsi     # 0x1b4e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x6b03
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3230
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0x150(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x14892(%rip), %rsi     # 0x1b3c6
leaq 0x148bb(%rip), %rdx     # 0x1b3f6
leaq -0x160(%rbp), %rdi
callq 0x4336
movb $0x1, %r12b
leaq -0x160(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r12d, %r12d
leaq 0x1c20b(%rip), %rsi     # 0x22d78
leaq -0x158e(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
movq %rax, %r13
movq -0x160(%rbp), %rdi
cmpq %r15, %rdi
je 0x6b9a
movq -0x150(%rbp), %rsi
incq %rsi
callq 0x3230
testb %r12b, %r12b
jne 0x6ba7
jmp 0x6c73
movq %rax, %r13
movq %r14, %rdi
callq 0x31a0
jmp 0x6c73
movq %rax, %r13
movq -0x140(%rbp), %rdi
cmpq %r12, %rdi
je 0x6c5a
movq -0x130(%rbp), %rsi
jmp 0x6c4d
jmp 0x6c14
movq %rax, %r13
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x6c40
movq -0x90(%rbp), %rsi
jmp 0x6c38
jmp 0x6c57
jmp 0x6c57
movq %rax, %r13
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x6c40
movq -0xe0(%rbp), %rsi
jmp 0x6c38
movq %rax, %r13
jmp 0x6c40
jmp 0x6c57
movq %rax, %r13
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x6c40
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x3230
movq -0x50(%rbp), %rdi
cmpq %rbx, %rdi
je 0x6c5a
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0x6c5a
movq %rax, %r13
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x6c73
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3230
movq %r13, %rdi
callq 0x33f0
nop