// File: /workspace/github_cpp_makefile_star2_O3/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 0x2477(%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 0x4098
movl %ebp, %eax
shrb $0x4, %al
movzbl %al, %eax
leaq 0x2254(%rip), %rcx      # 0x5080
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $-0x12, %r14b
je 0x308d
movzbl %r14b, %eax
cmpl $0xe0, %eax
jne 0x30da
movw $0x72, 0x4(%rsp)
movl $0x61656c63, (%rsp)     # imm = 0x61656C63
jmp 0x3161
cmpb $-0x5f, %r14b
je 0x3077
movzbl %r14b, %eax
cmpl $0x9e, %eax
jne 0x30da
andl $0xf, %ebp
leaq 0x24c2(%rip), %rsi      # 0x5346
leaq 0x24c4(%rip), %rdx      # 0x534f
jmp 0x3155
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x2464(%rip), %rsi      # 0x5304
jmp 0x2f80
andl $0xf, %ebp
leaq 0x23ef(%rip), %rsi      # 0x529e
leaq 0x23fd(%rip), %rdx      # 0x52b3
jmp 0x2fe4
andl $0xf, %ebp
leaq 0x244e(%rip), %rsi      # 0x5313
leaq 0x2458(%rip), %rdx      # 0x5324
jmp 0x2fe4
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x23d9(%rip), %rsi      # 0x52b8
leaq 0x2409(%rip), %rdx      # 0x52ef
jmp 0x2fe4
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x2394(%rip), %rsi      # 0x528f
leaq 0x2397(%rip), %rdx      # 0x5299
jmp 0x3155
movzbl %r14b, %eax
cmpl $0x1d, %eax
jle 0x304e
cmpl $0x32, %eax
jle 0x30b9
cmpl $0x33, %eax
je 0x3144
cmpl $0x55, %eax
je 0x31d3
cmpl $0x65, %eax
jne 0x30da
andl $0xf, %ebp
leaq 0x2472(%rip), %rsi      # 0x53b4
jmp 0x3008
andl $0xf, %ebp
leaq 0x234d(%rip), %rsi      # 0x529e
leaq 0x2357(%rip), %rdx      # 0x52af
jmp 0x2fe4
andl $0xf, %ebp
leaq 0x2337(%rip), %rsi      # 0x529e
leaq 0x2363(%rip), %rdx      # 0x52d1
jmp 0x2fe4
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x2301(%rip), %rsi      # 0x5281
leaq 0x2304(%rip), %rdx      # 0x528b
jmp 0x3155
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x231e(%rip), %rsi      # 0x52b8
leaq 0x2327(%rip), %rdx      # 0x52c8
jmp 0x2fe4
andl $0xf, %ebp
movl %r14d, %r8d
shrl $0x4, %r8d
andl $0xf, %r14d
leaq 0x2371(%rip), %rsi      # 0x5329
leaq 0x2382(%rip), %rdx      # 0x5341
movq %rsp, %rdi
movl %ebp, %ecx
movl %r14d, %r9d
xorl %eax, %eax
callq 0x20d0
jmp 0x3161
andl $0xf, %ebp
leaq 0x22c1(%rip), %rsi      # 0x529e
leaq 0x22e9(%rip), %rdx      # 0x52cd
movq %rsp, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x20d0
jmp 0x3161
andl $0xf, %ebp
shll $0x8, %ebp
orl %r14d, %ebp
leaq 0x22ed(%rip), %rsi      # 0x52f5
leaq 0x22be(%rip), %rdx      # 0x52cd
jmp 0x3155
movl %r14d, %eax
andb $0xf, %al
cmpb $0xe, %al
ja 0x3244
movzbl %al, %eax
leaq 0x2095(%rip), %rcx      # 0x50c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2276(%rip), %rsi      # 0x52b8
leaq 0x2284(%rip), %rdx      # 0x52cd
jmp 0x3225
cmpl $0x14, %eax
jg 0x3099
cmpl $0x7, %eax
je 0x3104
cmpl $0xa, %eax
jne 0x30da
andl $0xf, %ebp
leaq 0x22db(%rip), %rsi      # 0x5346
leaq 0x22f1(%rip), %rdx      # 0x5363
jmp 0x3155
andl $0xf, %ebp
leaq 0x22c5(%rip), %rsi      # 0x5346
leaq 0x22cc(%rip), %rdx      # 0x5354
jmp 0x3155
movl $0x746572, (%rsp)       # imm = 0x746572
jmp 0x3161
cmpl $0x15, %eax
je 0x3117
cmpl $0x18, %eax
jne 0x30da
andl $0xf, %ebp
leaq 0x2299(%rip), %rsi      # 0x5346
leaq 0x22c0(%rip), %rdx      # 0x5374
jmp 0x3155
cmpl $0x1e, %eax
je 0x317c
cmpl $0x29, %eax
jne 0x30da
andl $0xf, %ebp
leaq 0x22ac(%rip), %rsi      # 0x537d
leaq 0x22b1(%rip), %rdx      # 0x5389
jmp 0x3155
movabsq $0x6e776f6e6b6e75, %rax # imm = 0x6E776F6E6B6E75
movq %rax, (%rsp)
jmp 0x3161
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x21c0(%rip), %rsi      # 0x52b8
leaq 0x2226(%rip), %rdx      # 0x5325
jmp 0x3225
andl $0xf, %ebp
leaq 0x2238(%rip), %rsi      # 0x5346
leaq 0x2245(%rip), %rdx      # 0x535a
jmp 0x3155
andl $0xf, %ebp
leaq 0x2225(%rip), %rsi      # 0x5346
leaq 0x2243(%rip), %rdx      # 0x536b
jmp 0x3155
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2180(%rip), %rsi      # 0x52b8
leaq 0x219f(%rip), %rdx      # 0x52de
jmp 0x3225
andl $0xf, %ebp
leaq 0x2243(%rip), %rsi      # 0x5391
leaq 0x224a(%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 0x21f7(%rip), %rsi      # 0x537d
jmp 0x3008
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x211f(%rip), %rsi      # 0x52b8
leaq 0x2136(%rip), %rdx      # 0x52d6
jmp 0x3225
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x2105(%rip), %rsi      # 0x52b8
leaq 0x2128(%rip), %rdx      # 0x52e2
jmp 0x3225
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x20ee(%rip), %rsi      # 0x52b8
leaq 0x2115(%rip), %rdx      # 0x52e6
jmp 0x3225
andl $0xf, %ebp
leaq 0x21c6(%rip), %rsi      # 0x53a3
jmp 0x3008
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x20c8(%rip), %rsi      # 0x52b8
leaq 0x20de(%rip), %rdx      # 0x52d5
jmp 0x3225
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x20b1(%rip), %rsi      # 0x52b8
leaq 0x20cb(%rip), %rdx      # 0x52d9
jmp 0x3225
andl $0xf, %ebp
shrl $0x4, %r14d
leaq 0x209a(%rip), %rsi      # 0x52b8
leaq 0x20c6(%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 0x316c
movabsq $0x6e776f6e6b6e75, %rax # imm = 0x6E776F6E6B6E75
movq %rax, (%rsp)
jmp 0x3234
jmp 0x3256
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r12, %rdi
je 0x326d
movq (%r12), %rsi
incq %rsi
callq 0x2280
movq %r14, %rdi
callq 0x23a0