// File: /workspace/github_cpp_makefile_star2_O3/sangwoojun[P]rv32emulator/emulator.cpp
// Function: parse_reg(char*, int, bool)
int parse_reg(char* tok, int line, bool strict = true) {
	if ( tok[0] == 'x' ) {
		int ri = atoi(tok+1);
		if ( ri < 0 || ri > 32 ) {
			if ( strict ) print_syntax_error(line, "Malformed register name");
			return -1;
		}
		return ri;
	}
	if ( streq(tok, "zero") ) return 0; 
	if ( streq(tok, "ra") ) return 1;
	if ( streq(tok, "sp") ) return 2;
	if ( streq(tok, "gp") ) return 3;
	if ( streq(tok, "tp") ) return 4;
	if ( streq(tok, "t0") ) return 5;
	if ( streq(tok, "t1") ) return 6;
	if ( streq(tok, "t2") ) return 7;
	if ( streq(tok, "s0") ) return 8;
	if ( streq(tok, "s1") ) return 9;
	if ( streq(tok, "a0") ) return 10;
	if ( streq(tok, "a1") ) return 11;
	if ( streq(tok, "a2") ) return 12;
	if ( streq(tok, "a3") ) return 13;
	if ( streq(tok, "a4") ) return 14;
	if ( streq(tok, "a5") ) return 15;
	if ( streq(tok, "a6") ) return 16;
	if ( streq(tok, "a7") ) return 17;
	if ( streq(tok, "s2") ) return 18;
	if ( streq(tok, "s3") ) return 19;
	if ( streq(tok, "s4") ) return 20;
	if ( streq(tok, "s5") ) return 21;
	if ( streq(tok, "s6") ) return 22;
	if ( streq(tok, "s7") ) return 23;
	if ( streq(tok, "s8") ) return 24;
	if ( streq(tok, "s9") ) return 25;
	if ( streq(tok, "s10") ) return 26;
	if ( streq(tok, "s11") ) return 27;
	if ( streq(tok, "t3") ) return 28;
	if ( streq(tok, "t4") ) return 29;
	if ( streq(tok, "t5") ) return 30;
	if ( streq(tok, "t6") ) return 31;

	if ( strict ) print_syntax_error(line, "Malformed register name");
	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r14d
movl %esi, %ebx
movq %rdi, %r15
movzbl (%rdi), %r13d
cmpl $0x78, %r13d
jne 0x2db8
incq %r15
movq %r15, %rdi
callq 0x2310
movl %eax, %ecx
cmpl $0x21, %eax
setae %dl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovbl %ecx, %eax
andb %r14b, %dl
cmpb $0x1, %dl
jne 0x318c
leaq 0x87a2(%rip), %rdi      # 0xb540
leaq 0x884c(%rip), %rdx      # 0xb5f1
movl %ebx, %esi
xorl %eax, %eax
callq 0x2040
movl $0x1, %edi
callq 0x2210
leaq 0x8947(%rip), %rsi      # 0xb706
movq %r15, %rdi
callq 0x2280
testl %eax, %eax
je 0x2e0d
xorl %eax, %eax
cmpl $0x72, %r13d
jg 0x2e14
cmpl $0x67, %r13d
je 0x2e7f
movl $0x0, %r12d
cmpl $0x72, %r13d
jne 0x2edb
cmpb $0x61, 0x1(%r15)
jne 0x2e91
cmpb $0x0, 0x2(%r15)
jne 0x2e91
movl $0x1, %eax
jmp 0x318c
xorl %eax, %eax
jmp 0x318c
cmpl $0x73, %r13d
je 0x2e99
movl $0x0, %r12d
cmpl $0x74, %r13d
jne 0x2edb
cmpb $0x70, 0x1(%r15)
jne 0x2e3c
cmpb $0x0, 0x2(%r15)
je 0x30c3
cmpb $0x30, 0x1(%r15)
jne 0x2e4e
cmpb $0x0, 0x2(%r15)
je 0x30eb
cmpb $0x31, 0x1(%r15)
jne 0x2e60
cmpb $0x0, 0x2(%r15)
je 0x3109
cmpb $0x32, 0x1(%r15)
jne 0x2ed6
movb $0x1, %r12b
cmpb $0x0, 0x2(%r15)
jne 0x300d
movl $0x7, %eax
jmp 0x318c
cmpb $0x70, 0x1(%r15)
jne 0x2e91
cmpb $0x0, 0x2(%r15)
je 0x30cd
xorl %r12d, %r12d
jmp 0x300d
cmpb $0x70, 0x1(%r15)
jne 0x2eab
cmpb $0x0, 0x2(%r15)
je 0x30d7
cmpb $0x30, 0x1(%r15)
jne 0x2ebd
cmpb $0x0, 0x2(%r15)
je 0x30f5
movb $0x1, %al
cmpb $0x31, 0x1(%r15)
jne 0x2ed1
cmpb $0x0, 0x2(%r15)
je 0x3110
xorl %r12d, %r12d
jmp 0x2edb
movb $0x1, %r12b
xorl %eax, %eax
cmpl $0x61, %r13d
jne 0x2f75
cmpb $0x30, 0x1(%r15)
jne 0x2ef7
cmpb $0x0, 0x2(%r15)
je 0x30e1
cmpb $0x31, 0x1(%r15)
jne 0x2f09
cmpb $0x0, 0x2(%r15)
je 0x30ff
cmpb $0x32, 0x1(%r15)
jne 0x2f1b
cmpb $0x0, 0x2(%r15)
je 0x3117
cmpb $0x33, 0x1(%r15)
jne 0x2f2d
cmpb $0x0, 0x2(%r15)
je 0x3125
cmpb $0x34, 0x1(%r15)
jne 0x2f3f
cmpb $0x0, 0x2(%r15)
je 0x313a
cmpb $0x35, 0x1(%r15)
jne 0x2f51
cmpb $0x0, 0x2(%r15)
je 0x314f
cmpb $0x36, 0x1(%r15)
jne 0x2f63
cmpb $0x0, 0x2(%r15)
je 0x3164
cmpb $0x37, 0x1(%r15)
jne 0x2f75
cmpb $0x0, 0x2(%r15)
je 0x3172
testb %al, %al
je 0x300d
cmpb $0x32, 0x1(%r15)
jne 0x2f8f
cmpb $0x0, 0x2(%r15)
je 0x311e
cmpb $0x33, 0x1(%r15)
jne 0x2fa1
cmpb $0x0, 0x2(%r15)
je 0x3133
cmpb $0x34, 0x1(%r15)
jne 0x2fb3
cmpb $0x0, 0x2(%r15)
je 0x3148
cmpb $0x35, 0x1(%r15)
jne 0x2fc5
cmpb $0x0, 0x2(%r15)
je 0x315d
cmpb $0x36, 0x1(%r15)
jne 0x2fd7
cmpb $0x0, 0x2(%r15)
je 0x316b
cmpb $0x37, 0x1(%r15)
jne 0x2fe9
cmpb $0x0, 0x2(%r15)
je 0x3179
cmpb $0x38, 0x1(%r15)
jne 0x2ffb
cmpb $0x0, 0x2(%r15)
je 0x3180
cmpb $0x39, 0x1(%r15)
jne 0x300d
cmpb $0x0, 0x2(%r15)
je 0x3187
leaq 0x85f5(%rip), %rsi      # 0xb609
movq %r15, %rdi
callq 0x2280
testl %eax, %eax
je 0x309c
leaq 0x85e6(%rip), %rsi      # 0xb60d
movq %r15, %rdi
callq 0x2280
testl %eax, %eax
je 0x30b9
testb %r12b, %r12b
je 0x30a6
cmpb $0x33, 0x1(%r15)
jne 0x304e
cmpb $0x0, 0x2(%r15)
je 0x312c
cmpb $0x34, 0x1(%r15)
jne 0x3060
cmpb $0x0, 0x2(%r15)
je 0x3141
cmpb $0x35, 0x1(%r15)
jne 0x3072
cmpb $0x0, 0x2(%r15)
je 0x3156
cmpb $0x36, 0x1(%r15)
jne 0x30a6
xorl %eax, %eax
cmpb $0x0, 0x2(%r15)
setne %cl
andb %cl, %r14b
cmpb $0x1, %r14b
je 0x2d97
movb %cl, %al
negl %eax
orl $0x1f, %eax
jmp 0x318c
movl $0x1a, %eax
jmp 0x318c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %r14b, %r14b
je 0x318c
jmp 0x2d97
movl $0x1b, %eax
jmp 0x318c
movl $0x4, %eax
jmp 0x318c
movl $0x3, %eax
jmp 0x318c
movl $0x2, %eax
jmp 0x318c
movl $0xa, %eax
jmp 0x318c
movl $0x5, %eax
jmp 0x318c
movl $0x8, %eax
jmp 0x318c
movl $0xb, %eax
jmp 0x318c
movl $0x6, %eax
jmp 0x318c
movl $0x9, %eax
jmp 0x318c
movl $0xc, %eax
jmp 0x318c
movl $0x12, %eax
jmp 0x318c
movl $0xd, %eax
jmp 0x318c
movl $0x1c, %eax
jmp 0x318c
movl $0x13, %eax
jmp 0x318c
movl $0xe, %eax
jmp 0x318c
movl $0x1d, %eax
jmp 0x318c
movl $0x14, %eax
jmp 0x318c
movl $0xf, %eax
jmp 0x318c
movl $0x1e, %eax
jmp 0x318c
movl $0x15, %eax
jmp 0x318c
movl $0x10, %eax
jmp 0x318c
movl $0x16, %eax
jmp 0x318c
movl $0x11, %eax
jmp 0x318c
movl $0x17, %eax
jmp 0x318c
movl $0x18, %eax
jmp 0x318c
movl $0x19, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq