// File: /workspace/github_cpp_makefile_star2_O3/RuiDGPires[P]CrimLang/src/generator.cpp
// Function: gc_Tracker::init(crl::Node*)
void _gc_Tracker::init(crl::Node *node){
	u32 size = 0;
	ASSERT(node->get_child(1)->type == crl::Node::Type::LEAF, "Var declaration must have a name as second token");
	std::string name = get_token(node->get_child(1)).str;

	if (node->get_child(0)->type == crl::Node::Type::VECTOR){
		crl::Node *vec = node->get_child(0);
		ASSERT(vec->get_child(1)->type == crl::Node::Type::LEAF, "Vector needs to have it's size as second child");

		// Vectors will be laid on the stack like so: [1st element, 2nd, 3rd, ..., last element, size]
		// When roll-backing the SF, one just needs to peek at the top of the stack
		// When assigning values, the var location will be the first element	
		
		u32 element_size = size_of(get_token(vec->get_child(0)).str);
		size = atoi(get_token(vec->get_child(1)).str.c_str())*element_size;

		symb_tracker.local_create(name, size + 1);

		this->stream_funcs <<
			"; Advance the stack (variable is unitialized)\n" << 
			"MVI R1 " << size << "\n" <<
			"SUB RS R1\n" <<
			"PSH R1\n";

		return;
	}

	// ELSE....
	ASSERT(node->get_child(0)->type == crl::Node::Type::LEAF, "Var declaration must start with type");
	std::string type = get_token(node->get_child(0)).str;
	size = size_of(type);
	
	symb_tracker.local_create(name, size);

	if (node->children.size() == 3){
		ASSERT(node->get_child(2)->type == crl::Node::Type::ASSIGN, "Third child must be assign");
		this->expression(node->get_child(2)->get_child(0), this->stream_funcs);
		// The result of the expression will be stored on the stack, that is our variable
	}else
		this->stream_funcs << 
			"; Advance the stack (variable is unitialized)\n" << 
			"MVI R1 " << size << "\n" <<
			"SUB RS R1\n";
	
	this->stream_funcs << "\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq %rsi, %rdi
movl $0x1, %esi
callq *0x18(%rax)
cmpl $0x10, 0x8(%rax)
jne 0xb6ae
movq (%r14), %rax
movq %r14, %rdi
movl $0x1, %esi
callq *0x18(%rax)
movq %rax, %r15
leaq -0x48(%rbp), %r13
movq %r13, -0x10(%r13)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0x4d52
movl 0x80(%r15), %eax
movl %eax, 0x28(%r12)
movq 0x78(%r15), %rax
movq %rax, 0x20(%r12)
leaq -0x68(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq (%r12), %rax
cmpq %r13, %rax
je 0xb200
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0xb208
movups (%r13), %xmm0
movups %xmm0, (%rcx)
leaq -0x58(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0x70(%rbp)
movq %r13, (%rdi)
movq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
callq 0x191f8
movq (%r14), %rax
movq %r14, %rdi
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0x19, 0x8(%rax)
movq (%r14), %rax
movq 0x18(%rax), %rax
jne 0xb2cd
movq %r14, %rdi
xorl %esi, %esi
callq *%rax
movq %rax, %r14
movq (%rax), %rax
movq %r14, %rdi
movl $0x1, %esi
callq *0x18(%rax)
cmpl $0x10, 0x8(%rax)
jne 0xb786
movq (%r14), %rax
movq %r14, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq %rax, %r15
leaq -0x58(%rbp), %rdi
movq %r13, (%rdi)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
callq 0x4d52
movl 0x80(%r15), %eax
movl %eax, -0x30(%rbp)
movq 0x78(%r15), %rax
movq %rax, -0x38(%rbp)
leaq -0xa8(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x58(%rbp), %rax
cmpq %r13, %rax
je 0xb507
movq %rax, -0xb8(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0xb511
movq %r14, %rdi
xorl %esi, %esi
callq *%rax
cmpl $0x10, 0x8(%rax)
jne 0xb71a
movq (%r14), %rax
movq %r14, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq %rax, %r15
leaq -0x58(%rbp), %rdi
movq %r13, (%rdi)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
callq 0x4d52
movl 0x80(%r15), %eax
movl %eax, -0x30(%rbp)
movq 0x78(%r15), %rax
movq %rax, -0x38(%rbp)
leaq -0x88(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x58(%rbp), %rax
cmpq %r13, %rax
je 0xb33e
movq %rax, -0x98(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0xb348
movups (%r13), %xmm0
movups %xmm0, (%r12)
leaq -0x58(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0x90(%rbp)
movq %r13, (%rdi)
movq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
callq 0x191f8
leaq -0xe8(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
leaq -0xf8(%rbp), %rdi
callq 0x4d52
leaq -0xf8(%rbp), %rdi
callq 0x9395
movl %eax, %r15d
movq -0xf8(%rbp), %rdi
cmpq %r13, %rdi
je 0xb3bd
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0xc8(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd8(%rbp), %rdi
callq 0x4d52
leaq 0x530(%rbx), %rdi
leaq -0xd8(%rbp), %rsi
movl %r15d, %edx
callq 0xe250
movq -0xd8(%rbp), %rdi
cmpq %r13, %rdi
je 0xb410
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x3230
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
cmpq $0x18, %rax
jne 0xb463
movq (%r14), %rax
movq %r14, %rdi
movl $0x2, %esi
callq *0x18(%rax)
cmpl $0x6, 0x8(%rax)
jne 0xb7ef
movq (%r14), %rax
movq %r14, %rdi
movl $0x2, %esi
callq *0x18(%rax)
movq (%rax), %rcx
movq %rax, %rdi
xorl %esi, %esi
callq *0x18(%rcx)
leaq 0x318(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8c5c
jmp 0xb4c8
leaq 0x328(%rbx), %r14
leaq 0x10108(%rip), %rsi     # 0x1b579
movl $0x2e, %edx
movq %r14, %rdi
callq 0x3280
leaq 0xfef8(%rip), %rsi      # 0x1b37d
movl $0x7, %edx
movq %r14, %rdi
callq 0x3280
movl %r15d, %esi
movq %r14, %rdi
callq 0x3170
movq %rax, %r14
leaq 0x1003c(%rip), %rsi     # 0x1b4e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq 0xfff7(%rip), %rsi      # 0x1b4b2
movl $0xa, %edx
movq %r14, %rdi
callq 0x3280
addq $0x328, %rbx            # imm = 0x328
leaq 0x1000d(%rip), %rsi     # 0x1b4e3
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3280
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0xb683
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0xb683
movups (%r13), %xmm0
movups %xmm0, (%r12)
movq -0x50(%rbp), %rax
leaq -0xb8(%rbp), %rdi
movq %rax, 0x8(%rdi)
movq %r13, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movb $0x0, -0x48(%rbp)
callq 0x9395
movl %eax, %r15d
movq -0xb8(%rbp), %rdi
cmpq %r12, %rdi
je 0xb553
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x58(%rbp), %rdi
callq 0x191f8
movq (%r14), %rax
movq %r14, %rdi
movl $0x1, %esi
callq *0x18(%rax)
movq %rax, %r14
leaq -0x58(%rbp), %rdi
movq %r13, (%rdi)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
callq 0x4d52
movl 0x80(%r14), %eax
leaq -0x58(%rbp), %r12
movl %eax, 0x28(%r12)
movq 0x78(%r14), %rax
movq %rax, 0x20(%r12)
movq (%r12), %rdi
callq 0x3350
movl %eax, %r14d
movq %r12, %rdi
callq 0x191f8
leaq -0x108(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
addq %rsi, %rdx
leaq -0x118(%rbp), %rdi
callq 0x4d52
imull %r15d, %r14d
leaq 0x530(%rbx), %rdi
leal 0x1(%r14), %edx
leaq -0x118(%rbp), %rsi
callq 0xe250
movq -0x118(%rbp), %rdi
cmpq %r12, %rdi
je 0xb60a
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x3230
addq $0x328, %rbx            # imm = 0x328
leaq 0xff61(%rip), %rsi      # 0x1b579
movl $0x2e, %edx
movq %rbx, %rdi
callq 0x3280
leaq 0xfd51(%rip), %rsi      # 0x1b37d
movl $0x7, %edx
movq %rbx, %rdi
callq 0x3280
movl %r14d, %esi
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0xfe95(%rip), %rsi      # 0x1b4e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq 0xfe50(%rip), %rsi      # 0x1b4b2
movl $0xa, %edx
movq %rbx, %rdi
callq 0x3280
leaq 0xfecc(%rip), %rsi      # 0x1b542
movl $0x7, %edx
movq %rbx, %rdi
callq 0x3280
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0xb69c
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3230
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0x188(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xfc51(%rip), %rsi      # 0x1b31e
leaq 0xfc7a(%rip), %rdx      # 0x1b34e
leaq -0x198(%rbp), %rdi
callq 0x4336
movb $0x1, %r12b
leaq -0x198(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r12d, %r12d
leaq 0x17672(%rip), %rsi     # 0x22d78
leaq -0x6127(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
jmp 0xb856
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0x148(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xfbc0(%rip), %rsi      # 0x1b2f9
leaq 0xfbdd(%rip), %rdx      # 0x1b31d
leaq -0x158(%rbp), %rdi
callq 0x4336
movb $0x1, %r12b
leaq -0x158(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r12d, %r12d
leaq 0x17606(%rip), %rsi     # 0x22d78
leaq -0x6193(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
jmp 0xb856
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0x168(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xfda5(%rip), %rsi      # 0x1b54a
leaq 0xfdcc(%rip), %rdx      # 0x1b578
leaq -0x178(%rbp), %rdi
callq 0x4336
movb $0x1, %r12b
leaq -0x178(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r12d, %r12d
leaq 0x1759a(%rip), %rsi     # 0x22d78
leaq -0x61ff(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
jmp 0xb856
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0x128(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xfb4a(%rip), %rsi      # 0x1b358
leaq 0xfb5d(%rip), %rdx      # 0x1b372
leaq -0x138(%rbp), %rdi
callq 0x4336
movb $0x1, %r13b
leaq -0x138(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r13d, %r13d
leaq 0x17531(%rip), %rsi     # 0x22d78
leaq -0x6268(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
movq %rax, %rbx
movq -0x138(%rbp), %rdi
cmpq %r15, %rdi
je 0xb874
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x3230
testb %r13b, %r13b
jne 0xb881
jmp 0xb9a8
movq %rax, %rbx
movq %r14, %rdi
callq 0x31a0
jmp 0xb9a8
movq %rax, %rbx
movq -0x178(%rbp), %rdi
cmpq %r15, %rdi
je 0xb8c6
movq -0x168(%rbp), %rsi
jmp 0xb8be
jmp 0xb8d0
movq %rax, %rbx
movq -0x158(%rbp), %rdi
cmpq %r15, %rdi
je 0xb8c6
movq -0x148(%rbp), %rsi
incq %rsi
callq 0x3230
testb %r12b, %r12b
jne 0xb8d3
jmp 0xb9c3
movq %rax, %rbx
movq %r14, %rdi
callq 0x31a0
jmp 0xb9c3
movq %rax, %rbx
movq -0x118(%rbp), %rdi
cmpq %r12, %rdi
je 0xb9c3
movq -0x108(%rbp), %rsi
jmp 0xb9bb
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r13, %rdi
je 0xb9a8
movq -0xc8(%rbp), %rsi
jmp 0xb95a
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
cmpq %r12, %rdi
je 0xb939
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x58(%rbp), %rdi
callq 0x191f8
jmp 0xb9c3
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
cmpq %r13, %rdi
je 0xb9a8
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0xb9a8
movq %rax, %rbx
movq -0x198(%rbp), %rdi
cmpq %r15, %rdi
je 0xb982
movq -0x188(%rbp), %rsi
incq %rsi
callq 0x3230
testb %r12b, %r12b
jne 0xb98c
jmp 0xb9dc
movq %rax, %rbx
movq %r14, %rdi
callq 0x31a0
jmp 0xb9dc
jmp 0xb9a0
jmp 0xb9a0
jmp 0xb9a0
jmp 0xb9a0
jmp 0xb9a0
movq %rax, %rbx
jmp 0xb9c3
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0xb9c3
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x3230
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0xb9dc
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33f0