// File: /workspace/github_cpp_makefile_star2_O3/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 0x1a75
movq 0x4596(%rip), %rbx      # 0x5fd0
leaq 0x2620(%rip), %rsi      # 0x4061
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
leaq 0x60(%rbp), %rax
movq %rax, 0x10(%rsp)
movq 0x454b(%rip), %r15      # 0x5fd0
leaq 0x25f6(%rip), %rbx      # 0x4082
movl $0x27, %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 0x4516(%rip), %r14      # 0x5fe0
leaq 0xe(%rsp), %r12
leaq 0x258b(%rip), %r13      # 0x4061
movq %r14, %rdi
movq %r12, %rsi
callq 0x1120
movzbl 0xe(%rsp), %eax
cmpl $0x74, %eax
je 0x1b37
cmpl $0x64, %eax
je 0x1b7f
movq 0x10(%rsp), %rax
cmpl $0x33, (%rax)
jg 0x1b43
movl $0x20, %edx
movq %r15, %rdi
movq %r13, %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 0x1b43
movq 0x10(%rsp), %rax
movl (%rax), %eax
cmpl $0x34, %eax
jne 0x1b9f
movl $0x27, %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
jmp 0x1ad6
movq 0x8(%rbp), %rdx
movq 0x38(%rbp), %rsi
addq $-0x4, %rdx
cmpq 0x40(%rbp), %rsi
je 0x1bb5
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbp)
jmp 0x1bbe
movq 0x38(%rbp), %rsi
cmpq 0x40(%rbp), %rsi
je 0x1bc5
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbp)
jmp 0x1bd3
leaq 0x30(%rbp), %rdi
callq 0x3d5c
addq $-0x4, 0x8(%rbp)
jmp 0x1bd3
leaq 0x30(%rbp), %rdi
movq 0x10(%rsp), %rdx
callq 0x3d5c
leaq 0x30(%rbp), %rsi
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x20(%rsp)
callq 0x3c2e
movq %rbx, %rdi
callq 0x286a
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1c08
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbp, 0x18(%rsp)
leaq 0x2496(%rip), %rbx      # 0x40aa
movq 0x43c5(%rip), %r14      # 0x5fe0
leaq 0xe(%rsp), %r12
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 %r14, %rdi
movq %r12, %rsi
callq 0x1120
movzbl 0xe(%rsp), %eax
cmpl $0x72, %eax
je 0x1c71
cmpl $0x67, %eax
jne 0x1c20
leaq 0x246f(%rip), %r14      # 0x40e7
movq 0x4361(%rip), %rbp      # 0x5fe0
leaq 0x2424(%rip), %r13      # 0x40aa
leaq 0xe(%rsp), %rbx
cmpb $0x72, %al
je 0x1ca0
movzbl %al, %eax
cmpl $0x67, %eax
jne 0x1e3f
jmp 0x1e9c
movl $0x2f, %edx
movq %r15, %rdi
movq %r14, %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 %rbp, %rdi
leaq 0xd(%rsp), %r12
movq %r12, %rsi
callq 0x1120
movb 0xd(%rsp), %al
addb $-0x39, %al
cmpb $-0x9, %al
ja 0x1d3d
movl $0x2f, %edx
movq %r15, %rdi
movq %r14, %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 %rbp, %rdi
movq %r12, %rsi
callq 0x1120
movb 0xd(%rsp), %al
addb $-0x39, %al
cmpb $-0x8, %al
jb 0x1cf1
movl $0x30, %edx
movq %r15, %rdi
leaq 0x23cb(%rip), %r14      # 0x4117
movq %r14, %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 %rbp, %rdi
leaq 0xf(%rsp), %r12
movq %r12, %rsi
callq 0x1120
movb 0xf(%rsp), %al
leal -0x39(%rax), %ecx
cmpb $-0x9, %cl
ja 0x1de5
movl $0x30, %edx
movq %r15, %rdi
movq %r14, %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 %rbp, %rdi
movq %r12, %rsi
callq 0x1120
movb 0xf(%rsp), %al
leal -0x39(%rax), %ecx
cmpb $-0x8, %cl
jb 0x1d97
movsbq 0xd(%rsp), %rcx
movzbl %al, %eax
movl $0xffffffcf, %edx       # imm = 0xFFFFFFCF
addl %edx, %eax
movq 0x20(%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 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x3c2e
movq %r14, %rdi
callq 0x286a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x1e3f
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movl $0x3c, %edx
movq %r15, %rdi
movq %r13, %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 %rbp, %rdi
movq %rbx, %rsi
callq 0x1120
movzbl 0xe(%rsp), %eax
cmpl $0x67, %eax
je 0x1e90
cmpl $0x72, %eax
jne 0x1e3f
leaq 0x2250(%rip), %r14      # 0x40e7
jmp 0x1c8b
leaq 0x22a5(%rip), %rsi      # 0x4148
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 0x4102(%rip), %rdi      # 0x5fe0
leaq 0xd(%rsp), %rbx
movq %rbx, %rsi
callq 0x1120
movb (%rbx), %al
leal -0x39(%rax), %ecx
cmpb $-0x9, %cl
ja 0x1f56
leaq 0x224c(%rip), %rbx      # 0x4148
movq 0x40dd(%rip), %r14      # 0x5fe0
leaq 0xd(%rsp), %r12
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 %r14, %rdi
movq %r12, %rsi
callq 0x1120
movb 0xd(%rsp), %al
leal -0x39(%rax), %ecx
cmpb $-0x8, %cl
jb 0x1f08
movzbl %al, %eax
movl $0xffffffcf, %ecx       # imm = 0xFFFFFFCF
addl %ecx, %eax
movq 0x18(%rsp), %rbx
movq 0x30(%rbx), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x60(%rbx)
leaq 0x48(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0x3b9e
movsbq 0xd(%rsp), %rax
movq 0x30(%rbx), %rcx
movq 0x38(%rbx), %rdx
leaq (%rcx,%rax,4), %rsi
addq $-0xc0, %rsi
cmpq %rdx, %rsi
je 0x1fb2
leaq (%rcx,%rax,4), %rdi
addq $-0xc4, %rdi
subq %rsi, %rdx
callq 0x1140
movq 0x38(%rbx), %rdx
addq $-0x4, %rdx
movq %rdx, 0x38(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1ff7
movq 0x50(%rsp), %rsi
jmp 0x1fef
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x1ff7
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x1150