// File: /workspace/github_cpp_makefile_star2_O3/ogghead[P]Moon_Boersma_Coe_CSCI2270_FinalProject/Blackjack.cpp
// Function: Blackjack::HitMe(player*, bool)
void Blackjack::HitMe(player* currentPlayer, bool secondHand)//this boolean checks
//if the hand to deal to is the 2nd one, if a player has split
{
    int index = deck.size() - 1;
    card* tmp = deck[index];

    if (secondHand == false) //if this was the first hand
    {
        currentPlayer->hand.push_back(tmp);
        if((tmp->value==11)&&(currentPlayer->handValue+11 > 21)) //if the ace being 11 would bust the player
        //than the ace would be worth 1
        {
            currentPlayer->handValue=currentPlayer->handValue+1;
        }
        else
        {
        currentPlayer->handValue=currentPlayer->handValue + tmp->value;
         if(currentPlayer->handValue>21){   //if the player busts, this would force them into stand position
             currentPlayer->stand=true;
         }
        }
    }

    else
    {
        currentPlayer->hand2.push_back(tmp);
        if((tmp->value==11)&&(currentPlayer->handValue2+11 > 21)){  //same as above but with hand 2
            currentPlayer->handValue2=currentPlayer->handValue2+1;
        }else{
        currentPlayer->handValue2=currentPlayer->handValue2 + tmp->value;
        }
         if(currentPlayer->handValue2>21){
             currentPlayer->stand2=true;
         }
    }

            //card counting math
    if (tmp->value == 2 || tmp->value == 3 || tmp->value == 4 ||
        tmp->value == 5 || tmp->value == 6)
        {
            cardCounter = cardCounter + 1;
        }
    else if (tmp->value == 7 || tmp->value == 8 || tmp->value == 9)
        {
            cardCounter = cardCounter;
        }
    else if (tmp->value >= 10)
        {
            cardCounter = cardCounter - 1;
        }
    deck.pop_back();
    //delete tmp;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
subq %rax, %rcx
shlq $0x1d, %rcx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
addq %rcx, %rsi
sarq $0x1d, %rsi
movq (%rax,%rsi), %rax
movq %rax, -0x18(%rbp)
testl %edx, %edx
je 0x2864
movq 0x58(%r14), %rsi
cmpq 0x60(%r14), %rsi
je 0x2878
movq %rax, (%rsi)
addq $0x8, 0x58(%r14)
jmp 0x2885
movq 0x30(%r14), %rsi
cmpq 0x38(%r14), %rsi
je 0x28b2
movq %rax, (%rsi)
addq $0x8, 0x30(%r14)
jmp 0x28bf
leaq 0x50(%r14), %rdi
leaq -0x18(%rbp), %rdx
callq 0x30b2
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl 0x4c(%r14), %ecx
cmpl $0xb, %ecx
movl $0x1, %edx
cmovll %eax, %edx
cmpl $0xb, %eax
cmovnel %eax, %edx
addl %ecx, %edx
movl %edx, 0x4c(%r14)
cmpl $0x16, %edx
jl 0x28fc
movb $0x1, 0x6d(%r14)
jmp 0x28fc
leaq 0x28(%r14), %rdi
leaq -0x18(%rbp), %rdx
callq 0x30b2
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl $0xb, %eax
sete %dl
movl 0x24(%r14), %ecx
cmpl $0xb, %ecx
setge %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x28ec
incl %ecx
movl %ecx, 0x24(%r14)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x2909
addl %eax, %ecx
movl %ecx, 0x24(%r14)
cmpl $0x16, %ecx
jl 0x28fc
movb $0x1, 0x6c(%r14)
movl $0x1, %ecx
leal -0x2(%rax), %edx
cmpl $0x5, %edx
jae 0x290e
addl %ecx, 0x30(%rbx)
jmp 0x2916
leal -0x7(%rax), %ecx
cmpl $0x3, %ecx
jae 0x2924
addq $-0x8, 0x8(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0xa, %eax
jge 0x2909
jmp 0x2916