// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, -0x50(%rbp)
movq %rdi, -0x48(%rbp)
cmpl $0xe, 0x8(%rsi)
jne 0x6663
movq %rsi, %r14
movq (%rsi), %rax
movq 0x18(%rsi), %rbx
subq 0x10(%rsi), %rbx
movq %rsi, %rdi
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0xf, 0x8(%rax)
jne 0x66ba
sarq $0x3, %rbx
movq %rbx, -0x58(%rbp)
movq (%r14), %rax
movq %r14, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq -0x48(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
movq -0x50(%rbp), %rbx
movq %rbx, %rdx
callq 0x4f8c
leaq 0x500(%r15), %rsi
leaq -0x78(%rbp), %rdi
movq %rsi, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl %eax, %edx
callq 0xab34
leaq 0x10(%rbx), %rax
movq %rax, -0x40(%rbp)
pushq $0x1
popq %rbx
leaq -0xa8(%rbp), %r15
cmpq -0x58(%rbp), %rbx
jae 0x6645
leal 0x1(%rbx), %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movq -0x50(%rbp), %rdx
callq 0x4f8c
movl %eax, %r12d
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
callq *0x18(%rax)
addq $0x58, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0xb24a
movl -0x88(%rbp), %r13d
movq %r15, %rdi
callq 0x135f8
cmpl $0x15, %r13d
jne 0x65d1
movq -0x40(%rbp), %rdi
leaq 0xed33(%rip), %rsi      # 0x152b6
callq 0x3230
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x3220
movq %rax, %rdi
leaq 0xea67(%rip), %rsi      # 0x15005
callq 0x3230
movq %rax, %r13
movq %r15, %rdi
movq -0x30(%rbp), %rsi
movl %r12d, %edx
callq 0xab34
movq %r13, %rdi
movq %r15, %rsi
callq 0x3220
movq %rax, %rdi
leaq 0xef19(%rip), %rsi      # 0x154e3
callq 0x3230
jmp 0x6628
movq -0x40(%rbp), %rdi
leaq 0xecdf(%rip), %rsi      # 0x152bb
callq 0x3230
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x3220
movq %rax, %rdi
leaq 0xea0e(%rip), %rsi      # 0x15005
callq 0x3230
movq %rax, %r13
movq %r15, %rdi
movq -0x30(%rbp), %rsi
movl %r12d, %edx
callq 0xab34
movq %r13, %rdi
movq %r15, %rsi
callq 0x3220
movq %rax, %rdi
leaq 0xeec0(%rip), %rsi      # 0x154e3
callq 0x3230
movq %r15, %rdi
callq 0x3110
movq -0x30(%rbp), %rdi
movl %r12d, %esi
callq 0xac12
addq $0x2, %rbx
jmp 0x6520
leaq -0x78(%rbp), %rdi
callq 0x3110
movl -0x34(%rbp), %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x50
popq %rdi
callq 0x3140
movq %rax, %r14
leaq 0xec0c(%rip), %rsi      # 0x15281
leaq -0xe8(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0x3be4
movb $0x1, %r15b
pushq $-0x1
popq %rdx
leaq -0xe8(%rbp), %rcx
movq %r14, %rdi
movl %edx, %esi
callq 0x4e88
xorl %r15d, %r15d
leaq 0x176e7(%rip), %rsi     # 0x1dd90
leaq -0x1778(%rip), %rdx     # 0x4f38
movq %r14, %rdi
callq 0x33f0
jmp 0x670f
pushq $0x50
popq %rdi
callq 0x3140
movq %rax, %r14
leaq 0xebd1(%rip), %rsi      # 0x1529d
leaq -0xc8(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0x3be4
movb $0x1, %r15b
pushq $-0x1
popq %rdx
leaq -0xc8(%rbp), %rcx
movq %r14, %rdi
movl %edx, %esi
callq 0x4e88
xorl %r15d, %r15d
leaq 0x17690(%rip), %rsi     # 0x1dd90
leaq -0x17cf(%rip), %rdx     # 0x4f38
movq %r14, %rdi
callq 0x33f0
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
jmp 0x6727
jmp 0x6733
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x3110
testb %r15b, %r15b
jne 0x6736
jmp 0x6765
movq %rax, %rbx
movq %r14, %rdi
callq 0x31b0
jmp 0x6765
jmp 0x6759
jmp 0x6759
jmp 0x6746
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x3110
jmp 0x675c
jmp 0x6759
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x3410
nop