// File: RuiDGPires[P]CrimLang/src/generator.cpp
// Function: gc_Tracker::term(crl::Node*, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char>>&)
u32 _gc_Tracker::term(crl::Node *node, std::stringstream &stream){
	ASSERT(node->type == crl::Node::Type::TERM, "Term has to be term (duuuh)");
	size_t size = node->children.size();
	ASSERT(node->get_child(0)->type == crl::Node::Type::FACTOR, "Child needs to be factor");
	u32 reg1 = this->factor(node->get_child(0), stream);
	std::string name1 = reg_tracker.reg_name(reg1);
	u32 reg2;

	for (size_t i = 1; i < size; i += 2){
		// TODO : division
		reg2 = this->factor(node->get_child(i+1), stream);
		if (get_token(node->get_child(i)).type == crl::Token::Type::TIMES)
			stream << "MUL " << name1 << " " << reg_tracker.reg_name(reg2) << "\n";
		else
			stream << "DIV " << name1 << " " << reg_tracker.reg_name(reg2) << "\n";
		reg_tracker.free(reg2);
	}
	
	return reg1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x10(%rbp), %rax
cmpl $0xe, 0x8(%rax)
je 0xb8bf
movb $0x1, -0x4d(%rbp)
movl $0x50, %edi
callq 0x4190
movq %rax, -0x138(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x4590
movq -0x130(%rbp), %rdx
leaq 0x1fa4e(%rip), %rsi     # 0x2b281
leaq -0x38(%rbp), %rdi
callq 0x52e0
jmp 0xb83e
movq -0x138(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x38(%rbp), %rcx
movl %edx, %esi
callq 0x9140
jmp 0xb857
movq -0x138(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
leaq 0x2e517(%rip), %rsi     # 0x39d80
leaq -0x2560(%rip), %rdx     # 0x9310
callq 0x4550
jmp 0xbcc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb89d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x41e0
leaq -0x39(%rbp), %rdi
callq 0x4360
testb $0x1, -0x4d(%rbp)
jne 0xb8ae
jmp 0xb8ba
movq -0x138(%rbp), %rdi
callq 0x4230
jmp 0xbcbc
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x51d0
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0xf, 0x8(%rax)
je 0xb9a5
movb $0x1, -0x7a(%rbp)
movl $0x50, %edi
callq 0x4190
movq %rax, -0x148(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x4590
movq -0x140(%rbp), %rdx
leaq 0x1f984(%rip), %rsi     # 0x2b29d
leaq -0x78(%rbp), %rdi
callq 0x52e0
jmp 0xb924
movq -0x148(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x78(%rbp), %rcx
movl %edx, %esi
callq 0x9140
jmp 0xb93d
movq -0x148(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0x2e431(%rip), %rsi     # 0x39d80
leaq -0x2646(%rip), %rdx     # 0x9310
callq 0x4550
jmp 0xbcc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb983
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x41e0
leaq -0x79(%rbp), %rdi
callq 0x4360
testb $0x1, -0x7a(%rbp)
jne 0xb994
jmp 0xb9a0
movq -0x148(%rbp), %rdi
callq 0x4230
jmp 0xbcbc
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x18(%rax)
movq -0x128(%rbp), %rdi
movq %rax, %rsi
movq -0x18(%rbp), %rdx
callq 0x9360
movq -0x128(%rbp), %rsi
movl %eax, -0x80(%rbp)
addq $0x500, %rsi            # imm = 0x500
movl -0x80(%rbp), %edx
leaq -0xa0(%rbp), %rdi
callq 0x13040
movq $0x1, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0xbc8c
movq -0x10(%rbp), %rdi
movl -0xb0(%rbp), %esi
incl %esi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movq %rax, -0x150(%rbp)
jmp 0xba1e
movq -0x150(%rbp), %rsi
movq -0x128(%rbp), %rdi
movq -0x18(%rbp), %rdx
callq 0x9360
movl %eax, -0x154(%rbp)
jmp 0xba3d
movl -0x154(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0x10(%rbp), %rdi
movl -0xb0(%rbp), %esi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movq %rax, -0x160(%rbp)
jmp 0xba65
movq -0x160(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xa2e0
jmp 0xba7a
movl -0xc0(%rbp), %eax
movl %eax, -0x164(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x285a0
movl -0x164(%rbp), %eax
cmpl $0x15, %eax
jne 0xbb88
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x1f806(%rip), %rsi     # 0x2b2b6
callq 0x42e0
movq %rax, -0x170(%rbp)
jmp 0xbabe
movq -0x170(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x42c0
movq %rax, -0x178(%rbp)
jmp 0xbada
movq -0x178(%rbp), %rdi
leaq 0x1f51d(%rip), %rsi     # 0x2b005
callq 0x42e0
movq %rax, -0x180(%rbp)
jmp 0xbaf6
movq -0x128(%rbp), %rsi
addq $0x500, %rsi            # imm = 0x500
movl -0xa4(%rbp), %edx
leaq -0x100(%rbp), %rdi
callq 0x13040
jmp 0xbb18
movq -0x180(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x42c0
movq %rax, -0x188(%rbp)
jmp 0xbb34
movq -0x188(%rbp), %rdi
leaq 0x1f9a1(%rip), %rsi     # 0x2b4e3
callq 0x42e0
jmp 0xbb49
leaq -0x100(%rbp), %rdi
callq 0x41e0
jmp 0xbc58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbcb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x41e0
jmp 0xbcb0
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
leaq 0x1f724(%rip), %rsi     # 0x2b2bb
callq 0x42e0
movq %rax, -0x190(%rbp)
jmp 0xbba5
movq -0x190(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x42c0
movq %rax, -0x198(%rbp)
jmp 0xbbc1
movq -0x198(%rbp), %rdi
leaq 0x1f436(%rip), %rsi     # 0x2b005
callq 0x42e0
movq %rax, -0x1a0(%rbp)
jmp 0xbbdd
movq -0x128(%rbp), %rsi
addq $0x500, %rsi            # imm = 0x500
movl -0xa4(%rbp), %edx
leaq -0x120(%rbp), %rdi
callq 0x13040
jmp 0xbbff
movq -0x1a0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x42c0
movq %rax, -0x1a8(%rbp)
jmp 0xbc1b
movq -0x1a8(%rbp), %rdi
leaq 0x1f8ba(%rip), %rsi     # 0x2b4e3
callq 0x42e0
jmp 0xbc30
leaq -0x120(%rbp), %rdi
callq 0x41e0
jmp 0xbc58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x41e0
jmp 0xbcb0
movq -0x128(%rbp), %rdi
addq $0x500, %rdi            # imm = 0x500
movl -0xa4(%rbp), %esi
callq 0x13240
jmp 0xbc73
jmp 0xbc75
movq -0xb0(%rbp), %rax
addq $0x2, %rax
movq %rax, -0xb0(%rbp)
jmp 0xb9ef
movl -0x80(%rbp), %eax
movl %eax, -0x1ac(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x41e0
movl -0x1ac(%rbp), %eax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0x41e0
movq -0x48(%rbp), %rdi
callq 0x4580
nopw %cs:(%rax,%rax)