// File: tewalds[P]pentagod/./move.h
// Function: Move::rotate(unsigned int) const
Move rotate(unsigned int other) const {
		if(l < 0) //special
			return *this;

		assert(o <= 8 && other <= 8);

		if(other == o) //already the correct orientation
			return *this;

		if(o == 8 && other < 8) //unoriented move, default to board
			return Move(l, r, other);

		if(o == 8 || other == 8){ // oriented moves are incompatible with unoriented boards
			printf("rotate %s to %i\n", to_s(true).c_str(), other);
			assert(o <= 7 && other <= 7);
		}

/*
flip move:  Move(y, x, (9-r)&7). Works because (9-1)&7=8&7=0, (9-1)&7=8&7=0
rotate cw:  Move(5-y,   x, (r+2)&7)
rotate 180: Move(5-x, 5-y, (r+4)&7)
rotate ccw: Move(  y, 5-x, (r+6)&7)
*/

		unsigned int c = o*8 + other;
		switch(c){
		case  0: case 011: case 022: case 033: case 044: case 055: case 066: case 077: return *this;
		                                                                                    //Move(  x(),   y(),       r, other);
		case 01: case 012: case 023: case 030: case 047: case 054: case 065: case 076: return Move(5-y(),   x(), (r+2)&7, other);
		case 02: case 013: case 020: case 031: case 046: case 057: case 064: case 075: return Move(5-x(), 5-y(), (r+4)&7, other);
		case 03: case 010: case 021: case 032: case 045: case 056: case 067: case 074: return Move(  y(), 5-x(), (r+6)&7, other);

		case 04: case 015: case 026: case 037: case 040: case 051: case 062: case 073: return Move(  y(),   x(), ( 9-r)&7, other);
		case 07: case 014: case 025: case 036: case 041: case 052: case 063: case 070: return Move(5-x(),   y(), (11-r)&7, other);
		case 06: case 017: case 024: case 035: case 042: case 053: case 060: case 071: return Move(5-y(), 5-x(), (13-r)&7, other);
		case 05: case 016: case 027: case 034: case 043: case 050: case 061: case 072: return Move(  x(), 5-y(), (15-r)&7, other);
		default:
			printf("o: %i, other: %i, c: %#4x", o, other, c);
			assert(false && "Bad orientation?!?");
		}
	}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movl %esi, 0x84(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x48(%rsp)
movw (%rax), %ax
shlw $0x8, %ax
sarw $0x8, %ax
cwtl
cmpl $0x0, %eax
jge 0xd2f7
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x94(%rsp)
jmp 0xd7cf
movq 0x48(%rsp), %rax
movw (%rax), %ax
shrw $0xc, %ax
movzwl %ax, %ecx
xorl %eax, %eax
cmpl $0x8, %ecx
movb %al, 0x47(%rsp)
jg 0xd320
cmpl $0x8, 0x84(%rsp)
setbe %al
movb %al, 0x47(%rsp)
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0xd32a
jmp 0xd32c
jmp 0xd34b
leaq 0x30695(%rip), %rdi     # 0x3d9c8
leaq 0x306a3(%rip), %rsi     # 0x3d9dd
movl $0x5d, %edx
leaq 0x306a0(%rip), %rcx     # 0x3d9e6
callq 0x4250
movq 0x48(%rsp), %rcx
movl 0x84(%rsp), %eax
movw (%rcx), %cx
shrw $0xc, %cx
movzwl %cx, %ecx
cmpl %ecx, %eax
jne 0xd378
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x94(%rsp)
jmp 0xd7cf
movq 0x48(%rsp), %rax
movw (%rax), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0x8, %eax
jne 0xd3d0
cmpl $0x8, 0x84(%rsp)
jae 0xd3d0
movq 0x48(%rsp), %rax
movw (%rax), %cx
shlw $0x8, %cx
sarw $0x8, %cx
movswl %cx, %esi
movw (%rax), %ax
shrw $0x8, %ax
andw $0xf, %ax
movzwl %ax, %edx
movl 0x84(%rsp), %ecx
leaq 0x94(%rsp), %rdi
callq 0xde50
jmp 0xd7cf
movq 0x48(%rsp), %rax
movw (%rax), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0x8, %eax
je 0xd3f2
cmpl $0x8, 0x84(%rsp)
jne 0xd4ac
movq 0x48(%rsp), %rsi
leaq 0x60(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movl $0x1, %edx
callq 0xdec0
movq 0x38(%rsp), %rdi
callq 0x4160
movq %rax, %rsi
movl 0x84(%rsp), %edx
leaq 0x305e6(%rip), %rdi     # 0x3da0c
xorl %eax, %eax
callq 0x4060
jmp 0xd42f
leaq 0x60(%rsp), %rdi
callq 0x4210
movq 0x48(%rsp), %rax
movw (%rax), %ax
shrw $0xc, %ax
movzwl %ax, %ecx
xorl %eax, %eax
cmpl $0x7, %ecx
movb %al, 0x37(%rsp)
jg 0xd462
cmpl $0x7, 0x84(%rsp)
setbe %al
movb %al, 0x37(%rsp)
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0xd46c
jmp 0xd46e
jmp 0xd4aa
leaq 0x305a8(%rip), %rdi     # 0x3da1d
leaq 0x30561(%rip), %rsi     # 0x3d9dd
movl $0x67, %edx
leaq 0x3055e(%rip), %rcx     # 0x3d9e6
callq 0x4250
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x4210
jmp 0xd7de
jmp 0xd4ac
movq 0x48(%rsp), %rax
movzwl (%rax), %edx
shrl $0xc, %edx
movl 0x84(%rsp), %ecx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,8), %eax
movl %eax, 0x50(%rsp)
movl 0x50(%rsp), %eax
movq %rax, 0x28(%rsp)
subq $0x3f, %rax
ja 0xd788
movq 0x28(%rsp), %rax
leaq 0x2fb60(%rip), %rcx     # 0x3d048
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x94(%rsp)
jmp 0xd7cf
movq 0x48(%rsp), %rdi
callq 0xe350
movq 0x48(%rsp), %rdi
movl %eax, %ecx
movl $0x5, %eax
subl %ecx, %eax
movl %eax, 0x24(%rsp)
callq 0xe370
movl 0x24(%rsp), %esi
movl %eax, %edx
movq 0x48(%rsp), %rax
movw (%rax), %ax
shrw $0x8, %ax
andw $0xf, %ax
movzwl %ax, %ecx
addl $0x2, %ecx
andl $0x7, %ecx
movl 0x84(%rsp), %r8d
leaq 0x94(%rsp), %rdi
callq 0xe3a0
jmp 0xd7cf
movq 0x48(%rsp), %rdi
callq 0xe370
movq 0x48(%rsp), %rdi
movl %eax, %ecx
movl $0x5, %eax
subl %ecx, %eax
movl %eax, 0x20(%rsp)
callq 0xe350
movl 0x20(%rsp), %esi
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl $0x5, %edx
subl %ecx, %edx
movw (%rax), %ax
shrw $0x8, %ax
andw $0xf, %ax
movzwl %ax, %ecx
addl $0x4, %ecx
andl $0x7, %ecx
movl 0x84(%rsp), %r8d
leaq 0x94(%rsp), %rdi
callq 0xe3a0
jmp 0xd7cf
movq 0x48(%rsp), %rdi
callq 0xe350
movq 0x48(%rsp), %rdi
movl %eax, 0x1c(%rsp)
callq 0xe370
movl 0x1c(%rsp), %esi
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl $0x5, %edx
subl %ecx, %edx
movw (%rax), %ax
shrw $0x8, %ax
andw $0xf, %ax
movzwl %ax, %ecx
addl $0x6, %ecx
andl $0x7, %ecx
movl 0x84(%rsp), %r8d
leaq 0x94(%rsp), %rdi
callq 0xe3a0
jmp 0xd7cf
movq 0x48(%rsp), %rdi
callq 0xe350
movq 0x48(%rsp), %rdi
movl %eax, 0x18(%rsp)
callq 0xe370
movl 0x18(%rsp), %esi
movl %eax, %edx
movq 0x48(%rsp), %rax
movw (%rax), %ax
shrw $0x8, %ax
andw $0xf, %ax
movzwl %ax, %eax
movl $0x9, %ecx
subl %eax, %ecx
andl $0x7, %ecx
movl 0x84(%rsp), %r8d
leaq 0x94(%rsp), %rdi
callq 0xe3a0
jmp 0xd7cf
movq 0x48(%rsp), %rdi
callq 0xe370
movq 0x48(%rsp), %rdi
movl %eax, %ecx
movl $0x5, %eax
subl %ecx, %eax
movl %eax, 0x14(%rsp)
callq 0xe350
movl 0x14(%rsp), %esi
movl %eax, %edx
movq 0x48(%rsp), %rax
movw (%rax), %ax
shrw $0x8, %ax
andw $0xf, %ax
movzwl %ax, %eax
movl $0xb, %ecx
subl %eax, %ecx
andl $0x7, %ecx
movl 0x84(%rsp), %r8d
leaq 0x94(%rsp), %rdi
callq 0xe3a0
jmp 0xd7cf
movq 0x48(%rsp), %rdi
callq 0xe350
movq 0x48(%rsp), %rdi
movl %eax, %ecx
movl $0x5, %eax
subl %ecx, %eax
movl %eax, 0x10(%rsp)
callq 0xe370
movl 0x10(%rsp), %esi
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl $0x5, %edx
subl %ecx, %edx
movw (%rax), %ax
shrw $0x8, %ax
andw $0xf, %ax
movzwl %ax, %eax
movl $0xd, %ecx
subl %eax, %ecx
andl $0x7, %ecx
movl 0x84(%rsp), %r8d
leaq 0x94(%rsp), %rdi
callq 0xe3a0
jmp 0xd7cf
movq 0x48(%rsp), %rdi
callq 0xe370
movq 0x48(%rsp), %rdi
movl %eax, 0xc(%rsp)
callq 0xe350
movl 0xc(%rsp), %esi
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl $0x5, %edx
subl %ecx, %edx
movw (%rax), %ax
shrw $0x8, %ax
andw $0xf, %ax
movzwl %ax, %eax
movl $0xf, %ecx
subl %eax, %ecx
andl $0x7, %ecx
movl 0x84(%rsp), %r8d
leaq 0x94(%rsp), %rdi
callq 0xe3a0
jmp 0xd7cf
movq 0x48(%rsp), %rax
movw (%rax), %ax
shrw $0xc, %ax
movzwl %ax, %esi
movl 0x84(%rsp), %edx
movl 0x50(%rsp), %ecx
leaq 0x30289(%rip), %rdi     # 0x3da32
movb $0x0, %al
callq 0x4060
leaq 0x30295(%rip), %rdi     # 0x3da4c
leaq 0x3021f(%rip), %rsi     # 0x3d9dd
movl $0x7f, %edx
leaq 0x3021c(%rip), %rcx     # 0x3d9e6
callq 0x4250
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0x4660
nopl (%rax,%rax)