// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %rsi, %r14
movq %rdi, -0x40(%rbp)
movq (%rsi), %rax
movq %rsi, %rdi
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0x10, 0x8(%rax)
jne 0x5dc2
movq (%r14), %rax
movq %r14, %rdi
xorl %esi, %esi
callq *0x18(%rax)
leaq 0x58(%rax), %rsi
leaq -0x90(%rbp), %rbx
movq %rbx, %rdi
callq 0xb24a
leaq -0xa8(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%rbx), %rcx
leaq -0x80(%rbp), %rdx
cmpq %rdx, %rcx
je 0x5ad4
movq %rcx, -0xb8(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x5ada
movups (%rdx), %xmm0
movups %xmm0, (%rax)
leaq -0x90(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0xb0(%rbp)
movq %rdx, (%rdi)
andq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
callq 0x135f8
leaq 0x30(%r14), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x32f0
leaq -0xf8(%rbp), %rdi
callq 0x7909
movl %eax, %ebx
leaq -0xf8(%rbp), %rdi
callq 0x3110
addq $0x10, %r15
leaq 0xf84b(%rip), %rsi      # 0x1537d
movq %r15, -0x30(%rbp)
movq %r15, %rdi
callq 0x3230
movl %ebx, %esi
movq %rax, %rdi
callq 0x3180
leaq 0xf994(%rip), %rsi      # 0x154e3
movq %rax, %rdi
callq 0x3230
leaq 0xf954(%rip), %rsi      # 0x154b2
movq %rax, %rdi
callq 0x3230
movq -0x40(%rbp), %rax
leaq 0x318(%rax), %rcx
movq %rcx, -0x98(%rbp)
addq $0x530, %rax            # imm = 0x530
movq %rax, -0x38(%rbp)
pushq $0x1
popq %r15
leaq -0x158(%rbp), %r13
cmpl 0x50(%r14), %r15d
ja 0x5d76
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0x18(%rax)
movq %rax, %rbx
movq %rax, %rdi
addq $0x30, %rdi
leaq 0xf96c(%rip), %rsi      # 0x15520
callq 0x410a
testb %al, %al
je 0x5c01
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x18(%rax)
addq $0x58, %rax
leaq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0xb24a
leaq -0x50(%rbp), %rdx
movq %rdx, -0x60(%rbp)
movq -0x90(%rbp), %rax
leaq -0x80(%rbp), %rcx
cmpq %rcx, %rax
je 0x5c24
movq %rax, -0x60(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x5c2a
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq -0x40(%rbp), %rdi
movq %rax, %rsi
movq -0x98(%rbp), %rdx
callq 0x73e0
jmp 0x5d6e
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq -0x88(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rcx, -0x90(%rbp)
andq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x135f8
leaq -0x118(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x32f0
movq -0x38(%rbp), %rdi
leaq -0x118(%rbp), %r12
movq %r12, %rsi
callq 0xabb4
movl %eax, %ebx
movq %r12, %rdi
callq 0x3110
testb %bl, %bl
je 0x5cfe
movq -0x30(%rbp), %rdi
leaq 0xf6ed(%rip), %rsi      # 0x1537d
callq 0x3230
movq %rax, %rbx
movq %r13, %r12
movq %r13, %rdi
leaq -0x60(%rbp), %rsi
callq 0x32f0
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0xabee
movl %eax, %esi
movq %rbx, %rdi
callq 0x3180
movq %rax, %rdi
leaq 0xf81c(%rip), %rsi      # 0x154e3
callq 0x3230
movq %rax, %rdi
leaq 0xf84e(%rip), %rsi      # 0x15524
callq 0x3230
movq %rax, %rdi
leaq 0xf84a(%rip), %rsi      # 0x1552f
callq 0x3230
movq %rax, %rdi
leaq 0xf846(%rip), %rsi      # 0x1553a
callq 0x3230
movq %r13, %rdi
jmp 0x5d60
movq -0x30(%rbp), %rdi
leaq 0xf674(%rip), %rsi      # 0x1537d
callq 0x3230
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x32f0
movq -0x38(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xac04
movl %eax, %esi
movq %rbx, %rdi
callq 0x3180
movq %rax, %rdi
leaq 0xf79e(%rip), %rsi      # 0x154e3
callq 0x3230
movq %rax, %rdi
leaq 0xf7ee(%rip), %rsi      # 0x15542
callq 0x3230
leaq -0xd8(%rbp), %rdi
callq 0x3110
leaq -0x60(%rbp), %rdi
callq 0x3110
incl %r15d
jmp 0x5b8d
leaq 0xf798(%rip), %rsi      # 0x15515
movq -0x30(%rbp), %rdi
callq 0x3230
leaq -0xb8(%rbp), %rsi
movq %rax, %rdi
callq 0x3220
leaq 0xf747(%rip), %rsi      # 0x154e3
movq %rax, %rdi
callq 0x3230
leaq -0xb8(%rbp), %rdi
callq 0x3110
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x50
popq %rdi
callq 0x3140
movq %rax, %r14
leaq 0xf5f2(%rip), %rsi      # 0x153c6
leaq -0x138(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x3be4
movb $0x1, %r15b
pushq $-0x1
popq %rdx
leaq -0x138(%rbp), %rcx
movq %r14, %rdi
movl %edx, %esi
callq 0x4e88
xorl %r15d, %r15d
leaq 0x17f88(%rip), %rsi     # 0x1dd90
leaq -0xed7(%rip), %rdx      # 0x4f38
movq %r14, %rdi
callq 0x33f0
movq %rax, %rbx
leaq -0x138(%rbp), %rdi
callq 0x3110
testb %r15b, %r15b
jne 0x5e30
jmp 0x5e94
movq %rax, %rbx
movq %r14, %rdi
callq 0x31b0
jmp 0x5e94
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
jmp 0x5e83
jmp 0x5e6b
jmp 0x5e66
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
jmp 0x5e7a
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
jmp 0x5e7a
jmp 0x5e66
jmp 0x5e66
movq %rax, %rbx
jmp 0x5e88
movq %rax, %rbx
jmp 0x5e7f
movq %rax, %rbx
leaq -0x158(%rbp), %rdi
callq 0x3110
leaq -0x60(%rbp), %rdi
callq 0x3110
leaq -0xb8(%rbp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x3410