// File: kodejuice[P]chip8-emulator/./chip8.cc
// Function: Chip8::emulate_op()
void Chip8::emulate_op() {
	#define not_handled(m,l)\
		printf("\nUnrecognized instruction: %04x %04x\n", m,l); exit(2);

	int tmp;
	int opcode = (memory[PC] << 8) | memory[PC+1];
	int msb = opcode>>8, lsb = opcode&0xff;

    // printf("(%x) %x %x | pc = %x\n", opcode, memory[PC], memory[PC+1], PC);

	// Get bit-fields from instruction/opcode
	int u   = (opcode>>12) & 0xF,
		x   = (opcode>>8) & 0xF,
		y   = (opcode>>4) & 0xF,
		kk  = (opcode) & 0xFF,
		n   = (opcode) & 0xF,
		nnn = (opcode) & 0xFFF;

	// alliases for common registers
	byte &Vx = V[x], &Vy = V[y], &VF = V[0xF];

	switch (msb >> 4) {
		// 0x0e-
		case 0x0: {
			switch (lsb&0xf) {
				// 0x00e0
				case 0x0: // clr
					memset(screen, 0, 2048);
					redraw = true;
					PC += 2;
					break;

				// 0x00ee
				case 0xe: // ret
					PC = stack[--sp] + 2;
					break;

				default:
					not_handled(msb, lsb);
			}
		}
		break;

		// 0x1nnn
		case 0x1: // jmp nnn
			PC = nnn;
			break;

		// 0x2nnn
		case 0x2: // call nnn
			stack[sp++] = PC;
			PC = nnn;
			break;

		// 03xkk
		case 0x3: // jeq Vx, Vkk
			if (Vx == kk) PC += 2;
			PC += 2;
			break;

		// 0x4xkk
		case 0x4: //jneq Vx, Vkk
			if (Vx != kk) PC += 2;
			PC += 2;
			break;

		// 0x5xy0
		case 0x5: // jeqr Vx, Vy
			if (Vx == Vy) PC += 2;
			PC += 2;
			break;

		// 0x6xkk
		case 0x6: // mov Vx, kk
			Vx = kk;
			PC += 2;
			break;

		// 0x7xkk
		case 0x7: // add Vx, kk
            Vx += kk;
			PC += 2;
			break;

		// 0x8xyn
		case 0x8: {
			switch (lsb & 0xf) {
				// 0x8xy0
				case 0x0: // mov Vx, Vy
					Vx = Vy;
					PC += 2;
					break;

				// 0x8xy1
				case 0x1: // or Vx, Vy
					Vx |= Vy;
					PC += 2;
					break;

				// 0x8xy2
				case 0x2: // and Vx, Vy
					Vx &= Vy;
					PC += 2;
					break;

				// 0x8xy3
				case 0x3: // xor Vx, Vy
					Vx ^= Vy;
					PC += 2;
					break;

				// 0x8xy4
				case 0x4: // addr Vx, Vy
					tmp = Vx + Vy;
					VF = (tmp > 0xff);
					Vx += Vy;
					PC += 2;
					break;

				// 0x8xy5
				case 0x5: // sub Vx, Vy
					VF = Vx > Vy;
					Vx -= Vy;
					PC += 2;
					break;

				// 0x8xy6
				case 0x6: // shr Vx
					VF = Vx&1;
					Vx >>= 1;
					PC += 2;
					break;

				// 0x8xy7
				case 0x7: // subb Vy, Vx
					VF = Vy > Vx;
					Vy -= Vx;
					PC += 2;
					break;

				// 0x8ye
				case 0xe: // shl Vx
					VF = Vx >> 7;
					Vx <<= 1;
					PC += 2;
					break;

				default:
					not_handled(msb, lsb);
			}
		}
		break;

		// 9xy0
		case 0x9: // jneqr Vx, Vy
			if (Vx != Vy) PC += 2;
			PC += 2;
			break;

		// Annn
		case 0xA: // mov I, nnn
			I = nnn;
			PC += 2;
			break;

		// 0xBnnn
		case 0xB: // jmp V0+nnn
			PC = V[0] + nnn;
			break;

		// 0xCxkk
		case 0xC: // rnd Vx, kk
			Vx = uniform_int_distribution<>(0, 255)(rnd) & kk;
			PC += 2;
			break;

		// 0xDxyn
		case 0xD: { // draw Vx, Vy, n
			/*
				Read n bytes from memory, starting at the address stored in I.
				These bytes are then displayed as sprites on screen at coordinates (Vx, Vy), with width = 8 and height = n.
				Sprites are XORed onto the existing screen. If this causes any pixels to be erased, VF is set to 1, otherwise it is set to 0.
				If the sprite is positioned so part of it is outside the coordinates of the display, it wraps around to the opposite side of the screen.
			*/
			byte width = 8,
				height = n,
				*row_pixels = &memory[I];

			int px, py;
			for (int h = 0; h < height; ++h) {
				py = (Vy + h) % 32;

				for (int w = 0; w < width; ++w) {
					px = (Vx + w) % 64;

					if (*row_pixels & (0b10000000 >> w)) { // checks if (8-w)'th bit is set
						byte &pixel = screen[64*py + px];

						VF = (pixel == 1),
						pixel ^= 1;
					}
				}
				++row_pixels;
			}
			redraw = true;
			PC += 2;
		}
		break;

		// 0xEx--
		case 0xE: {
			switch (lsb) {
				// 0xE9E
				case 0x9E: // jkey Vx
					if (key_pressed[Vx]) PC += 2;
					PC += 2;
					break;

				// 0xA1
				case 0xA1: // jnkey Vx
					if (!key_pressed[Vx]) PC += 2;
					PC += 2;
					break;
			}
		}
		break;

		// 0xFx--
		case 0xF: {
			switch (lsb) {
				// 0xFx07
				case 0x07: // getdelay Vx
					Vx = DT;
					PC += 2;
					break;

				// 0xFx0A
				case 0x0A: // waitkey Vx
					awaitingKey = 0x80 | x;
					PC += 2;
					break;

				// 0xFx15
				case 0x15: // setdelay Vx
					DT = Vx;
					PC += 2;
					break;

				// 0xFx18
				case 0x18: // setsound Vx
					ST = Vx;
					PC += 2;
					break;

				// 0xFx1E
				case 0x1E: // mov I, Vx
					I += Vx;
					VF = (I+Vx > 0xff);
					PC += 2;
					break;

				// 0xFx29
				case 0x29: // spritei I, Vx
					I = 5 * Vx;
					PC += 2;
					break;

				// 0xFx33
				case 0x33: // bcd [I], Vx
					tmp = Vx;
					byte a,b,c;
					c = tmp%10, tmp/=10;
					b = tmp%10, tmp/=10;
					a = tmp;

					memory[I] = a, memory[I+1] = b, memory[I+2] = c;
					PC += 2;
					break;

				// 0xFx55
				case 0x55: { // mov [I], V0-VF
					byte *memv = &memory[I];

					for (int p = 0; p <= x; ++p)
						*(memv++) = V[p];

					I += x+1, PC += 2;
				}
				break;

				// 0xFx65
				case 0x65: { // mov V0-VF, [I]
					byte *memv = &memory[I];

					for (int p = 0; p <= x; ++p)
						V[p] = *(memv++);

					I += x+1, PC += 2;
					break;
				}

				default:
					not_handled(msb, lsb);
			}
			break;
		}

		default:
			not_handled(msb, lsb);
	}
	#undef not_handled

}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x18(%rsp)
movzwl 0x1002(%rax), %ecx
movzwl (%rax,%rcx), %ecx
bswapl %ecx
shrl $0x10, %ecx
movl %ecx, 0xb8(%rsp)
movl 0xb8(%rsp), %ecx
sarl $0x8, %ecx
movl %ecx, 0xb4(%rsp)
movzbl 0xb8(%rsp), %ecx
movl %ecx, 0xb0(%rsp)
movl 0xb8(%rsp), %ecx
shrl $0xc, %ecx
andl $0xf, %ecx
movl %ecx, 0xac(%rsp)
movl 0xb8(%rsp), %ecx
shrl $0x8, %ecx
andl $0xf, %ecx
movl %ecx, 0xa8(%rsp)
movl 0xb8(%rsp), %ecx
shrl $0x4, %ecx
andl $0xf, %ecx
movl %ecx, 0xa4(%rsp)
movzbl 0xb8(%rsp), %ecx
movl %ecx, 0xa0(%rsp)
movl 0xb8(%rsp), %ecx
andl $0xf, %ecx
movl %ecx, 0x9c(%rsp)
movl 0xb8(%rsp), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movl %ecx, 0x98(%rsp)
movslq 0xa8(%rsp), %rcx
leaq 0x1032(%rax,%rcx), %rcx
movq %rcx, 0x90(%rsp)
movslq 0xa4(%rsp), %rcx
leaq 0x1032(%rax,%rcx), %rcx
movq %rcx, 0x88(%rsp)
addq $0x1041, %rax           # imm = 0x1041
movq %rax, 0x80(%rsp)
movl 0xb4(%rsp), %eax
sarl $0x4, %eax
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
subl $0xf, %eax
ja 0x3616
movq 0x20(%rsp), %rax
leaq 0x75ad(%rip), %rcx      # 0xa004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0xb0(%rsp), %eax
andl $0xf, %eax
movl %eax, 0x14(%rsp)
je 0x2a7d
jmp 0x2a72
movl 0x14(%rsp), %eax
subl $0xe, %eax
je 0x2ab4
jmp 0x2ae2
movq 0x18(%rsp), %rdi
addq $0x1053, %rdi           # imm = 0x1053
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x21a0
movq 0x18(%rsp), %rax
movb $0x1, 0x1853(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2b08
movq 0x18(%rsp), %rax
movw 0x1004(%rax), %cx
addw $-0x1, %cx
movw %cx, 0x1004(%rax)
movzwl %cx, %ecx
movzwl 0x1006(%rax,%rcx,2), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2b08
movl 0xb4(%rsp), %esi
movl 0xb0(%rsp), %edx
leaq 0x76fb(%rip), %rdi      # 0xa1f2
movb $0x0, %al
callq 0x2060
movl $0x2, %edi
callq 0x2340
jmp 0x363c
movq 0x18(%rsp), %rax
movl 0x98(%rsp), %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x18(%rsp), %rax
movw 0x1002(%rax), %dx
movw 0x1004(%rax), %cx
movw %cx, %si
addw $0x1, %si
movw %si, 0x1004(%rax)
movzwl %cx, %ecx
movw %dx, 0x1006(%rax,%rcx,2)
movl 0x98(%rsp), %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
cmpl 0xa0(%rsp), %eax
jne 0x2b8e
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
cmpl 0xa0(%rsp), %eax
je 0x2bd3
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
movq 0x88(%rsp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x2c1e
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x18(%rsp), %rax
movl 0xa0(%rsp), %ecx
movb %cl, %dl
movq 0x90(%rsp), %rcx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x18(%rsp), %rax
movl 0xa0(%rsp), %esi
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
addl %esi, %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movl 0xb0(%rsp), %eax
andl $0xf, %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0xe, %eax
ja 0x2f40
movq 0x8(%rsp), %rax
leaq 0x7386(%rip), %rcx      # 0xa044
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x18(%rsp), %rax
movq 0x88(%rsp), %rcx
movb (%rcx), %dl
movq 0x90(%rsp), %rcx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movq 0x18(%rsp), %rax
movq 0x88(%rsp), %rcx
movzbl (%rcx), %esi
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
orl %esi, %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movq 0x18(%rsp), %rax
movq 0x88(%rsp), %rcx
movzbl (%rcx), %esi
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
andl %esi, %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movq 0x18(%rsp), %rax
movq 0x88(%rsp), %rcx
movzbl (%rcx), %esi
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
xorl %esi, %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movzbl (%rcx), %ecx
movq 0x88(%rsp), %rdx
movzbl (%rdx), %edx
addl %edx, %ecx
movl %ecx, 0xbc(%rsp)
cmpl $0xff, 0xbc(%rsp)
setg %dl
andb $0x1, %dl
movq 0x80(%rsp), %rcx
movb %dl, (%rcx)
movq 0x88(%rsp), %rcx
movzbl (%rcx), %esi
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
addl %esi, %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movzbl (%rcx), %ecx
movq 0x88(%rsp), %rdx
movzbl (%rdx), %edx
cmpl %edx, %ecx
setg %dl
andb $0x1, %dl
movq 0x80(%rsp), %rcx
movb %dl, (%rcx)
movq 0x88(%rsp), %rcx
movzbl (%rcx), %esi
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
subl %esi, %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movzbl (%rcx), %ecx
andl $0x1, %ecx
movb %cl, %dl
movq 0x80(%rsp), %rcx
movb %dl, (%rcx)
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
sarl %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movq 0x18(%rsp), %rax
movq 0x88(%rsp), %rcx
movzbl (%rcx), %ecx
movq 0x90(%rsp), %rdx
movzbl (%rdx), %edx
cmpl %edx, %ecx
setg %dl
andb $0x1, %dl
movq 0x80(%rsp), %rcx
movb %dl, (%rcx)
movq 0x90(%rsp), %rcx
movzbl (%rcx), %esi
movq 0x88(%rsp), %rcx
movzbl (%rcx), %edx
subl %esi, %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movzbl (%rcx), %ecx
sarl $0x7, %ecx
movb %cl, %dl
movq 0x80(%rsp), %rcx
movb %dl, (%rcx)
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
shll %edx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x2f66
movl 0xb4(%rsp), %esi
movl 0xb0(%rsp), %edx
leaq 0x729d(%rip), %rdi      # 0xa1f2
movb $0x0, %al
callq 0x2060
movl $0x2, %edi
callq 0x2340
jmp 0x363c
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
movq 0x88(%rsp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x2f9b
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x18(%rsp), %rax
movl 0x98(%rsp), %ecx
movw %cx, 0x1000(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x18(%rsp), %rax
movzbl 0x1032(%rax), %ecx
addl 0x98(%rsp), %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
leaq 0x78(%rsp), %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0x54e0
leaq 0x78(%rsp), %rdi
leaq 0xb2ad(%rip), %rsi      # 0xe2c8
callq 0x5510
movl %eax, %ecx
movq 0x18(%rsp), %rax
andl 0xa0(%rsp), %ecx
movb %cl, %dl
movq 0x90(%rsp), %rcx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movq 0x18(%rsp), %rax
movb $0x8, 0x77(%rsp)
movl 0x9c(%rsp), %ecx
movb %cl, 0x76(%rsp)
movzwl 0x1000(%rax), %ecx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
movzbl 0x76(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3171
movq 0x88(%rsp), %rax
movzbl (%rax), %eax
addl 0x5c(%rsp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %edx, 0x60(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
movzbl 0x77(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3153
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
addl 0x58(%rsp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, 0x64(%rsp)
movq 0x68(%rsp), %rax
movzbl (%rax), %eax
movl 0x58(%rsp), %ecx
movl $0x80, %edx
sarl %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x3141
movq 0x18(%rsp), %rax
addq $0x1053, %rax           # imm = 0x1053
movl 0x60(%rsp), %ecx
shll $0x6, %ecx
addl 0x64(%rsp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
sete %cl
andb $0x1, %cl
movq 0x80(%rsp), %rax
movb %cl, (%rax)
movq 0x50(%rsp), %rax
movzbl (%rax), %ecx
xorl $0x1, %ecx
movb %cl, (%rax)
jmp 0x3143
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x30b0
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x307c
movq 0x18(%rsp), %rax
movb $0x1, 0x1853(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movl 0xb0(%rsp), %eax
movl %eax, 0x4(%rsp)
subl $0x9e, %eax
je 0x31b7
jmp 0x31a7
movl 0x4(%rsp), %eax
subl $0xa1, %eax
je 0x31ff
jmp 0x3245
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movzbl (%rcx), %ecx
testb $0x1, 0x1042(%rax,%rcx)
je 0x31e7
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3245
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movzbl (%rcx), %ecx
testb $0x1, 0x1042(%rax,%rcx)
jne 0x322f
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
movq 0x18(%rsp), %rax
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x363c
movl 0xb0(%rsp), %eax
movl %eax, (%rsp)
subl $0x7, %eax
je 0x32ce
jmp 0x325b
movl (%rsp), %eax
subl $0xa, %eax
je 0x32f9
jmp 0x3269
movl (%rsp), %eax
subl $0x15, %eax
je 0x3327
jmp 0x3277
movl (%rsp), %eax
subl $0x18, %eax
je 0x3352
jmp 0x3285
movl (%rsp), %eax
subl $0x1e, %eax
je 0x337d
jmp 0x3293
movl (%rsp), %eax
subl $0x29, %eax
je 0x33dd
jmp 0x32a1
movl (%rsp), %eax
subl $0x33, %eax
je 0x340d
jmp 0x32af
movl (%rsp), %eax
subl $0x55, %eax
je 0x34d3
jmp 0x32bd
movl (%rsp), %eax
subl $0x65, %eax
je 0x3562
jmp 0x35ee
movq 0x18(%rsp), %rax
movb 0x1030(%rax), %dl
movq 0x90(%rsp), %rcx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movq 0x18(%rsp), %rax
movl 0xa8(%rsp), %ecx
orl $0x80, %ecx
movb %cl, 0x1052(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movb (%rcx), %cl
movb %cl, 0x1030(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movb (%rcx), %cl
movb %cl, 0x1031(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movzbl (%rcx), %edx
movzwl 0x1000(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x1000(%rax)
movzwl 0x1000(%rax), %ecx
movq 0x90(%rsp), %rdx
movzbl (%rdx), %edx
addl %edx, %ecx
cmpl $0xff, %ecx
setg %dl
andb $0x1, %dl
movq 0x80(%rsp), %rcx
movb %dl, (%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movq 0x18(%rsp), %rax
movq 0x90(%rsp), %rcx
movzbl (%rcx), %ecx
imull $0x5, %ecx, %ecx
movw %cx, 0x1000(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
movl %eax, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movb %dl, %al
movb %al, 0x4d(%rsp)
movl 0xbc(%rsp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movb %dl, %al
movb %al, 0x4e(%rsp)
movl 0xbc(%rsp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0xbc(%rsp)
movl 0xbc(%rsp), %ecx
movb %cl, 0x4f(%rsp)
movb 0x4f(%rsp), %dl
movzwl 0x1000(%rax), %ecx
movb %dl, (%rax,%rcx)
movb 0x4e(%rsp), %dl
movzwl 0x1000(%rax), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movb 0x4d(%rsp), %dl
movzwl 0x1000(%rax), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movq 0x18(%rsp), %rax
movzwl 0x1000(%rax), %ecx
addq %rcx, %rax
movq %rax, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0xa8(%rsp), %eax
jg 0x352d
movq 0x18(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movb 0x1032(%rax,%rcx), %cl
movq 0x40(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x40(%rsp)
movb %cl, (%rax)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x34ef
movq 0x18(%rsp), %rax
movl 0xa8(%rsp), %edx
addl $0x1, %edx
movzwl 0x1000(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x1000(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movq 0x18(%rsp), %rax
movzwl 0x1000(%rax), %ecx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0xa8(%rsp), %eax
jg 0x35bc
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x30(%rsp)
movb (%rcx), %dl
movslq 0x2c(%rsp), %rcx
movb %dl, 0x1032(%rax,%rcx)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x357e
movq 0x18(%rsp), %rax
movl 0xa8(%rsp), %edx
addl $0x1, %edx
movzwl 0x1000(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x1000(%rax)
movzwl 0x1002(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0x1002(%rax)
jmp 0x3614
movl 0xb4(%rsp), %esi
movl 0xb0(%rsp), %edx
leaq 0x6bef(%rip), %rdi      # 0xa1f2
movb $0x0, %al
callq 0x2060
movl $0x2, %edi
callq 0x2340
jmp 0x363c
movl 0xb4(%rsp), %esi
movl 0xb0(%rsp), %edx
leaq 0x6bc7(%rip), %rdi      # 0xa1f2
movb $0x0, %al
callq 0x2060
movl $0x2, %edi
callq 0x2340
addq $0xc8, %rsp
retq
nopw %cs:(%rax,%rax)