// File: /workspace/github_cpp_makefile_star2_O1/ljc2154[P]Rummy/rummy.cpp
// Function: playUserTurn(State&)
void playUserTurn(State &state)
{
	/* Give user options for drawing */
	if (state.turnCard < 52)
		cout << "Enter \"t\" to take the turn card." << endl;
	cout << "Enter \"d\" to draw a card from the deck." << endl;
	char choice;
	cin >> choice;
	while (choice != 'd' && (choice != 't' || state.turnCard == 52))
	{
		if (state.turnCard < 52)
			cout << "Enter \"t\" to take the turn card." << endl;
		cout << "Enter \"d\" to draw a card from the deck." << endl;
		cin >> choice;
	}
	/* handle user wants the turn card */
	if (choice == 't')
		state.userHand.push_back(state.turnCard);
	/* handle user wants to draw a new card from the deck */
	else
	{
		state.userHand.push_back(state.deck.back());
		state.deck.pop_back();
	}
	printHand(state.userHand);

	/* Give user options for tossing */
	cout << "Enter \"g\" to give back a card or \"r\" to rearrange your hand.";
	cout << endl;
	cin >> choice;
	while (choice != 'g' && choice != 'r')
	{
		cout << "Enter \"g\" to give back a card or \"r\" to rearrange your hand.";
		cout << endl;
		cin >> choice;
	}
	while (choice != 'g')
	{
		/* Handle user wants to rearrange hand */
		if (choice == 'r')
		{
			char pos1, pos2;
			cout << "Enter the position of first card to swap [1-8]." << endl;
			cin >> pos1;
			while (pos1 < '1' || pos1 > '8')
			{
				cout << "Enter the position of first card to swap [1-8]." << endl;
				cin >> pos1;
			}
			cout << "Enter the position of second card to swap [1-8]." << endl;
			cin >> pos2;
			while (pos2 < '1' || pos2 > '8')
			{
				cout << "Enter the position of second card to swap [1-8]." << endl;
				cin >> pos2;
			}
			/* swap cards */
			swap(state.userHand, pos1-49, pos2-49);		// subtract 48 for ASCII, subtract 1 more for 0 indexing
			printHand(state.userHand);					// print user's hand
		}
		/* Give user options for tossing */
		cout << "Enter \"g\" to give back a card or \"r\" to rearrange your hand.";
		cout << endl;
		cin >> choice;
		while (choice != 'g' && choice != 'r')
		{
			cout << "Enter \"g\" to give back a card or \"r\" to rearrange your hand.";
			cout << endl;
			cin >> choice;
		}
	}
	/* handle user wants to give back a card */
	if (choice == 'g')
	{
		cout << "Enter the position of the card you would like to give back [1-8].";
		cout << endl;
		char pos;
		cin >> pos;
		while (pos < '1' || pos > '8')
		{
			cout << "Enter the position of the card you would like to give back [1-8].";
			cout << endl;
			cin >> pos;
		}
		state.turnCard = state.userHand[pos-49];					// set turn card
		state.remaining.remove(state.turnCard);						// remove from remaining cards
		state.userHand.erase(state.userHand.begin()+pos-49);		// remove from user hand
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
cmpl $0x33, 0x60(%rdi)
jg 0x1a4f
movq 0x45bc(%rip), %rbx      # 0x5fd0
leaq 0x262a(%rip), %rsi      # 0x4045
movl $0x20, %edx
movq %rbx, %rdi
callq 0x1110
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq %r14, 0x10(%rsp)
addq $0x60, %r14
movq 0x4571(%rip), %r15      # 0x5fd0
leaq 0x2600(%rip), %r12      # 0x4066
movl $0x27, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x453c(%rip), %r13      # 0x5fe0
leaq 0xe(%rsp), %rbp
leaq 0x2595(%rip), %rbx      # 0x4045
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1120
movzbl 0xe(%rsp), %eax
cmpl $0x74, %eax
je 0x1acf
cmpl $0x64, %eax
jne 0x1ad5
jmp 0x1b74
cmpl $0x34, (%r14)
jne 0x1b4e
cmpl $0x33, (%r14)
jg 0x1b12
movl $0x20, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movl $0x27, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
jmp 0x1ab0
cmpb $0x74, %al
jne 0x1b74
movq 0x10(%rsp), %rbx
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x1f8e
movl 0x60(%rbx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x1ba7
movq 0x10(%rsp), %rbx
movq 0x8(%rbx), %rdx
movq 0x38(%rbx), %rsi
addq $-0x4, %rdx
cmpq 0x40(%rbx), %rsi
je 0x1b99
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x1ba2
leaq 0x30(%rbx), %rdi
callq 0x3cf6
addq $-0x4, 0x8(%rbx)
leaq 0x30(%rbx), %r12
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3bc8
movq %rbx, %rdi
callq 0x2831
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1bda
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x24ad(%rip), %rbx      # 0x408e
movq 0x43f8(%rip), %r13      # 0x5fe0
leaq 0xe(%rsp), %rbp
movl $0x3c, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1120
movzbl 0xe(%rsp), %eax
cmpl $0x72, %eax
je 0x1e5b
cmpl $0x67, %eax
jne 0x1bed
jmp 0x1e5b
leaq 0x247d(%rip), %rsi      # 0x40cb
movl $0x2f, %edx
movq %r15, %rdi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x4357(%rip), %rdi      # 0x5fe0
leaq 0xd(%rsp), %rbx
movq %rbx, %rsi
callq 0x1120
movb (%rbx), %al
addb $-0x39, %al
cmpb $-0x9, %al
ja 0x1cf5
leaq 0x2426(%rip), %rsi      # 0x40cb
movl $0x2f, %edx
movq %r15, %rdi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x4300(%rip), %rdi      # 0x5fe0
leaq 0xd(%rsp), %rbx
movq %rbx, %rsi
callq 0x1120
movb (%rbx), %al
addb $-0x39, %al
cmpb $-0x8, %al
jb 0x1c9e
leaq 0x23ff(%rip), %rsi      # 0x40fb
movl $0x30, %edx
movq %r15, %rdi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x42a9(%rip), %rdi      # 0x5fe0
leaq 0xf(%rsp), %rbx
movq %rbx, %rsi
callq 0x1120
movb (%rbx), %al
leal -0x39(%rax), %ecx
cmpb $-0x9, %cl
ja 0x1da7
leaq 0x23a6(%rip), %rsi      # 0x40fb
movl $0x30, %edx
movq %r15, %rdi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x4250(%rip), %rdi      # 0x5fe0
leaq 0xf(%rsp), %rbx
movq %rbx, %rsi
callq 0x1120
movb (%rbx), %al
leal -0x39(%rax), %ecx
cmpb $-0x8, %cl
jb 0x1d4e
movsbq 0xd(%rsp), %rcx
movq (%r12), %rdx
movl -0xc4(%rdx,%rcx,4), %esi
movzbl %al, %eax
movl -0xc4(%rdx,%rax,4), %edi
movl %edi, -0xc4(%rdx,%rcx,4)
movl %esi, -0xc4(%rdx,%rax,4)
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3bc8
movq %rbx, %rdi
callq 0x2831
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1dff
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x2288(%rip), %rsi      # 0x408e
movl $0x3c, %edx
movq %r15, %rdi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x419f(%rip), %rdi      # 0x5fe0
leaq 0xe(%rsp), %rbx
movq %rbx, %rsi
callq 0x1120
movzbl (%rbx), %eax
cmpl $0x67, %eax
je 0x1e5b
cmpl $0x72, %eax
jne 0x1dff
movzbl 0xe(%rsp), %eax
cmpl $0x72, %eax
je 0x1c47
cmpl $0x67, %eax
jne 0x1dff
leaq 0x22b7(%rip), %rsi      # 0x412c
movl $0x41, %edx
movq %r15, %rdi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x4130(%rip), %rdi      # 0x5fe0
leaq 0xd(%rsp), %rbx
movq %rbx, %rsi
callq 0x1120
movb (%rbx), %al
leal -0x39(%rax), %ecx
cmpb $-0x9, %cl
ja 0x1f28
leaq 0x225e(%rip), %rbx      # 0x412c
movq 0x410b(%rip), %r12      # 0x5fe0
leaq 0xd(%rsp), %r13
movl $0x41, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1110
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq %r12, %rdi
movq %r13, %rsi
callq 0x1120
movb 0xd(%rsp), %al
leal -0x39(%rax), %ecx
cmpb $-0x8, %cl
jb 0x1eda
movzbl %al, %eax
addl $-0x31, %eax
movq 0x10(%rsp), %rbx
movq 0x30(%rbx), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x60(%rbx)
leaq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x3b38
movsbq 0xd(%rsp), %rax
movq 0x30(%rbx), %rcx
movq 0x38(%rbx), %rdx
leaq (%rcx,%rax,4), %rsi
addq $-0xc0, %rsi
cmpq %rdx, %rsi
je 0x1f7a
leaq (%rcx,%rax,4), %rdi
addq $-0xc4, %rdi
subq %rsi, %rdx
callq 0x1140
addq $-0x4, 0x38(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%rbx), %rdi
movq %r14, %rdx
callq 0x3cf6
jmp 0x1ba7
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1fcd
movq 0x40(%rsp), %rsi
jmp 0x1fc5
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1fcd
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x1150