// File: /workspace/github_cpp_makefile_star2_O1/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, -0x40(%rbp)
movq %rdi, -0x80(%rbp)
cmpl $0xe, 0x8(%rsi)
jne 0x7842
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 0x78ac
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 -0x40(%rbp), %rdx
callq 0x5698
leaq 0x500(%rbx), %r13
leaq -0xa8(%rbp), %rdi
movq %r13, %rsi
movl %eax, -0x44(%rbp)
movl %eax, %edx
callq 0xdde4
movq %r15, -0xb8(%rbp)
cmpq $0x2, %r15
jb 0x780e
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
movq -0x40(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
movl $0x1, %r15d
leaq 0x3f(%rcx), %rax
movq %rax, -0xb0(%rbp)
leal 0x1(%r15), %esi
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x80(%rbp), %rdi
movq %rax, %rsi
movq -0x40(%rbp), %rdx
callq 0x5698
movl %eax, -0x2c(%rbp)
movq %r13, %r14
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
movq %r15, %rbx
movl %r15d, %esi
callq *0x18(%rax)
leaq -0x68(%rbp), %r13
leaq -0x78(%rbp), %r15
movq %rax, %r12
movq %r13, -0x78(%rbp)
movq 0x58(%rax), %rsi
movq 0x60(%rax), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x4d4a
movl 0x80(%r12), %eax
movl %eax, 0x18(%r13)
movq 0x78(%r12), %rax
movq %rax, 0x10(%r13)
movl -0x58(%rbp), %r12d
movq %r15, %rdi
callq 0x192b0
cmpl $0x15, %r12d
jne 0x771e
movl $0x4, %edx
movq -0x38(%rbp), %rdi
leaq 0x13c0d(%rip), %rsi     # 0x1b2b6
callq 0x3280
movq %r14, %r13
movl -0x2c(%rbp), %r14d
movq %rbx, %r15
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0x38(%rbp), %rdi
callq 0x3280
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13924(%rip), %rsi     # 0x1b005
callq 0x3280
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0xdde4
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %r12, %rdi
callq 0x3280
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13dcf(%rip), %rsi     # 0x1b4e3
callq 0x3280
jmp 0x779e
movl $0x4, %edx
movq -0x38(%rbp), %rdi
leaq 0x13b8d(%rip), %rsi     # 0x1b2bb
callq 0x3280
movq %r14, %r13
movl -0x2c(%rbp), %r14d
movq %rbx, %r15
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0x38(%rbp), %rdi
callq 0x3280
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1389f(%rip), %rsi     # 0x1b005
callq 0x3280
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0xdde4
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %r12, %rdi
callq 0x3280
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13d4a(%rip), %rsi     # 0x1b4e3
callq 0x3280
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x77b7
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3230
movslq %r14d, %rax
leaq 0x3f(%rax), %rdx
testq %rax, %rax
cmovnsq %rax, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq (%r13), %rdx
andq -0xb0(%rbp), %rax
xorl %esi, %esi
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
cmpq %rcx, %rax
setbe %sil
movq $-0x2, %rax
movl %r14d, %ecx
rolq %cl, %rax
andq %rax, -0x8(%rdx,%rsi,8)
addq $0x2, %r15
cmpq -0xb8(%rbp), %r15
jb 0x7612
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x782d
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), %r12
movq %r12, -0x10(%r12)
leaq 0x13a1f(%rip), %rsi     # 0x1b281
leaq 0x13a33(%rip), %rdx     # 0x1b29c
leaq -0xf8(%rbp), %rdi
callq 0x433a
movb $0x1, %r15b
leaq -0xf8(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r15d, %r15d
leaq 0x1b4dd(%rip), %rsi     # 0x22d78
leaq -0x22bc(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
jmp 0x7914
movl $0x50, %edi
callq 0x3120
movq %rax, %r14
leaq -0xc8(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x139d1(%rip), %rsi     # 0x1b29d
leaq 0x139e2(%rip), %rdx     # 0x1b2b5
leaq -0xd8(%rbp), %rdi
callq 0x433a
movb $0x1, %r15b
leaq -0xd8(%rbp), %rcx
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5470
xorl %r15d, %r15d
leaq 0x1b473(%rip), %rsi     # 0x22d78
leaq -0x2326(%rip), %rdx     # 0x55e6
movq %r14, %rdi
callq 0x33d0
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x7954
movq -0xc8(%rbp), %rsi
jmp 0x7944
jmp 0x794e
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
cmpq %r12, %rdi
je 0x7954
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0x7954
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x79ab
movq %r14, %rdi
callq 0x31a0
jmp 0x79ab
jmp 0x7989
jmp 0x7989
jmp 0x7969
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x798c
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3230
jmp 0x798c
jmp 0x7989
movq %rax, %rbx
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x79ab
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33f0
nop