// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x18, %rsp
movl %ecx, %r14d
movl %edx, %ebp
movl %esi, %edx
movq %rdi, %rbx
leaq 0x258c(%rip), %rsi      # 0x5214
movq %rsp, %r15
movq %r15, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x20c0
leaq 0x17(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2140
movl %ebp, %eax
shrb $0x4, %al
movzbl %al, %eax
leaq 0x23c7(%rip), %rcx      # 0x5080
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $-0x12, %r14b
je 0x2f30
movzbl %r14b, %eax
cmpl $0xe0, %eax
jne 0x2f07
movw $0x72, 0x4(%rsp)
movl $0x61656c63, (%rsp)     # imm = 0x61656C63
jmp 0x3057
cmpb $-0x5f, %r14b
je 0x2f1a
movzbl %r14b, %eax
cmpl $0x9e, %eax
jne 0x2f07
andl $0xf, %ebp
leaq 0x25e5(%rip), %rsi      # 0x52f6
leaq 0x25e7(%rip), %rdx      # 0x52ff
jmp 0x304b
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x2587(%rip), %rsi      # 0x52b4
jmp 0x2e39
andl $0xf, %ebp
leaq 0x2512(%rip), %rsi      # 0x524e
leaq 0x2520(%rip), %rdx      # 0x5263
jmp 0x2e9d
andl $0xf, %ebp
leaq 0x2571(%rip), %rsi      # 0x52c3
leaq 0x257b(%rip), %rdx      # 0x52d4
jmp 0x2e9d
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x24fc(%rip), %rsi      # 0x5268
leaq 0x252c(%rip), %rdx      # 0x529f
jmp 0x2e9d
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x24b7(%rip), %rsi      # 0x523f
leaq 0x24ba(%rip), %rdx      # 0x5249
jmp 0x304b
cmpb $0x65, %r14b
je 0x2f70
movzbl %r14b, %eax
cmpl $0xa, %eax
je 0x303a
cmpl $0x15, %eax
je 0x2fdc
cmpl $0x18, %eax
je 0x2f3c
cmpl $0x1e, %eax
je 0x2f61
cmpl $0x29, %eax
je 0x2fc9
cmpl $0x33, %eax
je 0x2f7f
cmpl $0x55, %eax
je 0x2f52
cmpl $0x7, %eax
jne 0x2f07
andl $0xf, %ebp
leaq 0x2502(%rip), %rsi      # 0x52f6
leaq 0x250f(%rip), %rdx      # 0x530a
jmp 0x304b
andl $0xf, %ebp
leaq 0x2444(%rip), %rsi      # 0x524e
leaq 0x244e(%rip), %rdx      # 0x525f
jmp 0x2e9d
andl $0xf, %ebp
leaq 0x242e(%rip), %rsi      # 0x524e
leaq 0x245a(%rip), %rdx      # 0x5281
jmp 0x2e9d
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x23f8(%rip), %rsi      # 0x5231
leaq 0x23fb(%rip), %rdx      # 0x523b
jmp 0x304b
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2415(%rip), %rsi      # 0x5268
leaq 0x241e(%rip), %rdx      # 0x5278
jmp 0x2e9d
andl $0xf, %ebp
movl %r14d, %r8d
shrl $0x4, %r8d
andl $0xf, %r14d
leaq 0x2468(%rip), %rsi      # 0x52d9
leaq 0x2479(%rip), %rdx      # 0x52f1
movq %rsp, %rdi
movl %ebp, %ecx
movl %r14d, %r9d
xorl %eax, %eax
callq 0x20c0
jmp 0x3057
andl $0xf, %ebp
leaq 0x23b8(%rip), %rsi      # 0x524e
leaq 0x23e0(%rip), %rdx      # 0x527d
movq %rsp, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x20c0
jmp 0x3057
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x23e4(%rip), %rsi      # 0x52a5
leaq 0x23b5(%rip), %rdx      # 0x527d
jmp 0x304b
movl %r14d, %eax
andb $0xf, %al
cmpb $0xe, %al
ja 0x30cf
movzbl %al, %eax
leaq 0x21dc(%rip), %rcx      # 0x50c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x236d(%rip), %rsi      # 0x5268
leaq 0x237b(%rip), %rdx      # 0x527d
jmp 0x30b3
movabsq $0x6e776f6e6b6e75, %rax # imm = 0x6E776F6E6B6E75
movq %rax, (%rsp)
jmp 0x3057
andl $0xf, %ebp
leaq 0x23d2(%rip), %rsi      # 0x52f6
leaq 0x23d9(%rip), %rdx      # 0x5304
jmp 0x304b
movl $0x746572, (%rsp)       # imm = 0x746572
jmp 0x3057
andl $0xf, %ebp
leaq 0x23b0(%rip), %rsi      # 0x52f6
leaq 0x23d7(%rip), %rdx      # 0x5324
jmp 0x304b
andl $0xf, %ebp
leaq 0x23f7(%rip), %rsi      # 0x5353
jmp 0x2ec1
andl $0xf, %ebp
leaq 0x23c2(%rip), %rsi      # 0x532d
jmp 0x2ec1
andl $0xf, %ebp
leaq 0x23ea(%rip), %rsi      # 0x5364
jmp 0x2ec1
andl $0xf, %ebp
leaq 0x23b8(%rip), %rsi      # 0x5341
leaq 0x23bf(%rip), %rdx      # 0x534f
jmp 0x304b
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x22c5(%rip), %rsi      # 0x5268
leaq 0x232b(%rip), %rdx      # 0x52d5
jmp 0x30b3
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x22ab(%rip), %rsi      # 0x5268
leaq 0x22ca(%rip), %rdx      # 0x528e
jmp 0x30b3
andl $0xf, %ebp
leaq 0x235a(%rip), %rsi      # 0x532d
leaq 0x235f(%rip), %rdx      # 0x5339
jmp 0x304b
andl $0xf, %ebp
leaq 0x2310(%rip), %rsi      # 0x52f6
leaq 0x232e(%rip), %rdx      # 0x531b
jmp 0x304b
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x226b(%rip), %rsi      # 0x5268
leaq 0x2282(%rip), %rdx      # 0x5286
jmp 0x30b3
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2251(%rip), %rsi      # 0x5268
leaq 0x2274(%rip), %rdx      # 0x5292
jmp 0x30b3
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2237(%rip), %rsi      # 0x5268
leaq 0x225e(%rip), %rdx      # 0x5296
jmp 0x30b3
andl $0xf, %ebp
leaq 0x22b2(%rip), %rsi      # 0x52f6
leaq 0x22c8(%rip), %rdx      # 0x5313
movq %rsp, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x20c0
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x23c0
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x21ea(%rip), %rsi      # 0x5268
leaq 0x2200(%rip), %rdx      # 0x5285
jmp 0x30b3
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x21d3(%rip), %rsi      # 0x5268
leaq 0x21ed(%rip), %rdx      # 0x5289
jmp 0x30b3
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x21bc(%rip), %rsi      # 0x5268
leaq 0x21e8(%rip), %rdx      # 0x529b
movq %rsp, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x20c0
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x23c0
jmp 0x3062
movabsq $0x6e776f6e6b6e75, %rax # imm = 0x6E776F6E6B6E75
movq %rax, (%rsp)
jmp 0x30c2
jmp 0x30e1
movq %rax, %r14
movq %rbx, %rdi
callq 0x2170
movq %r14, %rdi
callq 0x23a0