// File: /workspace/github_cpp_makefile_star2_O1/RuiDGPires[P]CrimLang/src/generator.cpp
// Function: gc_Tracker::basic_expression(crl::Node*, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char>>&)
u32 _gc_Tracker::basic_expression(crl::Node *node, std::stringstream &stream){
	size_t size = node->children.size();
	size_t i = 0;
	bool negate = false;

	if (node->get_child(0)->type == crl::Node::Type::LEAF){
		crl::Token t = get_token(node->get_child(0));
		if (t.type == crl::Token::Type::MINUS){
			negate = true;
			i++;
		}else if (t.type == crl::Token::Type::PLUS) i++;
	}
	u32 reg1 = this->term(node->get_child(i++), stream);
	std::string reg_name = reg_tracker.reg_name(reg1);

	if (negate){
		u32 aux = reg_tracker.alloc();
		stream <<
			"MVI " << reg_tracker.reg_name(aux) << " 0\n" <<
			"SUB " << reg_tracker.reg_name(aux) << " " << reg_name << "\n";
		reg_tracker.free(reg1);
		std::string name1 = reg_tracker.reg_name(aux);
		reg1 = aux;
	}

	u32 reg2;
	for (; i < size; i += 2){
		// TODO : division
		reg2 = this->term(node->get_child(i+1), stream);
		if (get_token(node->get_child(i)).type == crl::Token::Type::PLUS)
			stream << "ADD " << reg_name << " " << reg_tracker.reg_name(reg2) << "\n";
		else
			stream << "SUB " << reg_name << " " << reg_tracker.reg_name(reg2) << "\n";
		reg_tracker.free(reg2);
	}
	return reg1; 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, -0x68(%rbp)
movq %rsi, %rbx
movq %rdi, -0x88(%rbp)
movq (%rsi), %rax
movq 0x18(%rsi), %rcx
subq 0x10(%rsi), %rcx
movq %rcx, -0x70(%rbp)
xorl %r13d, %r13d
movq %rsi, %rdi
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0x10, 0x8(%rax)
movq %rbx, -0x80(%rbp)
jne 0x7a5b
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq %rax, %rbx
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x58(%rbx), %rsi
movq 0x60(%rbx), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %r15
movq %r15, %rdi
callq 0x4d4a
movl 0x80(%rbx), %eax
movl %eax, 0x28(%r15)
movq 0x78(%rbx), %rax
movq -0x80(%rbp), %rbx
movq %rax, 0x20(%r15)
cmpl $0x17, %eax
sete %r13b
andl $-0x2, %eax
xorl %r12d, %r12d
cmpl $0x16, %eax
sete %r12b
movq %r15, %rdi
callq 0x192b0
jmp 0x7a5e
xorl %r12d, %r12d
movq (%rbx), %rax
movq %rbx, %rdi
movl %r12d, %esi
callq *0x18(%rax)
movq -0x88(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
movq -0x68(%rbp), %rdx
callq 0x7550
movl %eax, %ebx
addq $0x500, %r15            # imm = 0x500
leaq -0xa8(%rbp), %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0xdde4
testb %r13b, %r13b
movq %r15, -0x78(%rbp)
je 0x7c26
movq %r15, %rdi
callq 0xdc9a
movl %eax, -0x2c(%rbp)
movq %r15, %r13
movq -0x68(%rbp), %rax
leaq 0x10(%rax), %r15
leaq 0x13785(%rip), %rsi     # 0x1b249
movl $0x4, %edx
movq %r15, %rdi
callq 0x3280
leaq -0x60(%rbp), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0xdde4
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
movq %rax, %r15
leaq 0x137c6(%rip), %rsi     # 0x1b2c0
movl $0x3, %edx
movq %rax, %rdi
callq 0x3280
leaq 0x137b6(%rip), %rsi     # 0x1b2c4
movl $0x4, %edx
movq %r15, %rdi
callq 0x3280
leaq -0xd0(%rbp), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0xdde4
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
movq %rax, %r15
leaq 0x134b8(%rip), %rsi     # 0x1b005
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
leaq 0x1396c(%rip), %rsi     # 0x1b4e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq -0xc0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7ba3
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x50(%rbp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x7bbc
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3230
movslq %ebx, %rax
leaq 0x3f(%rax), %rdx
testq %rax, %rax
cmovnsq %rax, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq (%r13), %rdx
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
leaq 0x3f(%rcx), %rsi
andq %rax, %rsi
xorl %eax, %eax
cmpq %rcx, %rsi
setbe %al
movq $-0x2, %rsi
movl %ebx, %ecx
rolq %cl, %rsi
andq %rsi, -0x8(%rdx,%rax,8)
leaq -0x60(%rbp), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0xdde4
movq -0x60(%rbp), %rdi
cmpq %r15, %rdi
je 0x7c29
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0x7c29
movl %ebx, -0x2c(%rbp)
movq -0x70(%rbp), %rax
sarq $0x3, %rax
incq %r12
movq %rax, -0x70(%rbp)
cmpq %rax, %r12
jae 0x7e3d
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
movq -0x68(%rbp), %rax
leaq 0x10(%rax), %r14
leaq 0x3f(%rcx), %rax
movq %rax, -0xb0(%rbp)
leal 0x1(%r12), %esi
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x88(%rbp), %rdi
movq %rax, %rsi
movq -0x68(%rbp), %rdx
callq 0x7550
movl %eax, -0x30(%rbp)
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
movq %r12, %r13
movl %r12d, %esi
callq *0x18(%rax)
leaq -0x50(%rbp), %rbx
leaq -0x60(%rbp), %r12
movq %rax, %r15
movq %rbx, -0x60(%rbp)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x4d4a
movl 0x80(%r15), %eax
movl %eax, 0x18(%rbx)
movq 0x78(%r15), %rax
movq %rax, 0x10(%rbx)
movl -0x40(%rbp), %r15d
movq %r12, %rdi
callq 0x192b0
cmpl $0x16, %r15d
jne 0x7d53
movl $0x4, %edx
movq %r14, %rdi
leaq 0x135e1(%rip), %rsi     # 0x1b2c9
callq 0x3280
movq %r13, %r12
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq %r14, %rdi
callq 0x3280
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x132ed(%rip), %rsi     # 0x1b005
callq 0x3280
leaq -0x60(%rbp), %rdi
movq -0x78(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0xdde4
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13797(%rip), %rsi     # 0x1b4e3
callq 0x3280
jmp 0x7dcb
movl $0x4, %edx
movq %r14, %rdi
leaq 0x13562(%rip), %rsi     # 0x1b2c4
callq 0x3280
movq %r13, %r12
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq %r14, %rdi
callq 0x3280
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13273(%rip), %rsi     # 0x1b005
callq 0x3280
leaq -0x60(%rbp), %rdi
movq -0x78(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0xdde4
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1371d(%rip), %rsi     # 0x1b4e3
callq 0x3280
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x7de4
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3230
movl -0x30(%rbp), %edi
movslq %edi, %rax
leaq 0x3f(%rax), %rdx
testq %rax, %rax
cmovnsq %rax, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
movq -0x78(%rbp), %rcx
addq (%rcx), %rdx
andq -0xb0(%rbp), %rax
xorl %esi, %esi
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
cmpq %rcx, %rax
setbe %sil
movq $-0x2, %rax
movl %edi, %ecx
rolq %cl, %rax
andq %rax, -0x8(%rdx,%rsi,8)
addq $0x2, %r12
cmpq -0x70(%rbp), %r12
jb 0x7c5e
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7e5c
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3230
movl -0x2c(%rbp), %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7ed0
jmp 0x7e79
jmp 0x7ed0
jmp 0x7ed0
movq %rax, %rbx
jmp 0x7ea0
movq %rax, %rbx
leaq -0xc0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7ea0
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x7ebb
jmp 0x7ed0
jmp 0x7ed0
jmp 0x7eb0
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x7ed3
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0x7ed3
jmp 0x7ed0
movq %rax, %rbx
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7ef2
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33f0