// File: ShootMe[P]Klondike-Solver/Solitaire.cpp
// Function: Solitaire::GetTalonCards(Card*, int*)
int Solitaire::GetTalonCards(Card talon[], int talonMoves[]) {
	int index = 0;

	//Check waste
	Pile & waste = piles[WASTE];
	int wasteSize = waste.Size();
	if (wasteSize > 0) {
		talon[index] = waste.Low();
		talonMoves[index++] = 0;
	}

	//Check cards waiting to be turned over from stock
	Pile & stock = piles[STOCK];
	int stockSize = stock.Size();
	for (int j = (stockSize > 0 && stockSize - drawCount <= 0) ? 0 : stockSize - drawCount; j >= 0; j -= drawCount) {
		talon[index] = stock.Up(j);
		talonMoves[index++] = stockSize - j;

		if (j > 0 && j < drawCount) { j = drawCount; }
	}

	//Check cards already turned over in the waste, meaning we have to "redeal" the deck to get to it
	int amountToDraw = stockSize;
	amountToDraw += stockSize;
	amountToDraw += wasteSize;
	amountToDraw++;
	wasteSize--;

	int lastIndex = drawCount - 1;
	while (lastIndex < wasteSize) {
		talon[index] = waste.Up(lastIndex);
		talonMoves[index++] = amountToDraw + lastIndex;
		lastIndex += drawCount;
	}

	//Check cards in stock after a "redeal". Only happens when draw count > 1 and you have access to more cards in the talon
	if (lastIndex > wasteSize && wasteSize > -1) {
		amountToDraw += wasteSize;
		amountToDraw += stockSize;
		for (int j = (stockSize > 0 && stockSize - lastIndex + wasteSize <= 0) ? 0 : stockSize - lastIndex + wasteSize; j > 0; j -= drawCount) {
			talon[index] = stock.Up(j);
			talonMoves[index++] = amountToDraw - j;
		}
	}

	return index;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x1c(%rbp)
addq $0x800, %rax            # imm = 0x800
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x6400
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0xb79d
movq -0x28(%rbp), %rdi
callq 0x6550
movl %eax, %ecx
movl %ecx, -0x32(%rbp)
shrq $0x20, %rax
movw %ax, -0x2e(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movl -0x32(%rbp), %ecx
movl %ecx, (%rax)
movw -0x2e(%rbp), %cx
movw %cx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x1c(%rbp)
movslq %ecx, %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x78(%rbp), %rax
addq $0x800, %rax            # imm = 0x800
addq $0x960, %rax            # imm = 0x960
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x6400
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0xb7dc
movq -0x78(%rbp), %rcx
movl -0x44(%rbp), %eax
subl 0x1904(%rcx), %eax
cmpl $0x0, %eax
jg 0xb7dc
xorl %eax, %eax
movl %eax, -0x7c(%rbp)
jmp 0xb7ec
movq -0x78(%rbp), %rcx
movl -0x44(%rbp), %eax
subl 0x1904(%rcx), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jl 0xb887
movq -0x40(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x6500
movl %eax, %ecx
movl %ecx, -0x4e(%rbp)
shrq $0x20, %rax
movw %ax, -0x4a(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movl -0x4e(%rbp), %ecx
movl %ecx, (%rax)
movw -0x4a(%rbp), %cx
movw %cx, 0x4(%rax)
movl -0x44(%rbp), %edx
subl -0x48(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
cmpl $0x0, -0x48(%rbp)
jle 0xb86e
movq -0x78(%rbp), %rcx
movl -0x48(%rbp), %eax
cmpl 0x1904(%rcx), %eax
jge 0xb86e
movq -0x78(%rbp), %rax
movl 0x1904(%rax), %eax
movl %eax, -0x48(%rbp)
jmp 0xb870
movq -0x78(%rbp), %rax
movl 0x1904(%rax), %ecx
movl -0x48(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x48(%rbp)
jmp 0xb7f2
movq -0x78(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, -0x54(%rbp)
movl -0x44(%rbp), %ecx
addl -0x54(%rbp), %ecx
movl %ecx, -0x54(%rbp)
movl -0x2c(%rbp), %ecx
addl -0x54(%rbp), %ecx
movl %ecx, -0x54(%rbp)
movl -0x54(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x54(%rbp)
movl -0x2c(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x2c(%rbp)
movl 0x1904(%rax), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xb92e
movq -0x28(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x6500
movq %rax, %rcx
movq -0x78(%rbp), %rax
movl %ecx, %edx
movl %edx, -0x5e(%rbp)
shrq $0x20, %rcx
movw %cx, -0x5a(%rbp)
movq -0x10(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
imulq $0x6, %rdx, %rdx
addq %rdx, %rcx
movl -0x5e(%rbp), %edx
movl %edx, (%rcx)
movw -0x5a(%rbp), %dx
movw %dx, 0x4(%rcx)
movl -0x54(%rbp), %esi
addl -0x58(%rbp), %esi
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %edx
movl %edx, %edi
addl $0x1, %edi
movl %edi, -0x1c(%rbp)
movslq %edx, %rdx
movl %esi, (%rcx,%rdx,4)
movl 0x1904(%rax), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0xb8c1
movl -0x58(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0xb9ef
cmpl $-0x1, -0x2c(%rbp)
jle 0xb9ef
movl -0x2c(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x44(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0xb971
movl -0x44(%rbp), %eax
subl -0x58(%rbp), %eax
addl -0x2c(%rbp), %eax
cmpl $0x0, %eax
jg 0xb971
xorl %eax, %eax
movl %eax, -0x80(%rbp)
jmp 0xb97d
movl -0x44(%rbp), %eax
subl -0x58(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jle 0xb9ed
movq -0x40(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x6500
movl %eax, %ecx
movl %ecx, -0x6a(%rbp)
shrq $0x20, %rax
movw %ax, -0x66(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movl -0x6a(%rbp), %ecx
movl %ecx, (%rax)
movw -0x66(%rbp), %cx
movw %cx, 0x4(%rax)
movl -0x54(%rbp), %edx
subl -0x64(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x78(%rbp), %rax
movl 0x1904(%rax), %ecx
movl -0x64(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x64(%rbp)
jmp 0xb983
jmp 0xb9ef
movl -0x1c(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)