// File: lhydave[P]SysYCompilerLab/back/riscv/emit_riscv.cpp
// Function: riscv::gen_code()
void gen_code()
{
	for (auto i : tigger::seq)
	{
		switch (i->stmt_type)
		{
		case tigger::FUNC_BEGIN:
		{
			auto stmt = std::static_pointer_cast<tigger::func_begin>(i);
			emit_func_begin(stmt);
			break;
		}
		case tigger::FUNC_END:
		{
			auto stmt = std::static_pointer_cast<tigger::func_end>(i);
			emit_func_end(stmt);
			break;
		}
		case tigger::GLB_VAR:
		{
			auto stmt = std::static_pointer_cast<tigger::global_var>(i);
			emit_global_var(stmt);
			break;
		}
		case tigger::ASSIGN:
		{
			auto stmt = std::static_pointer_cast<tigger::assign_stmt>(i);
			emit_assign(stmt);
			break;
		}
		case tigger::GOTO:
		{
			auto stmt = std::static_pointer_cast<tigger::goto_stmt>(i);
			emit_goto(stmt);
			break;
		}
		case tigger::LABEL:
		{
			auto stmt = std::static_pointer_cast<tigger::label_stmt>(i);
			emit_label(stmt);
			break;
		}
		case tigger::CALL:
		{
			auto stmt = std::static_pointer_cast<tigger::call_stmt>(i);
			emit_call(stmt);
			break;
		}
		case tigger::RET:
		{
			auto stmt = std::static_pointer_cast<tigger::ret_stmt>(i);
			emit_ret(stmt);
			break;
		}
		case tigger::STORE:
		{
			auto stmt = std::static_pointer_cast<tigger::store_stmt>(i);
			emit_store(stmt);
			break;
		}
		case tigger::LOAD:
		{
			auto stmt = std::static_pointer_cast<tigger::load_stmt>(i);
			emit_load(stmt);
			break;
		}
		case tigger::LOADADDR:
		{
			auto stmt = std::static_pointer_cast<tigger::loadaddr_stmt>(i);
			emit_loadaddr(stmt);
			break;
		}
		default: break;
		} // switch
	} // for
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
leaq 0x2d096(%rip), %rax     # 0x72a58
movq %rax, -0x8(%rbp)
leaq 0x2d08b(%rip), %rdi     # 0x72a58
callq 0x37ca0
movq %rax, -0x10(%rbp)
leaq 0x2d07b(%rip), %rdi     # 0x72a58
callq 0x37a50
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x48780
testb $0x1, %al
jne 0x459fc
jmp 0x45dd6
leaq -0x10(%rbp), %rdi
callq 0x38110
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x487c0
movq -0xf8(%rbp), %rdi
callq 0x487f0
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0xf0(%rbp)
subl $0xa, %eax
ja 0x45db2
movq -0xf0(%rbp), %rax
leaq 0x9098(%rip), %rcx      # 0x4eae0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x38(%rbp), %rdi
movq %rdi, -0x100(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x48810
movq -0x100(%rbp), %rdi
callq 0x45df0
jmp 0x45a73
leaq -0x38(%rbp), %rdi
callq 0x36100
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x36100
jmp 0x45dcb
leaq -0x58(%rbp), %rdi
movq %rdi, -0x108(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x48860
movq -0x108(%rbp), %rdi
callq 0x45ee0
jmp 0x45abd
leaq -0x58(%rbp), %rdi
callq 0x361c0
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x361c0
jmp 0x45dcb
leaq -0x68(%rbp), %rdi
movq %rdi, -0x110(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x488b0
movq -0x110(%rbp), %rdi
callq 0x45fd0
jmp 0x45b07
leaq -0x68(%rbp), %rdi
callq 0x36030
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x36030
jmp 0x45dcb
leaq -0x78(%rbp), %rdi
movq %rdi, -0x118(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x48900
movq -0x118(%rbp), %rdi
callq 0x460d0
jmp 0x45b51
leaq -0x78(%rbp), %rdi
callq 0x36290
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x36290
jmp 0x45dcb
leaq -0x88(%rbp), %rdi
movq %rdi, -0x120(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x48950
movq -0x120(%rbp), %rdi
callq 0x47270
jmp 0x45b9e
leaq -0x88(%rbp), %rdi
callq 0x36360
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x36360
jmp 0x45dcb
leaq -0x98(%rbp), %rdi
movq %rdi, -0x128(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x489a0
movq -0x128(%rbp), %rdi
callq 0x47730
jmp 0x45bf1
leaq -0x98(%rbp), %rdi
callq 0x36420
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x36420
jmp 0x45dcb
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x130(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x489f0
movq -0x130(%rbp), %rdi
callq 0x47780
jmp 0x45c44
leaq -0xa8(%rbp), %rdi
callq 0x364e0
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x364e0
jmp 0x45dcb
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x138(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x48a40
movq -0x138(%rbp), %rdi
callq 0x47840
jmp 0x45c97
leaq -0xb8(%rbp), %rdi
callq 0x365a0
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x365a0
jmp 0x45dcb
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x140(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x48a90
movq -0x140(%rbp), %rdi
callq 0x478c0
jmp 0x45cea
leaq -0xc8(%rbp), %rdi
callq 0x36670
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x36670
jmp 0x45dcb
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x148(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x48ae0
movq -0x148(%rbp), %rdi
callq 0x479f0
jmp 0x45d3d
leaq -0xd8(%rbp), %rdi
callq 0x36740
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x36740
jmp 0x45dcb
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x48b30
movq -0x150(%rbp), %rdi
callq 0x47c50
jmp 0x45d8a
leaq -0xe8(%rbp), %rdi
callq 0x36890
jmp 0x45db4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x36890
jmp 0x45dcb
jmp 0x45db4
leaq -0x28(%rbp), %rdi
callq 0x36010
leaq -0x10(%rbp), %rdi
callq 0x48b80
jmp 0x459e6
leaq -0x28(%rbp), %rdi
callq 0x36010
jmp 0x45ddf
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x5610
nopl (%rax,%rax)