// File: /workspace/github_cpp_makefile_star2_O2/sangwoojun[P]rv32emulator/emulator.cpp
// Function: parse_instr(char*)
instr_type parse_instr(char* tok) {
	// 2r->1r
	if ( streq(tok, "add") ) return ADD;
	if ( streq(tok, "sub") ) return SUB;
	if ( streq(tok, "slt") ) return SLT;
	if ( streq(tok, "sltu") ) return SLTU;
	if ( streq(tok, "and") ) return AND;
	if ( streq(tok, "or") ) return OR;
	if ( streq(tok, "xor") ) return XOR;
	if ( streq(tok, "sll") ) return SLL;
	if ( streq(tok, "srl") ) return SRL;
	if ( streq(tok, "sra") ) return SRA;

	// 1r, imm -> 1r
	if ( streq(tok, "addi") ) return ADDI;
	if ( streq(tok, "slti") ) return SLTI;
	if ( streq(tok, "sltiu") ) return SLTIU;
	if ( streq(tok, "andi") ) return ANDI;
	if ( streq(tok, "ori") ) return ORI;
	if ( streq(tok, "xori") ) return XORI;
	if ( streq(tok, "slli") ) return SLLI;
	if ( streq(tok, "srli") ) return SRLI;
	if ( streq(tok, "srai") ) return SRAI;

	//load/store
	if ( streq(tok, "lb") ) return LB;
	if ( streq(tok, "lbu") ) return LBU;
	if ( streq(tok, "lh") ) return LH;
	if ( streq(tok, "lhu") ) return LHU;
	if ( streq(tok, "lw") ) return LW;
	if ( streq(tok, "sb") ) return SB;
	if ( streq(tok, "sh") ) return SH;
	if ( streq(tok, "sw") ) return SW;

	//branch
	if ( streq(tok, "beq") ) return BEQ;
	if ( streq(tok, "bge") ) return BGE;
	if ( streq(tok, "bgeu") ) return BGEU;
	if ( streq(tok, "blt") ) return BLT;
	if ( streq(tok, "bltu") ) return BLTU;
	if ( streq(tok, "bne") ) return BNE;

	// jal
	if ( streq(tok, "jal") ) return JAL;
	if ( streq(tok, "jalr") ) return JALR;

	// lui
	if ( streq(tok, "auipc") ) return AUIPC;
	if ( streq(tok, "lui") ) return LUI;

	// unimpl
	//if ( streq(tok, "unimpl") ) return UNIMPL;
	if ( streq(tok, "hcf") ) return HCF;
	return UNIMPL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x7cfa(%rip), %rsi      # 0xa56a
callq 0x27c0
testb %al, %al
je 0x2880
pushq $0x1
jmp 0x2c14
leaq 0x7ce7(%rip), %rsi      # 0xa56e
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x289a
pushq $0x22
jmp 0x2c14
leaq 0x7cd1(%rip), %rsi      # 0xa572
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x28b4
pushq $0x1a
jmp 0x2c14
leaq 0x7cbb(%rip), %rsi      # 0xa576
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x28ce
pushq $0x1d
jmp 0x2c14
leaq 0x7ca6(%rip), %rsi      # 0xa57b
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x28e8
pushq $0x3
jmp 0x2c14
leaq 0x7c91(%rip), %rsi      # 0xa580
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2902
pushq $0x14
jmp 0x2c14
leaq 0x7c76(%rip), %rsi      # 0xa57f
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x291c
pushq $0x24
jmp 0x2c14
leaq 0x7c60(%rip), %rsi      # 0xa583
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2936
pushq $0x18
jmp 0x2c14
leaq 0x7c4a(%rip), %rsi      # 0xa587
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2950
pushq $0x20
jmp 0x2c14
leaq 0x7c34(%rip), %rsi      # 0xa58b
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x296a
pushq $0x1e
jmp 0x2c14
leaq 0x7c1e(%rip), %rsi      # 0xa58f
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2984
pushq $0x2
jmp 0x2c14
leaq 0x7c09(%rip), %rsi      # 0xa594
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x299e
pushq $0x1b
jmp 0x2c14
leaq 0x7bf4(%rip), %rsi      # 0xa599
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x29b8
pushq $0x1c
jmp 0x2c14
leaq 0x7be0(%rip), %rsi      # 0xa59f
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x29d2
pushq $0x4
jmp 0x2c14
leaq 0x7bcc(%rip), %rsi      # 0xa5a5
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x29ec
pushq $0x15
jmp 0x2c14
leaq 0x7bb1(%rip), %rsi      # 0xa5a4
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2a06
pushq $0x25
jmp 0x2c14
leaq 0x7b9c(%rip), %rsi      # 0xa5a9
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2a20
pushq $0x19
jmp 0x2c14
leaq 0x7b87(%rip), %rsi      # 0xa5ae
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2a3a
pushq $0x21
jmp 0x2c14
leaq 0x7b72(%rip), %rsi      # 0xa5b3
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2a54
pushq $0x1f
jmp 0x2c14
leaq 0x7b5d(%rip), %rsi      # 0xa5b8
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2a6e
pushq $0xe
jmp 0x2c14
leaq 0x7b46(%rip), %rsi      # 0xa5bb
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2a88
pushq $0xf
jmp 0x2c14
leaq 0x7b30(%rip), %rsi      # 0xa5bf
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2aa2
pushq $0x10
jmp 0x2c14
leaq 0x7b19(%rip), %rsi      # 0xa5c2
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2abc
pushq $0x11
jmp 0x2c14
leaq 0x7b03(%rip), %rsi      # 0xa5c6
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2ad6
pushq $0x13
jmp 0x2c14
leaq 0x7aec(%rip), %rsi      # 0xa5c9
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2af0
pushq $0x16
jmp 0x2c14
leaq 0x7ad5(%rip), %rsi      # 0xa5cc
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2b0a
pushq $0x17
jmp 0x2c14
leaq 0x7abe(%rip), %rsi      # 0xa5cf
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2b24
pushq $0x23
jmp 0x2c14
leaq 0x7aa7(%rip), %rsi      # 0xa5d2
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2b3e
pushq $0x6
jmp 0x2c14
leaq 0x7a91(%rip), %rsi      # 0xa5d6
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2b58
pushq $0x7
jmp 0x2c14
leaq 0x7a7b(%rip), %rsi      # 0xa5da
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2b72
pushq $0x8
jmp 0x2c14
leaq 0x7a66(%rip), %rsi      # 0xa5df
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2b8c
pushq $0x9
jmp 0x2c14
leaq 0x7a50(%rip), %rsi      # 0xa5e3
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2ba3
pushq $0xa
jmp 0x2c14
leaq 0x7a3e(%rip), %rsi      # 0xa5e8
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2bba
pushq $0xb
jmp 0x2c14
leaq 0x7a2b(%rip), %rsi      # 0xa5ec
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2bd1
pushq $0xc
jmp 0x2c14
leaq 0x7a18(%rip), %rsi      # 0xa5f0
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2be8
pushq $0xd
jmp 0x2c14
leaq 0x7a06(%rip), %rsi      # 0xa5f5
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2bff
pushq $0x5
jmp 0x2c14
leaq 0x79f5(%rip), %rsi      # 0xa5fb
movq %rbx, %rdi
callq 0x27c0
testb %al, %al
je 0x2c1c
pushq $0x12
popq %rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x79dc(%rip), %rsi      # 0xa5ff
movq %rbx, %rdi
callq 0x27c0
xorl %ecx, %ecx
testb %al, %al
pushq $0x26
popq %rax
cmovel %ecx, %eax
jmp 0x2c15