// File: /workspace/github_cpp_makefile_star2_O1/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 0xb714
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 0x4d4a
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 0xb266
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0xb26e
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 0x192b0
movq (%r14), %rax
movq %r14, %rdi
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0x19, 0x8(%rax)
movq (%r14), %rax
movq 0x18(%rax), %rax
jne 0xb333
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 0xb7ee
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 0x4d4a
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 0xb56d
movq %rax, -0xb8(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0xb577
movq %r14, %rdi
xorl %esi, %esi
callq *%rax
cmpl $0x10, 0x8(%rax)
jne 0xb781
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 0x4d4a
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 0xb3a4
movq %rax, -0x98(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0xb3ae
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 0x192b0
leaq -0xe8(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
leaq -0xf8(%rbp), %rdi
callq 0x4d4a
leaq -0xf8(%rbp), %rdi
callq 0x93d7
movl %eax, %r15d
movq -0xf8(%rbp), %rdi
cmpq %r13, %rdi
je 0xb423
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 0x4d4a
leaq 0x530(%rbx), %rdi
leaq -0xd8(%rbp), %rsi
movl %r15d, %edx
callq 0xe29e
movq -0xd8(%rbp), %rdi
cmpq %r13, %rdi
je 0xb476
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x3230
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
cmpq $0x18, %rax
jne 0xb4c9
movq (%r14), %rax
movq %r14, %rdi
movl $0x2, %esi
callq *0x18(%rax)
cmpl $0x6, 0x8(%rax)
jne 0xb858
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 0x8c94
jmp 0xb52e
leaq 0x328(%rbx), %r14
leaq 0x100a2(%rip), %rsi     # 0x1b579
movl $0x2e, %edx
movq %r14, %rdi
callq 0x3280
leaq 0xfe92(%rip), %rsi      # 0x1b37d
movl $0x7, %edx
movq %r14, %rdi
callq 0x3280
movl %r15d, %esi
movq %r14, %rdi
callq 0x3170
movq %rax, %r14
leaq 0xffd6(%rip), %rsi      # 0x1b4e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq 0xff91(%rip), %rsi      # 0x1b4b2
movl $0xa, %edx
movq %r14, %rdi
callq 0x3280
addq $0x328, %rbx            # imm = 0x328
leaq 0xffa7(%rip), %rsi      # 0x1b4e3
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3280
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0xb6e9
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0xb6e9
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 0x93d7
movl %eax, %r15d
movq -0xb8(%rbp), %rdi
cmpq %r12, %rdi
je 0xb5b9
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x58(%rbp), %rdi
callq 0x192b0
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 0x4d4a
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 0x192b0
leaq -0x108(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
addq %rsi, %rdx
leaq -0x118(%rbp), %rdi
callq 0x4d4a
imull %r15d, %r14d
leaq 0x530(%rbx), %rdi
leal 0x1(%r14), %edx
leaq -0x118(%rbp), %rsi
callq 0xe29e
movq -0x118(%rbp), %rdi
cmpq %r12, %rdi
je 0xb670
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x3230
addq $0x328, %rbx            # imm = 0x328
leaq 0xfefb(%rip), %rsi      # 0x1b579
movl $0x2e, %edx
movq %rbx, %rdi
callq 0x3280
leaq 0xfceb(%rip), %rsi      # 0x1b37d
movl $0x7, %edx
movq %rbx, %rdi
callq 0x3280
movl %r14d, %esi
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
leaq 0xfe2f(%rip), %rsi      # 0x1b4e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq 0xfdea(%rip), %rsi      # 0x1b4b2
movl $0xa, %edx
movq %rbx, %rdi
callq 0x3280
leaq 0xfe66(%rip), %rsi      # 0x1b542
movl $0x7, %edx
movq %rbx, %rdi
callq 0x3280
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0xb702
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), %r12
movq %r12, -0x10(%r12)
leaq 0xfbea(%rip), %rsi      # 0x1b31e
leaq 0xfc13(%rip), %rdx      # 0x1b34e
leaq -0x198(%rbp), %rdi
callq 0x433a
movb $0x1, %r15b
leaq -0x198(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r15d, %r15d
leaq 0x1760b(%rip), %rsi     # 0x22d78
leaq -0x618e(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
jmp 0xb8bf
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0x148(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xfb58(%rip), %rsi      # 0x1b2f9
leaq 0xfb75(%rip), %rdx      # 0x1b31d
leaq -0x158(%rbp), %rdi
callq 0x433a
movb $0x1, %r15b
leaq -0x158(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r15d, %r15d
leaq 0x1759e(%rip), %rsi     # 0x22d78
leaq -0x61fb(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
jmp 0xb8bf
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0x168(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xfd3c(%rip), %rsi      # 0x1b54a
leaq 0xfd63(%rip), %rdx      # 0x1b578
leaq -0x178(%rbp), %rdi
callq 0x433a
movb $0x1, %r15b
leaq -0x178(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r15d, %r15d
leaq 0x17531(%rip), %rsi     # 0x22d78
leaq -0x6268(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
jmp 0xb8bf
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0x128(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0xfae1(%rip), %rsi      # 0x1b358
leaq 0xfaf4(%rip), %rdx      # 0x1b372
leaq -0x138(%rbp), %rdi
callq 0x433a
movb $0x1, %r15b
leaq -0x138(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r15d, %r15d
leaq 0x174c8(%rip), %rsi     # 0x22d78
leaq -0x62d1(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
movq %rax, %rbx
movq -0x138(%rbp), %rdi
cmpq %r13, %rdi
je 0xb8e5
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0xb8e5
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xba1f
movq %r14, %rdi
callq 0x31a0
jmp 0xba1f
movq %rax, %rbx
movq -0x178(%rbp), %rdi
cmpq %r12, %rdi
je 0xb93b
movq -0x168(%rbp), %rsi
jmp 0xb92b
jmp 0xb935
movq %rax, %rbx
movq -0x158(%rbp), %rdi
cmpq %r12, %rdi
je 0xb93b
movq -0x148(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0xb93b
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xba3a
movq %r14, %rdi
callq 0x31a0
jmp 0xba3a
movq %rax, %rbx
movq -0x118(%rbp), %rdi
cmpq %r12, %rdi
je 0xba3a
movq -0x108(%rbp), %rsi
jmp 0xba32
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r13, %rdi
je 0xba1f
movq -0xc8(%rbp), %rsi
jmp 0xb9ce
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
cmpq %r12, %rdi
je 0xb9aa
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x58(%rbp), %rdi
callq 0x192b0
jmp 0xba3a
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
cmpq %r13, %rdi
je 0xba1f
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0xba1f
movq %rax, %rbx
movq -0x198(%rbp), %rdi
cmpq %r12, %rdi
je 0xb9fe
movq -0x188(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0xb9fe
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xba53
movq %r14, %rdi
callq 0x31a0
jmp 0xba53
jmp 0xba17
jmp 0xba17
jmp 0xba17
jmp 0xba17
jmp 0xba17
movq %rax, %rbx
jmp 0xba3a
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0xba3a
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x3230
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0xba53
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33f0
nop