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


	u32 size = size_of(type);

	this->stream_defines << "%define " << name << " " << symb_tracker.global_create(name, size) << "\n";

	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_global_vars);
		this->stream_global_vars << 
			"; Global " << name << "\n" << 
			"MVI R1 " << name << "\n" <<
			"; Pop the result from the expression\n";
		for (u32 i = 0; i < size; i++)
				this->stream_global_vars <<
				"POP R2\n" <<
				"STORE m[R1][" << size - i - 1<< "] R2\n";
		this->stream_global_vars << "\n";
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0x10, 0x8(%rax)
je 0xd603
movb $0x1, -0x45(%rbp)
movl $0x50, %edi
callq 0x4190
movq %rax, -0x198(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x4590
movq -0x190(%rbp), %rdx
leaq 0x1dd82(%rip), %rsi     # 0x2b2f9
leaq -0x30(%rbp), %rdi
callq 0x52e0
jmp 0xd582
movq -0x198(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x30(%rbp), %rcx
movl %edx, %esi
callq 0x9140
jmp 0xd59b
movq -0x198(%rbp), %rdi
movb $0x0, -0x45(%rbp)
leaq 0x2c7d3(%rip), %rsi     # 0x39d80
leaq -0x42a4(%rip), %rdx     # 0x9310
callq 0x4550
jmp 0xdc2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xd5e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x41e0
leaq -0x31(%rbp), %rdi
callq 0x4360
testb $0x1, -0x45(%rbp)
jne 0xd5f2
jmp 0xd5fe
movq -0x198(%rbp), %rdi
callq 0x4230
jmp 0xdc25
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x18(%rax)
cmpl $0x10, 0x8(%rax)
je 0xd6db
movb $0x1, -0x6a(%rbp)
movl $0x50, %edi
callq 0x4190
movq %rax, -0x1a8(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x4590
movq -0x1a0(%rbp), %rdx
leaq 0x1dccf(%rip), %rsi     # 0x2b31e
leaq -0x68(%rbp), %rdi
callq 0x52e0
jmp 0xd65a
movq -0x1a8(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x68(%rbp), %rcx
movl %edx, %esi
callq 0x9140
jmp 0xd673
movq -0x1a8(%rbp), %rdi
movb $0x0, -0x6a(%rbp)
leaq 0x2c6fb(%rip), %rsi     # 0x39d80
leaq -0x437c(%rip), %rdx     # 0x9310
callq 0x4550
jmp 0xdc2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xd6b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x41e0
leaq -0x69(%rbp), %rdi
callq 0x4360
testb $0x1, -0x6a(%rbp)
jne 0xd6ca
jmp 0xd6d6
movq -0x1a8(%rbp), %rdi
callq 0x4230
jmp 0xdc25
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
xorl %esi, %esi
callq *%rax
movq %rax, %rsi
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0xa2e0
movq -0x1b8(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x41d0
movq -0x1b8(%rbp), %rdi
callq 0x285a0
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
movl $0x1, %esi
callq *%rax
movq %rax, -0x1b0(%rbp)
jmp 0xd73a
movq -0x1b0(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0xa2e0
jmp 0xd74f
leaq -0xe0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movq %rsi, -0x1c0(%rbp)
callq 0x41d0
movq -0x1c0(%rbp), %rdi
callq 0x285a0
leaq -0x138(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x4150
jmp 0xd78a
leaq -0x138(%rbp), %rdi
callq 0xdc30
movl %eax, -0x1c4(%rbp)
jmp 0xd79e
leaq -0x138(%rbp), %rdi
callq 0x41e0
movl -0x1c4(%rbp), %eax
movq -0x188(%rbp), %rdi
movl %eax, -0x114(%rbp)
addq $0x18, %rdi
leaq 0x1db87(%rip), %rsi     # 0x2b34f
callq 0x42e0
movq %rax, -0x1d0(%rbp)
jmp 0xd7d6
movq -0x1d0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x42c0
movq %rax, -0x1d8(%rbp)
jmp 0xd7f2
movq -0x1d8(%rbp), %rdi
leaq 0x1d805(%rip), %rsi     # 0x2b005
callq 0x42e0
movq %rax, -0x1e0(%rbp)
jmp 0xd80e
movq -0x188(%rbp), %rax
addq $0x530, %rax            # imm = 0x530
movq %rax, -0x1e8(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x4150
jmp 0xd837
movq -0x1e8(%rbp), %rdi
movl -0x114(%rbp), %edx
leaq -0x158(%rbp), %rsi
callq 0x13280
movl %eax, -0x1ec(%rbp)
jmp 0xd858
movl -0x1ec(%rbp), %esi
movq -0x1e0(%rbp), %rdi
callq 0x4420
movq %rax, -0x1f8(%rbp)
jmp 0xd873
movq -0x1f8(%rbp), %rdi
leaq 0x1dc62(%rip), %rsi     # 0x2b4e3
callq 0x42e0
jmp 0xd888
leaq -0x158(%rbp), %rdi
callq 0x41e0
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x51d0
cmpq $0x3, %rax
jne 0xdbec
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
movl $0x2, %esi
callq *%rax
movq %rax, -0x200(%rbp)
jmp 0xd8c6
movq -0x200(%rbp), %rax
cmpl $0x6, 0x8(%rax)
je 0xda0a
movb $0x1, -0x17a(%rbp)
movl $0x50, %edi
callq 0x4190
movq %rax, -0x210(%rbp)
leaq -0x179(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x4590
movq -0x208(%rbp), %rdx
leaq 0x1da48(%rip), %rsi     # 0x2b358
leaq -0x178(%rbp), %rdi
callq 0x52e0
jmp 0xd91e
movq -0x210(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x178(%rbp), %rcx
movl %edx, %esi
callq 0x9140
jmp 0xd93a
movq -0x210(%rbp), %rdi
movb $0x0, -0x17a(%rbp)
leaq 0x2c431(%rip), %rsi     # 0x39d80
leaq -0x4646(%rip), %rdx     # 0x9310
callq 0x4550
jmp 0xdc2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xdc19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xdc0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x41e0
jmp 0xdc0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x41e0
jmp 0xdc0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xd9e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x41e0
leaq -0x179(%rbp), %rdi
callq 0x4360
testb $0x1, -0x17a(%rbp)
jne 0xd9f9
jmp 0xda05
movq -0x210(%rbp), %rdi
callq 0x4230
jmp 0xdc0d
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
movl $0x2, %esi
callq *%rax
movq %rax, -0x218(%rbp)
jmp 0xda25
movq -0x218(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
xorl %esi, %esi
callq *%rax
movq %rax, -0x220(%rbp)
jmp 0xda40
movq -0x220(%rbp), %rsi
movq -0x188(%rbp), %rdi
movq %rdi, %rdx
addq $0x190, %rdx            # imm = 0x190
callq 0xd440
jmp 0xda5f
movq -0x188(%rbp), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
leaq 0x1d8ff(%rip), %rsi     # 0x2b373
callq 0x42e0
movq %rax, -0x228(%rbp)
jmp 0xda82
movq -0x228(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x42c0
movq %rax, -0x230(%rbp)
jmp 0xda9e
movq -0x230(%rbp), %rdi
leaq 0x1da37(%rip), %rsi     # 0x2b4e3
callq 0x42e0
movq %rax, -0x238(%rbp)
jmp 0xdaba
movq -0x238(%rbp), %rdi
leaq 0x1d8b5(%rip), %rsi     # 0x2b37d
callq 0x42e0
movq %rax, -0x240(%rbp)
jmp 0xdad6
movq -0x240(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x42c0
movq %rax, -0x248(%rbp)
jmp 0xdaf2
movq -0x248(%rbp), %rdi
leaq 0x1d9e3(%rip), %rsi     # 0x2b4e3
callq 0x42e0
movq %rax, -0x250(%rbp)
jmp 0xdb0e
movq -0x250(%rbp), %rdi
leaq 0x1d869(%rip), %rsi     # 0x2b385
callq 0x42e0
jmp 0xdb23
movl $0x0, -0x180(%rbp)
movl -0x180(%rbp), %eax
cmpl -0x114(%rbp), %eax
jae 0xdbce
movq -0x188(%rbp), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
leaq 0x1d857(%rip), %rsi     # 0x2b3ab
callq 0x42e0
movq %rax, -0x258(%rbp)
jmp 0xdb62
movq -0x258(%rbp), %rdi
leaq 0x1d843(%rip), %rsi     # 0x2b3b3
callq 0x42e0
movq %rax, -0x260(%rbp)
jmp 0xdb7e
movq -0x260(%rbp), %rdi
movl -0x114(%rbp), %eax
movl -0x180(%rbp), %esi
notl %esi
addl %eax, %esi
callq 0x4420
movq %rax, -0x268(%rbp)
jmp 0xdba3
movq -0x268(%rbp), %rdi
leaq 0x1d80f(%rip), %rsi     # 0x2b3c0
callq 0x42e0
jmp 0xdbb8
jmp 0xdbba
movl -0x180(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x180(%rbp)
jmp 0xdb2d
movq -0x188(%rbp), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
leaq 0x1d900(%rip), %rsi     # 0x2b4e3
callq 0x42e0
jmp 0xdbea
jmp 0xdbec
leaq -0xe0(%rbp), %rdi
callq 0x41e0
leaq -0x90(%rbp), %rdi
callq 0x41e0
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0xe0(%rbp), %rdi
callq 0x41e0
leaq -0x90(%rbp), %rdi
callq 0x41e0
movq -0x40(%rbp), %rdi
callq 0x4580
nop