// File: /workspace/github_cpp_makefile_star2_O1/kodejuice[P]chip8-emulator/./debug/disassembler.cc
// Function: decode[abi:cxx11](int, unsigned char, unsigned char)
string decode(int i, byte msb, byte lsb) {
	char ln[20];
	sprintf(ln, "%04x:  %02x %02x  =>  ", i, msb, lsb);
	string str = ln;

	byte nib = msb >> 4;

	switch (nib)
	{
		case 0x0: 
			switch (lsb)
			{
				case 0xe0: {sprintf(ln,"%s","clear"), str+=ln;} break;
				case 0xee: {sprintf(ln,"%s","ret"), str+=ln;} break;
				default: {sprintf(ln,"unknown"), str+=ln;} break;
			}
			break;
		case 0x1: {sprintf(ln,"%s 0x%03x", "jmp", ADDR), str+=ln;} break;
		case 0x2: {sprintf(ln,"%s 0x%02x", "call", ADDR), str+=ln;} break;
		case 0x3: {sprintf(ln,"%s V%01X, 0x%02x", "jeq", msb&0xf, lsb), str+=ln;} break;
		case 0x4: {sprintf(ln,"%s V%01X, 0x%02x", "jneq", msb&0xf, lsb), str+=ln;} break;
		case 0x5: {sprintf(ln,"%s V%01X, V%01X", "jeqr", msb&0xf, lsb>>4), str+=ln;} break;
		case 0x6: {sprintf(ln,"%s V%01X, 0x%02x", "mov", msb&0xf, lsb), str+=ln;} break;
		case 0x7: {sprintf(ln,"%s V%01X, 0x%02x", "add", msb&0xf, lsb), str+=ln;} break;
		case 0x8:
			{
				byte lastnib = lsb&0xf;
				switch(lastnib)
				{
					case 0: {sprintf(ln,"%s V%01X, V%01X", "mov", msb&0xf, lsb>>4), str+=ln;} break;
					case 1: {sprintf(ln,"%s V%01X, V%01X", "or", msb&0xf, lsb>>4), str+=ln;} break;
					case 2: {sprintf(ln,"%s V%01X, V%01X", "and", msb&0xf, lsb>>4), str+=ln;} break;
					case 3: {sprintf(ln,"%s V%01X, V%01X", "xor", msb&0xf, lsb>>4), str+=ln;} break;
					case 4: {sprintf(ln,"%s V%01X, V%01X", "addr", msb&0xf, lsb>>4), str+=ln;} break;
					case 5: {sprintf(ln,"%s V%01X, V%01X", "sub", msb&0xf, lsb>>4), str+=ln;} break;
					case 6: {sprintf(ln,"%s V%01X, V%01X", "shr", msb&0xf, lsb>>4), str+=ln;} break;
					case 7: {sprintf(ln,"%s V%01X, V%01X", "subb", msb&0xf, lsb>>4), str+=ln;} break;
					case 0xe: {sprintf(ln,"%s V%01X, V%01X", "shl", msb&0xf, lsb>>4), str+=ln;} break;
					default: {sprintf(ln,"unknown"), str+=ln;} break;
				}
			}
			break;
		case 0x9: {sprintf(ln,"%s V%01X, V%01X", "jneqr", msb&0xf, lsb>>4), str+=ln;} break;
		case 0xa: {sprintf(ln,"%s I, [0x%03x]", "mov", ADDR), str+=ln;} break;
		case 0xb: {sprintf(ln,"%s 0x%03x+(V0)", "jmp", ADDR), str+=ln;} break;
		case 0xc: {sprintf(ln,"%s V%01X, 0x%02X", "rand", msb&0xf, lsb), str+=ln;} break;
		case 0xd: {sprintf(ln,"%s V%01X, V%01X, 0x%01x", "draw", msb&0xf, lsb>>4, lsb&0xf), str+=ln;} break;
		case 0xe: 
			switch(lsb)
			{
				case 0x9E: {sprintf(ln,"%s V%01X", "jkey", msb&0xf), str+=ln;} break;
				case 0xA1: {sprintf(ln,"%s V%01X", "jnkey", msb&0xf), str+=ln;} break;
				default: {sprintf(ln,"unknown"), str+=ln;} break;
			}
			break;
		case 0xf: 
			switch(lsb)
			{
				case 0x07: {sprintf(ln,"%s V%01X", "getdelay", msb&0xf), str+=ln;} break;
				case 0x0a: {sprintf(ln,"%s V%01X", "waitkey", msb&0xf), str+=ln;} break;
				case 0x15: {sprintf(ln,"%s V%01X", "setdelay", msb&0xf), str+=ln;} break;
				case 0x18: {sprintf(ln,"%s V%01X", "setsound", msb&0xf), str+=ln;} break;
				case 0x1e: {sprintf(ln,"%s I, V%01X", "mov", msb&0xf), str+=ln;} break;
				case 0x29: {sprintf(ln,"%s I, V%01X", "spritei", msb&0xf), str+=ln;} break;
				case 0x33: {sprintf(ln,"%s [I], V%01X", "bcd", msb&0xf), str+=ln;} break;
				case 0x55: {sprintf(ln,"%s [I], V0-V%01X", "mov", msb&0xf), str+=ln;} break;
				case 0x65: {sprintf(ln,"%s V0-V%01X, [I]", "mov", msb&0xf), str+=ln;} break;
				default: {sprintf(ln,"unknown"), str+=ln;} break;
			}
			break;
	}

	return str;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movl %ecx, %r14d
movl %edx, %ebp
movl %esi, %edx
movq %rdi, %rbx
leaq 0x243d(%rip), %rsi      # 0x5264
movq %rsp, %r15
movq %r15, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x20d0
leaq 0x10(%rbx), %r12
movq %r12, (%rbx)
movq %r15, %rdi
callq 0x2180
leaq (%rsp,%rax), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x40c6
movl %ebp, %eax
shrb $0x4, %al
movzbl %al, %eax
leaq 0x221a(%rip), %rcx      # 0x5080
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $-0x12, %r14b
je 0x30c7
movzbl %r14b, %eax
cmpl $0xe0, %eax
jne 0x3114
movw $0x72, 0x4(%rsp)
movl $0x61656c63, (%rsp)     # imm = 0x61656C63
jmp 0x319b
cmpb $-0x5f, %r14b
je 0x30b1
movzbl %r14b, %eax
cmpl $0x9e, %eax
jne 0x3114
andl $0xf, %ebp
leaq 0x2488(%rip), %rsi      # 0x5346
leaq 0x248a(%rip), %rdx      # 0x534f
jmp 0x318f
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x242a(%rip), %rsi      # 0x5304
jmp 0x2fba
andl $0xf, %ebp
leaq 0x23b5(%rip), %rsi      # 0x529e
leaq 0x23c3(%rip), %rdx      # 0x52b3
jmp 0x301e
andl $0xf, %ebp
leaq 0x2414(%rip), %rsi      # 0x5313
leaq 0x241e(%rip), %rdx      # 0x5324
jmp 0x301e
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x239f(%rip), %rsi      # 0x52b8
leaq 0x23cf(%rip), %rdx      # 0x52ef
jmp 0x301e
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x235a(%rip), %rsi      # 0x528f
leaq 0x235d(%rip), %rdx      # 0x5299
jmp 0x318f
movzbl %r14b, %eax
cmpl $0x1d, %eax
jle 0x3088
cmpl $0x32, %eax
jle 0x30f3
cmpl $0x33, %eax
je 0x317e
cmpl $0x55, %eax
je 0x320d
cmpl $0x65, %eax
jne 0x3114
andl $0xf, %ebp
leaq 0x2438(%rip), %rsi      # 0x53b4
jmp 0x3042
andl $0xf, %ebp
leaq 0x2313(%rip), %rsi      # 0x529e
leaq 0x231d(%rip), %rdx      # 0x52af
jmp 0x301e
andl $0xf, %ebp
leaq 0x22fd(%rip), %rsi      # 0x529e
leaq 0x2329(%rip), %rdx      # 0x52d1
jmp 0x301e
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x22c7(%rip), %rsi      # 0x5281
leaq 0x22ca(%rip), %rdx      # 0x528b
jmp 0x318f
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x22e4(%rip), %rsi      # 0x52b8
leaq 0x22ed(%rip), %rdx      # 0x52c8
jmp 0x301e
andl $0xf, %ebp
movl %r14d, %r8d
shrl $0x4, %r8d
andl $0xf, %r14d
leaq 0x2337(%rip), %rsi      # 0x5329
leaq 0x2348(%rip), %rdx      # 0x5341
movq %rsp, %rdi
movl %ebp, %ecx
movl %r14d, %r9d
xorl %eax, %eax
callq 0x20d0
jmp 0x319b
andl $0xf, %ebp
leaq 0x2287(%rip), %rsi      # 0x529e
leaq 0x22af(%rip), %rdx      # 0x52cd
movq %rsp, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x20d0
jmp 0x319b
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x22b3(%rip), %rsi      # 0x52f5
leaq 0x2284(%rip), %rdx      # 0x52cd
jmp 0x318f
movl %r14d, %eax
andb $0xf, %al
cmpb $0xe, %al
ja 0x327e
movzbl %al, %eax
leaq 0x205b(%rip), %rcx      # 0x50c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x223c(%rip), %rsi      # 0x52b8
leaq 0x224a(%rip), %rdx      # 0x52cd
jmp 0x325f
cmpl $0x14, %eax
jg 0x30d3
cmpl $0x7, %eax
je 0x313e
cmpl $0xa, %eax
jne 0x3114
andl $0xf, %ebp
leaq 0x22a1(%rip), %rsi      # 0x5346
leaq 0x22b7(%rip), %rdx      # 0x5363
jmp 0x318f
andl $0xf, %ebp
leaq 0x228b(%rip), %rsi      # 0x5346
leaq 0x2292(%rip), %rdx      # 0x5354
jmp 0x318f
movl $0x746572, (%rsp)       # imm = 0x746572
jmp 0x319b
cmpl $0x15, %eax
je 0x3151
cmpl $0x18, %eax
jne 0x3114
andl $0xf, %ebp
leaq 0x225f(%rip), %rsi      # 0x5346
leaq 0x2286(%rip), %rdx      # 0x5374
jmp 0x318f
cmpl $0x1e, %eax
je 0x31b6
cmpl $0x29, %eax
jne 0x3114
andl $0xf, %ebp
leaq 0x2272(%rip), %rsi      # 0x537d
leaq 0x2277(%rip), %rdx      # 0x5389
jmp 0x318f
movabsq $0x6e776f6e6b6e75, %rax # imm = 0x6E776F6E6B6E75
movq %rax, (%rsp)
jmp 0x319b
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2186(%rip), %rsi      # 0x52b8
leaq 0x21ec(%rip), %rdx      # 0x5325
jmp 0x325f
andl $0xf, %ebp
leaq 0x21fe(%rip), %rsi      # 0x5346
leaq 0x220b(%rip), %rdx      # 0x535a
jmp 0x318f
andl $0xf, %ebp
leaq 0x21eb(%rip), %rsi      # 0x5346
leaq 0x2209(%rip), %rdx      # 0x536b
jmp 0x318f
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2146(%rip), %rsi      # 0x52b8
leaq 0x2165(%rip), %rdx      # 0x52de
jmp 0x325f
andl $0xf, %ebp
leaq 0x2209(%rip), %rsi      # 0x5391
leaq 0x2210(%rip), %rdx      # 0x539f
movq %rsp, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x20d0
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x23d0
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
andl $0xf, %ebp
leaq 0x21bd(%rip), %rsi      # 0x537d
jmp 0x3042
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x20e5(%rip), %rsi      # 0x52b8
leaq 0x20fc(%rip), %rdx      # 0x52d6
jmp 0x325f
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x20cb(%rip), %rsi      # 0x52b8
leaq 0x20ee(%rip), %rdx      # 0x52e2
jmp 0x325f
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x20b4(%rip), %rsi      # 0x52b8
leaq 0x20db(%rip), %rdx      # 0x52e6
jmp 0x325f
andl $0xf, %ebp
leaq 0x218c(%rip), %rsi      # 0x53a3
jmp 0x3042
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x208e(%rip), %rsi      # 0x52b8
leaq 0x20a4(%rip), %rdx      # 0x52d5
jmp 0x325f
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2077(%rip), %rsi      # 0x52b8
leaq 0x2091(%rip), %rdx      # 0x52d9
jmp 0x325f
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2060(%rip), %rsi      # 0x52b8
leaq 0x208c(%rip), %rdx      # 0x52eb
movq %rsp, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x20d0
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x23d0
jmp 0x31a6
movabsq $0x6e776f6e6b6e75, %rax # imm = 0x6E776F6E6B6E75
movq %rax, (%rsp)
jmp 0x326e
jmp 0x3290
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r12, %rdi
je 0x32a7
movq (%r12), %rsi
incq %rsi
callq 0x2280
movq %r14, %rdi
callq 0x23a0