// File: /workspace/github_cpp_makefile_star2_O1/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), %r13
movq %r13, %rdi
callq 0x3aae
movl %eax, %r15d
xorl %ebp, %ebp
movl $0x0, %r14d
testl %eax, %eax
jle 0x6f7b
movq %r13, %rdi
callq 0x3b1a
movl %eax, (%rbx)
shrq $0x20, %rax
movw %ax, 0x4(%rbx)
movl $0x0, (%r12)
movl $0x1, %r14d
movq %r13, 0x38(%rsp)
movq %r12, 0x18(%rsp)
movq 0x10(%rsp), %r13
leaq 0x1160(%r13), %r12
movq %r12, %rdi
callq 0x3aae
movq %r13, %rdx
movl %eax, %r13d
subl 0x1904(%rdx), %eax
cmovgl %eax, %ebp
testl %r13d, %r13d
cmovlel %eax, %ebp
testl %ebp, %ebp
movq %r13, 0x8(%rsp)
movq %r15, 0x30(%rsp)
movq %r12, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
js 0x7021
movl %r14d, %r14d
leaq (%r14,%r14,2), %rax
leaq (%rbx,%rax,2), %rbx
movq 0x18(%rsp), %r15
movq %r12, %rdi
movl %ebp, %esi
callq 0x3afc
movq 0x10(%rsp), %rdx
movl %eax, (%rbx)
shrq $0x20, %rax
movw %ax, 0x4(%rbx)
movl %r13d, %eax
subl %ebp, %eax
movl %eax, (%r15,%r14,4)
incq %r14
movl 0x1904(%rdx), %eax
cmpl %eax, %ebp
movl %eax, %ecx
cmovgl %ebp, %ecx
testl %ebp, %ebp
cmovel %ebp, %ecx
addq $0x6, %rbx
subl %eax, %ecx
movl %ecx, %ebp
jns 0x6fd6
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %r15
leal -0x1(%r15), %ebp
movl 0x1904(%rdx), %eax
leal -0x1(%rax), %r13d
cmpl %r15d, %eax
jge 0x709a
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 %r13d, %esi
callq 0x3afc
movl %eax, (%rbx)
shrq $0x20, %rax
movw %ax, 0x4(%rbx)
movq 0x40(%rsp), %rax
addl %r13d, %eax
movl %eax, (%r12)
movq 0x10(%rsp), %rax
addl 0x1904(%rax), %r13d
addq $0x4, %r12
addq $0x6, %rbx
incl %r14d
cmpl %ebp, %r13d
jl 0x705d
movq 0x30(%rsp), %rdx
testl %edx, %edx
setle %al
cmpl %edx, %r13d
setl %cl
orb %al, %cl
jne 0x7139
movq 0x8(%rsp), %rcx
testl %ecx, %ecx
jle 0x70c5
leal (%rcx,%rbp), %eax
subl %r13d, %eax
testl %eax, %eax
jle 0x70cc
addl %ecx, %ebp
subl %r13d, %ebp
jmp 0x70ce
xorl %ebp, %ebp
movq 0x10(%rsp), %r13
movq 0x20(%rsp), %r12
testl %ebp, %ebp
jle 0x7139
movq 0x8(%rsp), %rcx
leal (%rdx,%rcx,2), %eax
addl %edx, %ecx
addl %eax, %ecx
movq %rcx, 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 %ebp, %esi
callq 0x3afc
movl %eax, (%r15)
shrq $0x20, %rax
movw %ax, 0x4(%r15)
movq 0x8(%rsp), %rax
subl %ebp, %eax
movl %eax, (%rbx)
addq $0x4, %rbx
addq $0x6, %r15
incl %r14d
subl 0x1904(%r13), %ebp
jg 0x7106
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop