// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %rdi, %rbp
cmpl $0x33, 0x60(%rdi)
jg 0x1676
movq 0x496e(%rip), %rdi      # 0x5fd0
leaq 0x19dc(%rip), %rsi      # 0x3045
callq 0x10f0
movq %rax, %rdi
callq 0x1080
leaq 0x60(%rbp), %rax
movq %rax, 0x10(%rsp)
movq 0x494a(%rip), %rbx      # 0x5fd0
leaq 0x19d9(%rip), %r14      # 0x3066
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rax, %rdi
callq 0x1080
movq 0x4939(%rip), %r15      # 0x5fe0
leaq 0xe(%rsp), %r12
leaq 0x1992(%rip), %r13      # 0x3045
movq %r15, %rdi
movq %r12, %rsi
callq 0x1130
movzbl 0xe(%rsp), %eax
cmpl $0x74, %eax
je 0x16ec
cmpl $0x64, %eax
je 0x170b
movq 0x10(%rsp), %rax
cmpl $0x33, (%rax)
jg 0x16f6
movq %rbx, %rdi
movq %r13, %rsi
callq 0x10f0
movq %rax, %rdi
callq 0x1080
jmp 0x16f6
movq 0x10(%rsp), %rax
cmpl $0x34, (%rax)
jne 0x1723
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rax, %rdi
callq 0x1080
jmp 0x16b3
leaq 0x30(%rbp), %rdi
movq 0x8(%rbp), %rsi
addq $-0x4, %rsi
callq 0x2ac8
addq $-0x4, 0x8(%rbp)
jmp 0x1731
leaq 0x30(%rbp), %rdi
movq 0x10(%rsp), %rsi
callq 0x2ac8
leaq 0x30(%rbp), %rsi
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x18(%rsp)
callq 0x2b4e
movq %rbx, %rdi
callq 0x1f55
movq %rbp, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x2c46
movq 0x486b(%rip), %rbx      # 0x5fd0
leaq 0x1922(%rip), %r14      # 0x308e
movq 0x486d(%rip), %r15      # 0x5fe0
leaq 0xe(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rbx, %rdi
callq 0x1080
movq %r15, %rdi
movq %r12, %rsi
callq 0x1130
movzbl 0xe(%rsp), %eax
cmpl $0x72, %eax
je 0x17a5
cmpl $0x67, %eax
jne 0x1778
movq 0x4824(%rip), %r12      # 0x5fd0
leaq 0x1918(%rip), %r14      # 0x30cb
movq 0x4826(%rip), %rbp      # 0x5fe0
leaq 0x18cd(%rip), %r13      # 0x308e
leaq 0xe(%rsp), %rbx
cmpb $0x72, %al
je 0x17db
movzbl %al, %eax
cmpl $0x67, %eax
jne 0x1887
jmp 0x18c0
leaq 0xd(%rsp), %r15
movq %r12, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rax, %rdi
callq 0x1080
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1130
movb 0xd(%rsp), %al
addb $-0x39, %al
cmpb $-0x8, %al
jb 0x17e0
leaq 0x18ec(%rip), %r14      # 0x30fb
leaq 0xf(%rsp), %r15
movq %r12, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rax, %rdi
callq 0x1080
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1130
movzbl 0xf(%rsp), %eax
leal -0x39(%rax), %ecx
cmpb $-0x8, %cl
jb 0x1814
movsbq 0xd(%rsp), %rcx
movl $0xffffffcf, %edx       # imm = 0xFFFFFFCF
addl %edx, %eax
movq 0x18(%rsp), %rsi
movq (%rsi), %rdx
movl -0xc4(%rdx,%rcx,4), %r8d
movl (%rdx,%rax,4), %edi
movl %edi, -0xc4(%rdx,%rcx,4)
movl %r8d, (%rdx,%rax,4)
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x2b4e
movq %r14, %rdi
callq 0x1f55
movq %r14, %rdi
callq 0x2c46
movq %r12, %rdi
movq %r13, %rsi
callq 0x10f0
movq %r12, %rdi
callq 0x1080
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1130
movzbl 0xe(%rsp), %eax
cmpl $0x67, %eax
je 0x18b4
cmpl $0x72, %eax
jne 0x1887
leaq 0x1810(%rip), %r14      # 0x30cb
jmp 0x17c6
movq 0x4709(%rip), %rbx      # 0x5fd0
leaq 0x185e(%rip), %r14      # 0x312c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rbx, %rdi
callq 0x1080
movq 0x46f8(%rip), %r15      # 0x5fe0
leaq 0xd(%rsp), %r12
movq 0x20(%rsp), %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x1130
movzbl 0xd(%rsp), %eax
leal -0x39(%rax), %ecx
cmpb $-0x9, %cl
ja 0x191f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10f0
movq %rbx, %rdi
callq 0x1080
jmp 0x18f2
movl $0xffffffcf, %ecx       # imm = 0xFFFFFFCF
addl %ecx, %eax
movq 0x30(%r13), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x60(%r13)
leaq 0x48(%r13), %rdi
movq 0x10(%rsp), %rsi
callq 0x2af2
movq 0x30(%r13), %rax
movsbq 0xd(%rsp), %rcx
leaq (%rax,%rcx,4), %rsi
addq $-0xc4, %rsi
movq 0x18(%rsp), %rdi
callq 0x2b9c
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x197f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2c46
movq %rbx, %rdi
callq 0x1160