// File: /workspace/github_cpp_makefile_star2_O2/lhydave[P]SysYCompilerLab/back/riscv/emit_riscv.cpp
// Function: riscv::emit_assign(std::shared_ptr<tigger::assign_stmt> const&)
void emit_assign(const shared_ptr<tigger::assign_stmt> &stmt)
{
	auto lval = stmt->lval, rval = stmt->rval;
	auto parsearray = [](const string &s) {
		std::pair<string, int> ret;
		auto l = s.find('['), r = s.find(']');
		ret.first = s.substr(0, l);
		ret.second = atoi(s.substr(l + 1, r - l - 1).c_str());
		return ret;
	};
	if (lval.find('[') != string::npos) // array store
	{
		auto temp = parsearray(lval);
		if (in_int12(temp.second))
			riscv_dst << "\tsw\t" << rval << ", " << temp.second << "("
					  << temp.first << ")\n";
		else
		{
			riscv_dst << "\tli\tt0, " << temp.second << "\n";
			riscv_dst << "\tadd\tt0, t0, " << temp.second << "\n";
			riscv_dst << "\tsw\t" << rval << ", 0(t0)\n";
		}
		return;
	}
	if (rval.find('[') != string::npos) // array load
	{
		auto temp = parsearray(rval);
		if (in_int12(temp.second))
			riscv_dst << "\tlw\t" << lval << ", " << temp.second << "("
					  << temp.first << ")\n";
		else
		{
			riscv_dst << "\tli\tt0, " << temp.second << "\n";
			riscv_dst << "\tadd\tt0, t0, " << temp.first << "\n";
			riscv_dst << "\tsw\t" << lval << ", 0(t0)\n";
		}
		return;
	}
	// ordinary assign
	if (isdigit(rval[0]) ||
		(rval[0] == '-' && isdigit(rval[1]))) // number assign
	{
		riscv_dst << "\tli\t" << lval << ", " << rval << "\n";
		return;
	}
	if (rval[0] == '-') // negate
	{
		riscv_dst << "\tneg\t" << lval << ", "
				  << rval.substr(1, rval.length() - 1) << "\n";
		return;
	}
	if (rval[0] == '!')
	{
		riscv_dst << "\tseqz\t" << lval << ", "
				  << rval.substr(1, rval.length() - 1) << "\n";
		return;
	}
	std::istringstream rval_f(rval);
	string left, op, right;
	rval_f >> left;
	if (rval_f.peek() == EOF) // single assign
	{
		riscv_dst << "\tmv\t" << lval << ", " << left << "\n";
		return;
	}
	// binary operator
	rval_f >> op >> right;
	static unordered_map<string, string> convert = {{"+", "add"}, {"-", "sub"},
		{"*", "mul"}, {"/", "div"}, {"%", "rem"}, {"<", "slt"}, {">", "sgt"},
		{"<=", "sgt"}, {">=", "slt"}, {"||", "or"}, {"!=", "xor"},
		{"==", "xor"}};
	if (op == "&&")
	{
		riscv_dst << "\tsnez" << lval << ", " << left << "\n\tsnez\tt0, "
				  << right << "\n\tand\t" << lval << ", " << lval << ", t0\n";
		return;
	}
	riscv_dst << "\t" << convert[op] << "\t" << lval << ", " << left << ", "
			  << right << "\n";
	if (op == "<=" || op == ">=" || op == "==")
	{
		riscv_dst << "\tseqz\t" << lval << ", " << lval << "\n";
		return;
	}
	if (op == "||" || op == "!=")
	{
		riscv_dst << "\tsnez\t" << lval << ", " << lval << "\n";
		return;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x530, %rsp            # imm = 0x530
movq %rdi, %rbx
movq (%rdi), %rsi
addq $0x8, %rsi
leaq 0x10(%rsp), %rdi
callq 0x5380
movq (%rbx), %rsi
addq $0x28, %rsi
leaq 0x30(%rsp), %rdi
callq 0x5380
leaq 0x10(%rsp), %rdi
pushq $0x5b
popq %rsi
xorl %edx, %edx
callq 0x5330
cmpq $-0x1, %rax
je 0x1a484
leaq 0xb0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1b5ba
movl $0x800, %eax            # imm = 0x800
addl 0xd0(%rsp), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0x1a52f
leaq 0x14156(%rip), %rdi     # 0x2e578
leaq 0x53b4(%rip), %rsi      # 0x1f7dd
callq 0x5230
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x5470(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
movl 0xd0(%rsp), %esi
movq %rax, %rdi
callq 0x54a0
leaq 0x5498(%rip), %rsi      # 0x1f8f8
movq %rax, %rdi
callq 0x5230
leaq 0xb0(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x54fd(%rip), %rsi      # 0x1f97c
jmp 0x1a5b8
leaq 0x30(%rsp), %rdi
pushq $0x5b
popq %rsi
xorl %edx, %edx
callq 0x5330
cmpq $-0x1, %rax
je 0x1a5c5
leaq 0xb0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1b5ba
movl $0x800, %eax            # imm = 0x800
addl 0xd0(%rsp), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0x1a629
leaq 0x140ab(%rip), %rdi     # 0x2e578
leaq 0x531c(%rip), %rsi      # 0x1f7f0
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x53c5(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
movl 0xd0(%rsp), %esi
movq %rax, %rdi
callq 0x54a0
leaq 0x53ed(%rip), %rsi      # 0x1f8f8
movq %rax, %rdi
callq 0x5230
leaq 0xb0(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x5452(%rip), %rsi      # 0x1f97c
jmp 0x1a6b3
leaq 0x14042(%rip), %rdi     # 0x2e578
leaq 0x536f(%rip), %rsi      # 0x1f8ac
callq 0x5230
movl 0xd0(%rsp), %esi
movq %rax, %rdi
callq 0x54a0
leaq 0x4484(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
leaq 0x14011(%rip), %rdi     # 0x2e578
leaq 0x5274(%rip), %rsi      # 0x1f7e2
callq 0x5230
movl 0xd0(%rsp), %esi
movq %rax, %rdi
callq 0x54a0
leaq 0x4453(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
leaq 0x13fe0(%rip), %rdi     # 0x2e578
leaq 0x523e(%rip), %rsi      # 0x1f7dd
callq 0x5230
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x53be(%rip), %rsi      # 0x1f976
movq %rax, %rdi
callq 0x5230
jmp 0x1a6bb
movq 0x30(%rsp), %rax
movsbl (%rax), %ecx
leal -0x30(%rcx), %edx
cmpl $0xa, %edx
jae 0x1a6e9
leaq 0x13f98(%rip), %rdi     # 0x2e578
leaq 0x520e(%rip), %rsi      # 0x1f7f5
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x52b2(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x43c0(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
jmp 0x1a6c8
leaq 0x13f48(%rip), %rdi     # 0x2e578
leaq 0x5275(%rip), %rsi      # 0x1f8ac
callq 0x5230
movl 0xd0(%rsp), %esi
movq %rax, %rdi
callq 0x54a0
leaq 0x438a(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
leaq 0x13f17(%rip), %rdi     # 0x2e578
leaq 0x517a(%rip), %rsi      # 0x1f7e2
callq 0x5230
leaq 0xb0(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4358(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
leaq 0x13ee5(%rip), %rdi     # 0x2e578
leaq 0x5143(%rip), %rsi      # 0x1f7dd
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x52c3(%rip), %rsi      # 0x1f976
movq %rax, %rdi
callq 0x5230
leaq 0xb0(%rsp), %rdi
callq 0x5548
leaq 0x30(%rsp), %rdi
callq 0x5548
leaq 0x10(%rsp), %rdi
callq 0x5548
addq $0x530, %rsp            # imm = 0x530
popq %rbx
popq %r14
popq %r15
retq
movzbl %cl, %ecx
cmpl $0x21, %ecx
je 0x1a780
cmpl $0x2d, %ecx
jne 0x1a7f2
movsbl 0x1(%rax), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
jbe 0x1a5d9
leaq 0x13e63(%rip), %rdi     # 0x2e578
leaq 0x50de(%rip), %rsi      # 0x1f7fa
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x517d(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
movq %rax, %rbx
leaq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rcx
decq %rcx
leaq 0xb0(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x5270
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0x5210
leaq 0x4269(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
jmp 0x1a6bb
leaq 0x13df1(%rip), %rdi     # 0x2e578
leaq 0x5072(%rip), %rsi      # 0x1f800
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x510b(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
movq %rax, %rbx
leaq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rcx
decq %rcx
leaq 0xb0(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x5270
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0x5210
leaq 0x41f7(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
jmp 0x1a6bb
leaq 0x3b0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x5480
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x60(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x3b0(%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x5310
leaq 0x3b0(%rsp), %rdi
callq 0x50f0
cmpl $-0x1, %eax
je 0x1a952
leaq 0x3b0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x5310
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x5310
movb 0x1432e(%rip), %al      # 0x2ebc0
testb %al, %al
je 0x1ab10
leaq 0x4fa4(%rip), %rsi      # 0x1f845
leaq 0x50(%rsp), %rdi
callq 0xc8ce
testb %al, %al
je 0x1a986
leaq 0x13cbe(%rip), %rdi     # 0x2e578
leaq 0x4f87(%rip), %rsi      # 0x1f848
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4fd8(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
leaq 0x90(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4f55(%rip), %rsi      # 0x1f84e
movq %rax, %rdi
callq 0x5230
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4f45(%rip), %rsi      # 0x1f85a
movq %rax, %rdi
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4f81(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4fc5(%rip), %rsi      # 0x1f912
jmp 0x1aad5
leaq 0x13c1f(%rip), %rdi     # 0x2e578
leaq 0x4ea7(%rip), %rsi      # 0x1f807
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4f39(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
jmp 0x1aac3
leaq 0x13beb(%rip), %rdi     # 0x2e578
leaq 0x4f87(%rip), %rsi      # 0x1f91b
callq 0x5230
movq %rax, %rbx
leaq 0x141e5(%rip), %rdi     # 0x2eb88
leaq 0x50(%rsp), %rsi
callq 0x1bf0e
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5210
leaq 0x4f5c(%rip), %rsi      # 0x1f91b
movq %rax, %rdi
callq 0x5230
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4ed7(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
leaq 0x90(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x4eb8(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x5210
leaq 0x3fc6(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
leaq 0x4e0d(%rip), %rsi      # 0x1f832
leaq 0x50(%rsp), %rdi
callq 0xc8ce
leaq 0x4dca(%rip), %rbx      # 0x1f800
testb %al, %al
jne 0x1aa95
leaq 0x4df4(%rip), %rsi      # 0x1f835
leaq 0x50(%rsp), %rdi
callq 0xc8ce
testb %al, %al
jne 0x1aa95
leaq 0x4dec(%rip), %rsi      # 0x1f842
leaq 0x50(%rsp), %rdi
callq 0xc8ce
testb %al, %al
jne 0x1aa95
leaq 0x4dcd(%rip), %rsi      # 0x1f838
leaq 0x50(%rsp), %rdi
callq 0xc8ce
leaq 0x4de5(%rip), %rbx      # 0x1f861
testb %al, %al
jne 0x1aa95
leaq 0x4db4(%rip), %rsi      # 0x1f83b
leaq 0x50(%rsp), %rdi
callq 0xc8ce
testb %al, %al
je 0x1aadd
leaq 0x13adc(%rip), %rdi     # 0x2e578
movq %rbx, %rsi
callq 0x5230
leaq 0x10(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5210
leaq 0x4df7(%rip), %rsi      # 0x1f8b2
movq %rax, %rdi
callq 0x5230
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5210
leaq 0x3f07(%rip), %rsi      # 0x1e9dc
movq %rax, %rdi
callq 0x5230
leaq 0x70(%rsp), %rdi
callq 0x5548
leaq 0x50(%rsp), %rdi
callq 0x5548
leaq 0x90(%rsp), %rdi
callq 0x5548
leaq 0x3b0(%rsp), %rdi
callq 0x5550
jmp 0x1a6c8
leaq 0x140a9(%rip), %rdi     # 0x2ebc0
callq 0x54e0
testl %eax, %eax
je 0x1a89a
leaq 0x4ce1(%rip), %rsi      # 0x1f80c
leaq 0x4cdc(%rip), %rdx      # 0x1f80e
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0x1b7b0
leaq 0xf0(%rsp), %r14
leaq 0x4c7d(%rip), %rsi      # 0x1f7ce
leaq 0x4cba(%rip), %rdx      # 0x1f812
movq %r14, %rdi
callq 0x1b7b0
leaq 0x130(%rsp), %r14
leaq 0x4ca7(%rip), %rsi      # 0x1f816
leaq 0x4ca2(%rip), %rdx      # 0x1f818
movq %r14, %rdi
callq 0x1b7b0
leaq 0x170(%rsp), %r14
leaq 0x38ec(%rip), %rsi      # 0x1e479
leaq 0x4c88(%rip), %rdx      # 0x1f81c
movq %r14, %rdi
callq 0x1b7b0
leaq 0x1b0(%rsp), %r14
leaq 0x4c75(%rip), %rsi      # 0x1f820
leaq 0x4c70(%rip), %rdx      # 0x1f822
movq %r14, %rdi
callq 0x1b7b0
leaq 0x1f0(%rsp), %r14
leaq 0x4c5d(%rip), %rsi      # 0x1f826
leaq 0x4c58(%rip), %rdx      # 0x1f828
movq %r14, %rdi
callq 0x1b7b0
leaq 0x230(%rsp), %r14
leaq 0x4c45(%rip), %rsi      # 0x1f82c
leaq 0x4c40(%rip), %rdx      # 0x1f82e
movq %r14, %rdi
callq 0x1b7b0
leaq 0x270(%rsp), %r14
leaq 0x4c2d(%rip), %rsi      # 0x1f832
leaq 0x4c22(%rip), %rdx      # 0x1f82e
movq %r14, %rdi
callq 0x1b7f0
leaq 0x2b0(%rsp), %r14
leaq 0x4c12(%rip), %rsi      # 0x1f835
leaq 0x4bfe(%rip), %rdx      # 0x1f828
movq %r14, %rdi
callq 0x1b7f0
leaq 0x2f0(%rsp), %r14
leaq 0x4bf7(%rip), %rsi      # 0x1f838
leaq 0x316c(%rip), %rdx      # 0x1ddb4
movq %r14, %rdi
callq 0x1b830
leaq 0x330(%rsp), %r14
leaq 0x4bdc(%rip), %rsi      # 0x1f83b
leaq 0x4bd8(%rip), %rdx      # 0x1f83e
movq %r14, %rdi
callq 0x1b7f0
leaq 0x370(%rsp), %r14
leaq 0x4bc5(%rip), %rsi      # 0x1f842
leaq 0x4bba(%rip), %rdx      # 0x1f83e
movq %r14, %rdi
callq 0x1b7f0
leaq 0x3b0(%rsp), %rdx
leaq 0xd(%rsp), %rax
movq %rax, (%rsp)
leaq 0x13ee4(%rip), %rdi     # 0x2eb88
leaq 0xb0(%rsp), %rsi
leaq 0xf(%rsp), %r8
leaq 0xe(%rsp), %r9
xorl %ecx, %ecx
callq 0x1ba2a
movl $0x2c0, %ebx            # imm = 0x2C0
leaq (%rsp,%rbx), %rdi
addq $0xb0, %rdi
callq 0x1b870
addq $-0x40, %rbx
cmpq $-0x40, %rbx
jne 0x1acc2
leaq 0xba3(%rip), %rdi       # 0x1b886
leaq 0x13e9e(%rip), %rsi     # 0x2eb88
leaq 0x135b7(%rip), %rdx     # 0x2e2a8
callq 0x5200
leaq 0x13ec3(%rip), %rdi     # 0x2ebc0
callq 0x5190
jmp 0x1a89a
movq %rax, %r15
movl $0x2c0, %ebx            # imm = 0x2C0
leaq (%rsp,%rbx), %rdi
addq $0xb0, %rdi
callq 0x1b870
addq $-0x40, %rbx
cmpq $-0x40, %rbx
jne 0x1ad0f
jmp 0x1ad44
movq %rax, %r15
jmp 0x1ad44
movq %rax, %r15
addq $-0x40, %r14
movq %r14, %rdi
callq 0x1b870
cmpq %rbx, %r14
jne 0x1ad33
leaq 0x13e75(%rip), %rdi     # 0x2ebc0
callq 0x5180
jmp 0x1ad61
jmp 0x1ad93
jmp 0x1ad9f
jmp 0x1ad93
jmp 0x1ad93
jmp 0x1ad9f
jmp 0x1ad93
movq %rax, %r15
leaq 0x70(%rsp), %rdi
callq 0x5548
leaq 0x50(%rsp), %rdi
callq 0x5548
leaq 0x90(%rsp), %rdi
callq 0x5548
leaq 0x3b0(%rsp), %rdi
callq 0x5550
jmp 0x1adaf
jmp 0x1ad93
movq %rax, %r15
jmp 0x1adaf
movq %rax, %r15
jmp 0x1adb9
jmp 0x1ad9f
movq %rax, %r15
leaq 0xb0(%rsp), %rdi
callq 0x5548
leaq 0x30(%rsp), %rdi
callq 0x5548
leaq 0x10(%rsp), %rdi
callq 0x5548
movq %r15, %rdi
callq 0x54c0