// File: 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
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0x10, 0x8(%rax)
je 0xa747
movb $0x1, -0x4d(%rbp)
movl $0x50, %edi
callq 0x4190
movq %rax, -0x1b0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x4590
movq -0x1a8(%rbp), %rdx
leaq 0x20d0b(%rip), %rsi     # 0x2b3c6
leaq -0x38(%rbp), %rdi
callq 0x52e0
jmp 0xa6c6
movq -0x1b0(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x38(%rbp), %rcx
movl %edx, %esi
callq 0x9140
jmp 0xa6df
movq -0x1b0(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
leaq 0x2f68f(%rip), %rsi     # 0x39d80
leaq -0x13e8(%rip), %rdx     # 0x9310
callq 0x4550
jmp 0xacae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xa725
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x41e0
leaq -0x39(%rbp), %rdi
callq 0x4360
testb $0x1, -0x4d(%rbp)
jne 0xa736
jmp 0xa742
movq -0x1b0(%rbp), %rdi
callq 0x4230
jmp 0xaca5
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
xorl %esi, %esi
callq *%rax
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0xa2e0
movq -0x1b8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x41d0
movq -0x1b8(%rbp), %rdi
callq 0x285a0
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
leaq -0xc8(%rbp), %rdi
callq 0x4150
jmp 0xa79e
leaq -0xc8(%rbp), %rdi
callq 0xdc30
movl %eax, -0x1bc(%rbp)
jmp 0xa7b2
leaq -0xc8(%rbp), %rdi
callq 0x41e0
movl -0x1bc(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x20ba4(%rip), %rsi     # 0x2b37d
callq 0x42e0
movq %rax, -0x1c8(%rbp)
jmp 0xa7e7
movq -0x1c8(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x4420
movq %rax, -0x1d0(%rbp)
jmp 0xa802
movq -0x1d0(%rbp), %rdi
leaq 0x20cd3(%rip), %rsi     # 0x2b4e3
callq 0x42e0
movq %rax, -0x1d8(%rbp)
jmp 0xa81e
movq -0x1d8(%rbp), %rdi
leaq 0x20c86(%rip), %rsi     # 0x2b4b2
callq 0x42e0
jmp 0xa833
movl $0x1, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
ja 0xac3f
movq -0x10(%rbp), %rdi
movl -0xcc(%rbp), %esi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movq %rax, -0x1e0(%rbp)
jmp 0xa86c
movq -0x1e0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
addq $0x30, %rdi
leaq 0x20c94(%rip), %rsi     # 0x2b520
callq 0x66e0
movb %al, -0x1e1(%rbp)
jmp 0xa899
movb -0x1e1(%rbp), %al
andb $0x1, %al
movb %al, -0xd9(%rbp)
testb $0x1, -0xd9(%rbp)
je 0xabed
movq -0xd8(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
xorl %esi, %esi
callq *%rax
movq %rax, -0x1f0(%rbp)
jmp 0xa8cf
movq -0x1f0(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0xa2e0
jmp 0xa8e4
leaq -0x100(%rbp), %rdi
movq %rdi, -0x200(%rbp)
leaq -0x130(%rbp), %rsi
movq %rsi, -0x208(%rbp)
callq 0x41d0
movq -0x208(%rbp), %rdi
callq 0x285a0
movq -0x1a0(%rbp), %rax
movq -0x200(%rbp), %rsi
addq $0x530, %rax            # imm = 0x530
movq %rax, -0x1f8(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x4150
jmp 0xa93a
movq -0x1f8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x13160
movb %al, -0x209(%rbp)
jmp 0xa955
leaq -0x150(%rbp), %rdi
callq 0x41e0
movb -0x209(%rbp), %al
testb $0x1, %al
jne 0xa970
jmp 0xaaf9
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x209fe(%rip), %rsi     # 0x2b37d
callq 0x42e0
movq %rax, -0x218(%rbp)
jmp 0xa98d
movq -0x1a0(%rbp), %rax
addq $0x530, %rax            # imm = 0x530
movq %rax, -0x220(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4150
jmp 0xa9b6
movq -0x220(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x131d0
movq %rax, -0x228(%rbp)
jmp 0xa9d2
movq -0x218(%rbp), %rdi
movq -0x228(%rbp), %rax
movl %eax, %ecx
movl %ecx, -0x158(%rbp)
shrq $0x20, %rax
movb %al, -0x154(%rbp)
movl -0x158(%rbp), %esi
callq 0x4420
movq %rax, -0x230(%rbp)
jmp 0xaa06
movq -0x230(%rbp), %rdi
leaq 0x20acf(%rip), %rsi     # 0x2b4e3
callq 0x42e0
movq %rax, -0x238(%rbp)
jmp 0xaa22
movq -0x238(%rbp), %rdi
leaq 0x20af4(%rip), %rsi     # 0x2b524
callq 0x42e0
movq %rax, -0x240(%rbp)
jmp 0xaa3e
movq -0x240(%rbp), %rdi
leaq 0x20ae3(%rip), %rsi     # 0x2b52f
callq 0x42e0
movq %rax, -0x248(%rbp)
jmp 0xaa5a
movq -0x248(%rbp), %rdi
leaq 0x20ad2(%rip), %rsi     # 0x2b53a
callq 0x42e0
jmp 0xaa6f
leaq -0x178(%rbp), %rdi
callq 0x41e0
jmp 0xabce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xac9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x41e0
jmp 0xac9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xabdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x41e0
jmp 0xabdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x41e0
jmp 0xabdc
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x20875(%rip), %rsi     # 0x2b37d
callq 0x42e0
movq %rax, -0x250(%rbp)
jmp 0xab16
movq -0x1a0(%rbp), %rax
addq $0x530, %rax            # imm = 0x530
movq %rax, -0x258(%rbp)
leaq -0x198(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4150
jmp 0xab3f
movq -0x258(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x13210
movl %eax, -0x25c(%rbp)
jmp 0xab5a
movl -0x25c(%rbp), %esi
movq -0x250(%rbp), %rdi
callq 0x4420
movq %rax, -0x268(%rbp)
jmp 0xab75
movq -0x268(%rbp), %rdi
leaq 0x20960(%rip), %rsi     # 0x2b4e3
callq 0x42e0
movq %rax, -0x270(%rbp)
jmp 0xab91
movq -0x270(%rbp), %rdi
leaq 0x209a3(%rip), %rsi     # 0x2b542
callq 0x42e0
jmp 0xaba6
leaq -0x198(%rbp), %rdi
callq 0x41e0
jmp 0xabce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x41e0
jmp 0xabdc
leaq -0x100(%rbp), %rdi
callq 0x41e0
jmp 0xac29
leaq -0x100(%rbp), %rdi
callq 0x41e0
jmp 0xac9c
movq -0xd8(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
xorl %esi, %esi
callq *%rax
movq %rax, -0x278(%rbp)
jmp 0xac08
movq -0x278(%rbp), %rsi
movq -0x1a0(%rbp), %rdi
movq %rdi, %rdx
addq $0x318, %rdx            # imm = 0x318
callq 0xd440
jmp 0xac27
jmp 0xac29
jmp 0xac2b
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0xa83d
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x208c7(%rip), %rsi     # 0x2b515
callq 0x42e0
movq %rax, -0x280(%rbp)
jmp 0xac5c
movq -0x280(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x42c0
movq %rax, -0x288(%rbp)
jmp 0xac75
movq -0x288(%rbp), %rdi
leaq 0x20860(%rip), %rsi     # 0x2b4e3
callq 0x42e0
jmp 0xac8a
leaq -0x70(%rbp), %rdi
callq 0x41e0
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0x41e0
movq -0x48(%rbp), %rdi
callq 0x4580
nop