// File: ShootMe[P]Klondike-Solver/Solitaire.cpp
// Function: Solitaire::UndoMove()
void Solitaire::UndoMove() {
	Move move = movesMade[--movesMadeCount];

	if (move.From != WASTE && move.Extra > 0) {
		piles[move.From].Flip();
	}

	if (move.Count == 1) {
		piles[move.To].Remove(piles[move.From]);

		if (move.To >= FOUNDATION1C) {
			--foundationCount;
		} else if (move.From >= FOUNDATION1C) {
			++foundationCount;
		}

		if (move.From == WASTE && move.Extra > 0) {
			int wasteSize = piles[WASTE].Size();
			if (move.Extra <= wasteSize) {
				piles[WASTE].RemoveTalon(piles[STOCK], move.Extra);
			} else {
				roundCount--;
				wasteSize += wasteSize;
				int stockSize = piles[STOCK].Size();
				wasteSize += stockSize;
				wasteSize += stockSize;
				wasteSize -= move.Extra;
				if (wasteSize > 0) {
					piles[STOCK].RemoveTalon(piles[WASTE], wasteSize);
				} else {
					piles[WASTE].RemoveTalon(piles[STOCK], -wasteSize);
				}
			}
		}
	} else {
		piles[move.To].Remove(piles[move.From], move.Count);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl 0x1914(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x1914(%rax)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xc(%rbp)
movzbl -0xc(%rbp), %eax
cmpl $0x0, %eax
je 0x89fc
movzbl -0x9(%rbp), %eax
cmpl $0x0, %eax
jle 0x89fc
movq -0x20(%rbp), %rdi
addq $0x800, %rdi            # imm = 0x800
movzbl -0xc(%rbp), %eax
imulq $0x12c, %rax, %rax      # imm = 0x12C
addq %rax, %rdi
callq 0x6090
movzbl -0xa(%rbp), %eax
cmpl $0x1, %eax
jne 0x8b83
movq -0x20(%rbp), %rsi
movq %rsi, %rdi
addq $0x800, %rdi            # imm = 0x800
movzbl -0xb(%rbp), %eax
imulq $0x12c, %rax, %rax      # imm = 0x12C
addq %rax, %rdi
addq $0x800, %rsi            # imm = 0x800
movzbl -0xc(%rbp), %eax
imulq $0x12c, %rax, %rax      # imm = 0x12C
addq %rax, %rsi
callq 0x6150
movzbl -0xb(%rbp), %eax
cmpl $0x9, %eax
jl 0x8a5d
movq -0x20(%rbp), %rax
movl 0x190c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x190c(%rax)
jmp 0x8a7b
movzbl -0xc(%rbp), %eax
cmpl $0x9, %eax
jl 0x8a79
movq -0x20(%rbp), %rax
movl 0x190c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x190c(%rax)
jmp 0x8a7b
movzbl -0xc(%rbp), %eax
cmpl $0x0, %eax
jne 0x8b81
movzbl -0x9(%rbp), %eax
cmpl $0x0, %eax
jle 0x8b81
movq -0x20(%rbp), %rdi
addq $0x800, %rdi            # imm = 0x800
callq 0x6400
movl %eax, -0x10(%rbp)
movzbl -0x9(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0x8adb
movq -0x20(%rbp), %rsi
movq %rsi, %rdi
addq $0x800, %rdi            # imm = 0x800
addq $0x800, %rsi            # imm = 0x800
addq $0x960, %rsi            # imm = 0x960
movzbl -0x9(%rbp), %edx
callq 0x62a0
jmp 0x8b7f
movq -0x20(%rbp), %rdi
movl 0x1908(%rdi), %eax
addl $-0x1, %eax
movl %eax, 0x1908(%rdi)
movl -0x10(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
addq $0x800, %rdi            # imm = 0x800
addq $0x960, %rdi            # imm = 0x960
callq 0x6400
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x14(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movzbl -0x9(%rbp), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jle 0x8b57
movq -0x20(%rbp), %rsi
movq %rsi, %rdi
addq $0x800, %rdi            # imm = 0x800
addq $0x960, %rdi            # imm = 0x960
addq $0x800, %rsi            # imm = 0x800
movl -0x10(%rbp), %edx
callq 0x62a0
jmp 0x8b7d
movq -0x20(%rbp), %rsi
movq %rsi, %rdi
addq $0x800, %rdi            # imm = 0x800
addq $0x800, %rsi            # imm = 0x800
addq $0x960, %rsi            # imm = 0x960
xorl %edx, %edx
subl -0x10(%rbp), %edx
callq 0x62a0
jmp 0x8b7f
jmp 0x8b81
jmp 0x8bbd
movq -0x20(%rbp), %rsi
movq %rsi, %rdi
addq $0x800, %rdi            # imm = 0x800
movzbl -0xb(%rbp), %eax
imulq $0x12c, %rax, %rax      # imm = 0x12C
addq %rax, %rdi
addq $0x800, %rsi            # imm = 0x800
movzbl -0xc(%rbp), %eax
imulq $0x12c, %rax, %rax      # imm = 0x12C
addq %rax, %rsi
movzbl -0xa(%rbp), %edx
callq 0x61e0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)