// File: /workspace/github_cpp_makefile_star2_O3/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 $0xd8, %rsp
movq %rdx, -0x38(%rbp)
movq %rdi, -0x80(%rbp)
cmpl $0xe, 0x8(%rsi)
jne 0x77ef
movq %rsi, %rbx
movq (%rsi), %rax
movq 0x18(%rsi), %r15
subq 0x10(%rsi), %r15
movq %rsi, %rdi
xorl %esi, %esi
callq *0x18(%rax)
cmpl $0xf, 0x8(%rax)
jne 0x7858
sarq $0x3, %r15
movq (%rbx), %rax
movq %rbx, -0x88(%rbp)
movq %rbx, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq -0x80(%rbp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
movq -0x38(%rbp), %rdx
callq 0x5698
leaq 0x500(%rbx), %r14
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
movl %eax, -0x44(%rbp)
movl %eax, %edx
callq 0xdda4
movq %r15, -0xb8(%rbp)
cmpq $0x2, %r15
jb 0x77bb
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movl $0x1, %ebx
leaq 0x3f(%rcx), %rax
movq %rax, -0xb0(%rbp)
leal 0x1(%rbx), %esi
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x80(%rbp), %rdi
movq %rax, %rsi
movq -0x38(%rbp), %rdx
callq 0x5698
movq %rax, -0x40(%rbp)
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
movq %rbx, %r15
movl %ebx, %esi
callq *0x18(%rax)
leaq -0x68(%rbp), %r13
leaq -0x78(%rbp), %rbx
movq %rax, %r12
movq %r13, -0x78(%rbp)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x4d52
movl 0x80(%r12), %eax
movl %eax, 0x18(%r13)
movq 0x78(%r12), %rax
movq %rax, 0x10(%r13)
movl -0x58(%rbp), %r12d
movq %rbx, %rdi
callq 0x191f8
cmpl $0x15, %r12d
jne 0x76d4
movl $0x4, %edx
movq -0x30(%rbp), %rdi
leaq 0x13c4e(%rip), %rsi     # 0x1b2b6
callq 0x3280
movq %r15, %rbx
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x3280
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1396c(%rip), %rsi     # 0x1b005
callq 0x3280
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
movq -0x40(%rbp), %rdx
callq 0xdda4
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %r12, %rdi
callq 0x3280
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13e16(%rip), %rsi     # 0x1b4e3
callq 0x3280
jmp 0x774e
movl $0x4, %edx
movq -0x30(%rbp), %rdi
leaq 0x13bd7(%rip), %rsi     # 0x1b2bb
callq 0x3280
movq %r15, %rbx
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x3280
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x138f0(%rip), %rsi     # 0x1b005
callq 0x3280
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
movq -0x40(%rbp), %rdx
callq 0xdda4
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %r12, %rdi
callq 0x3280
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13d9a(%rip), %rsi     # 0x1b4e3
callq 0x3280
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x7767
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3230
movq -0x40(%rbp), %rcx
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movslq %ecx, %rdi
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq (%r14), %rax
andq -0xb0(%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, %rbx
cmpq -0xb8(%rbp), %rbx
jb 0x75d9
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x77da
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3230
movl -0x44(%rbp), %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0xe8(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x13a73(%rip), %rsi     # 0x1b281
leaq 0x13a87(%rip), %rdx     # 0x1b29c
leaq -0xf8(%rbp), %rdi
callq 0x4336
movb $0x1, %r12b
leaq -0xf8(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r12d, %r12d
leaq 0x1b531(%rip), %rsi     # 0x22d78
leaq -0x2268(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
jmp 0x78bf
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0xc8(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x13a26(%rip), %rsi     # 0x1b29d
leaq 0x13a37(%rip), %rdx     # 0x1b2b5
leaq -0xd8(%rbp), %rdi
callq 0x4336
movb $0x1, %r12b
leaq -0xd8(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r12d, %r12d
leaq 0x1b4c8(%rip), %rsi     # 0x22d78
leaq -0x22d1(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r15, %rdi
je 0x78f7
movq -0xc8(%rbp), %rsi
jmp 0x78ef
jmp 0x78fe
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
cmpq %r15, %rdi
je 0x78f7
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x3230
testb %r12b, %r12b
jne 0x7901
jmp 0x7953
movq %rax, %rbx
movq %r14, %rdi
callq 0x31a0
jmp 0x7953
jmp 0x7931
jmp 0x7931
jmp 0x7911
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x7934
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0x7934
jmp 0x7931
movq %rax, %rbx
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7953
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33f0
nop