// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %rdx, -0x68(%rbp)
movq %rsi, %rbx
movq %rdi, -0x90(%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 0x7a03
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 0x4d52
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 0x191f8
jmp 0x7a06
xorl %r12d, %r12d
movq (%rbx), %rax
movq %rbx, %rdi
movl %r12d, %esi
callq *0x18(%rax)
movq -0x90(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
movq -0x68(%rbp), %rdx
callq 0x7518
movl %eax, %ebx
addq $0x500, %r15            # imm = 0x500
leaq -0xb0(%rbp), %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0xdda4
testb %r13b, %r13b
movq %r15, -0x78(%rbp)
je 0x7bcd
movq %r15, %rdi
callq 0xdc82
movl %eax, -0x2c(%rbp)
movq %r15, %r13
movq -0x68(%rbp), %rax
leaq 0x10(%rax), %r15
leaq 0x137dd(%rip), %rsi     # 0x1b249
movl $0x4, %edx
movq %r15, %rdi
callq 0x3280
leaq -0x60(%rbp), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0xdda4
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
movq %rax, %r15
leaq 0x1381e(%rip), %rsi     # 0x1b2c0
movl $0x3, %edx
movq %rax, %rdi
callq 0x3280
leaq 0x1380e(%rip), %rsi     # 0x1b2c4
movl $0x4, %edx
movq %r15, %rdi
callq 0x3280
leaq -0xd8(%rbp), %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
callq 0xdda4
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
movq %rax, %r15
leaq 0x13510(%rip), %rsi     # 0x1b005
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
leaq 0x139c4(%rip), %rsi     # 0x1b4e3
movl $0x1, %edx
movq %rax, %rdi
callq 0x3280
leaq -0xc8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7b4b
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x50(%rbp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x7b64
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3230
movslq %ebx, %rax
leal 0x3f(%rbx), %ecx
testl %ebx, %ebx
cmovnsl %ebx, %ecx
sarl $0x6, %ecx
movslq %ecx, %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 0xdda4
movq -0x60(%rbp), %rdi
cmpq %r15, %rdi
je 0x7bd0
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0x7bd0
movl %ebx, -0x2c(%rbp)
movq -0x70(%rbp), %rax
sarq $0x3, %rax
incq %r12
movq %rax, -0x70(%rbp)
cmpq %rax, %r12
jae 0x7def
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
movq -0x68(%rbp), %rax
leaq 0x10(%rax), %r14
leaq 0x3f(%rcx), %rax
movq %rax, -0xb8(%rbp)
leal 0x1(%r12), %esi
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x90(%rbp), %rdi
movq %rax, %rsi
movq -0x68(%rbp), %rdx
callq 0x7518
movq %rax, -0x88(%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 0x4d52
movl 0x80(%r15), %eax
movl %eax, 0x18(%rbx)
movq 0x78(%r15), %rax
movq %rax, 0x10(%rbx)
movl -0x40(%rbp), %r15d
movq %r12, %rdi
callq 0x191f8
cmpl $0x16, %r15d
jne 0x7d02
movl $0x4, %edx
movq %r14, %rdi
leaq 0x13636(%rip), %rsi     # 0x1b2c9
callq 0x3280
movq %r13, %r12
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %r14, %rdi
callq 0x3280
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13342(%rip), %rsi     # 0x1b005
callq 0x3280
leaq -0x60(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0xdda4
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
movl $0x1, %edx
movq %rax, %rdi
leaq 0x137e8(%rip), %rsi     # 0x1b4e3
callq 0x3280
jmp 0x7d7e
movl $0x4, %edx
movq %r14, %rdi
leaq 0x135b3(%rip), %rsi     # 0x1b2c4
callq 0x3280
movq %r13, %r12
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %r14, %rdi
callq 0x3280
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x132c4(%rip), %rsi     # 0x1b005
callq 0x3280
leaq -0x60(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0xdda4
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r15, %rdi
callq 0x3280
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1376a(%rip), %rsi     # 0x1b4e3
callq 0x3280
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x7d97
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3230
movq -0x88(%rbp), %rcx
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movslq %ecx, %rdi
sarl $0x6, %eax
cltq
shlq $0x3, %rax
movq -0x78(%rbp), %rdx
addq (%rdx), %rax
andq -0xb8(%rbp), %rdi
xorl %edx, %edx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
cmpq %rsi, %rdi
setbe %dl
movq $-0x2, %rsi
rolq %cl, %rsi
andq %rsi, -0x8(%rax,%rdx,8)
addq $0x2, %r12
cmpq -0x70(%rbp), %r12
jb 0x7c05
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7e0e
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x3230
movl -0x2c(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7e82
jmp 0x7e2b
jmp 0x7e82
jmp 0x7e82
movq %rax, %rbx
jmp 0x7e52
movq %rax, %rbx
leaq -0xc8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7e52
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x3230
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x7e6d
jmp 0x7e82
jmp 0x7e82
jmp 0x7e62
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x7e85
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0x7e85
jmp 0x7e82
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7ea4
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33f0