// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
leaq 0x800(%rdi), %rbp
movq %rbp, %rdi
callq 0x3a66
movl %eax, %r15d
xorl %r13d, %r13d
movl $0x0, %r14d
testl %eax, %eax
jle 0x6f42
movq %rbp, %rdi
callq 0x3ad2
movl %eax, (%rbx)
shrq $0x20, %rax
movw %ax, 0x4(%rbx)
movl $0x0, (%r12)
movl $0x1, %r14d
movq %rbp, 0x38(%rsp)
movq %r12, 0x18(%rsp)
movq 0x10(%rsp), %rbp
leaq 0x1160(%rbp), %r12
movq %r12, %rdi
callq 0x3a66
movq %rbp, %rdx
movl %eax, %ebp
movl 0x1904(%rdx), %eax
movl %ebp, %ecx
subl %eax, %ecx
cmovgl %ecx, %r13d
testl %ebp, %ebp
cmovlel %ecx, %r13d
testl %r13d, %r13d
movq %rbp, 0x8(%rsp)
movq %r15, 0x30(%rsp)
movq %r12, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
js 0x6ff3
movl %r14d, %r14d
leaq (%r14,%r14,2), %rax
leaq (%rbx,%rax,2), %rbx
movq 0x18(%rsp), %r15
movq %r12, %rdi
movl %r13d, %esi
callq 0x3ab4
movq 0x10(%rsp), %rdx
movl %eax, (%rbx)
shrq $0x20, %rax
movw %ax, 0x4(%rbx)
movl %ebp, %eax
subl %r13d, %eax
movl %eax, (%r15,%r14,4)
incq %r14
movl 0x1904(%rdx), %eax
cmpl %eax, %r13d
movl %eax, %ecx
cmovgl %r13d, %ecx
testl %r13d, %r13d
cmovel %r13d, %ecx
addq $0x6, %rbx
subl %eax, %ecx
movl %ecx, %r13d
jns 0x6fa2
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %r15
leal -0x1(%r15), %r13d
leal -0x1(%rax), %ebp
cmpl %r15d, %eax
jge 0x7062
movq 0x8(%rsp), %rax
leal (%r15,%rax,2), %eax
incl %eax
movq %rax, 0x40(%rsp)
movl %r14d, %eax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %r12
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rax,2), %rbx
movq 0x38(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
callq 0x3ab4
movl %eax, (%rbx)
shrq $0x20, %rax
movw %ax, 0x4(%rbx)
movq 0x40(%rsp), %rax
addl %ebp, %eax
movl %eax, (%r12)
movq 0x10(%rsp), %rax
addl 0x1904(%rax), %ebp
addq $0x4, %r12
addq $0x6, %rbx
incl %r14d
cmpl %r13d, %ebp
jl 0x7028
movq 0x30(%rsp), %rcx
testl %ecx, %ecx
jle 0x70ea
cmpl %ecx, %ebp
jl 0x70ea
movq 0x8(%rsp), %rax
addl %eax, %r13d
subl %ebp, %r13d
testl %eax, %eax
testl %r13d, %r13d
movq 0x10(%rsp), %rbp
movq 0x20(%rsp), %r12
jle 0x70ea
movq 0x8(%rsp), %rsi
leal (%rcx,%rsi,2), %eax
addl %ecx, %esi
addl %eax, %esi
movq %rsi, 0x8(%rsp)
movl %r14d, %eax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rbx
leaq (%rax,%rax,2), %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,2), %r15
movq %r12, %rdi
movl %r13d, %esi
callq 0x3ab4
movl %eax, (%r15)
shrq $0x20, %rax
movw %ax, 0x4(%r15)
movq 0x8(%rsp), %rax
subl %r13d, %eax
movl %eax, (%rbx)
addq $0x4, %rbx
addq $0x6, %r15
incl %r14d
subl 0x1904(%rbp), %r13d
jg 0x70b5
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq