// File: /workspace/github_cpp_makefile_star2_O1/fredericmarchand[P]TexasHoldem/main.cpp
// Function: main
int main(int argc, char** argv) 
{
    bool AI_game = true;
    Game *game = new Game(2);
    Player *me = game->getPlayers()[0];
    me->setDealer(true);

    if (argc > 1)
    {
        AI_game = false;
        me->setAI(false);
    }

    while (1)
    {
        //Check if the game is over
        if (game->getPlayers()[0]->getChipCount() == 0 || game->getPlayers()[1]->getChipCount() == 0)
        {
            break;
        }

        game->resetDeck();
        game->clearPlayerStates();
        game->rotateDealerChip();

        printLabel("Starting new game");
        cout << "Small Blind: $" << SMALL_BLIND << endl;
        cout << "Big Blind:   $" << BIG_BLIND << endl;
        cout << "Dealer: Player " << game->getPlayerIndex(game->getDealer()) << endl;
        game->shuffleDeck(0);

        //Blinds
        game->getSmallBlindPlayer()->bet(SMALL_BLIND);
        game->getBigBlindPlayer()->bet(BIG_BLIND);

        game->distributeCards();
        me->printHand();

        if (game->playRound(me, true) == true)
            goto end;

        //Finish blinds round
        game->printPot();
        
        //Flop
        printLabel("Flop");
        game->flipFlop(VERBOSE);

        //Round of betting
        if (game->playRound(me, false))
            goto end;

        game->printPot();

        //Turn
        printLabel("Turn");
        game->flipTurn(VERBOSE);

        //Round of betting
        if (game->playRound(me, false))
            goto end;

        game->printPot();

        //River
        printLabel("River");
        game->flipRiver(VERBOSE);

        //Final round of betting
        game->playRound(me, false);

        game->printPot();

end:
        //Check Results and give pot to winner
        cout << endl;
        int winnerIndex = game->determineWinner();
        if (winnerIndex == 0)
        {
            game->getPlayers()[0]->incHandsWon();
        }
        else if (winnerIndex == 1)
        {
            game->getPlayers()[1]->incHandsWon();
        }

        for (int i = 0; i < game->getPlayerCount(); ++i)
        {
            cout << "Player " << i << " has won " << game->getPlayers()[i]->getHandsWon() << " games" << endl;
        }
        
        cin.ignore();
        //break;
    }

    //Print winner
    cout << "The winner is: " << (game->getPlayers()[0]->getChipCount() == 0 ? "Player 1" : "Player 0") << endl;

    delete game;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edi, %r14d
movl $0x1e0, %edi            # imm = 0x1E0
callq 0x2130
movq %rax, %rbx
movq %rax, %rdi
movl $0x2, %esi
callq 0x3950
movq %rbx, %r15
movq %rbx, %rdi
callq 0x3bae
movq (%rax), %rbx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x2a50
cmpl $0x2, %r14d
jl 0x61c3
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2a46
movq %rbx, -0x30(%rbp)
movq %r15, %r14
movq %r15, %rdi
callq 0x3bae
movq (%rax), %rdi
callq 0x2a0a
testl %eax, %eax
je 0x664f
leaq -0x40(%rbp), %r12
movq 0x3de3(%rip), %r15      # 0x9fd0
movq %r14, %rdi
callq 0x3bae
movq 0x8(%rax), %rdi
callq 0x2a0a
testl %eax, %eax
je 0x664f
movq %r14, %rdi
callq 0x3a72
movq %r14, %rdi
callq 0x5022
movq %r14, %rdi
callq 0x3d08
movq %r12, -0x50(%rbp)
leaq -0x50(%rbp), %r13
movq %r13, %rdi
leaq 0xfa2(%rip), %rsi       # 0x71d2
leaq 0xfac(%rip), %rdx       # 0x71e3
callq 0x28cc
movq %r13, %rdi
callq 0x6058
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
movq -0x30(%rbp), %rbx
je 0x625d
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2140
movl $0xe, %edx
movq %r15, %rdi
leaq 0xf78(%rip), %rsi       # 0x71e4
callq 0x2150
movq %r15, %rdi
movl $0x32, %esi
callq 0x21b0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2090
movl $0xe, %edx
movq %r15, %rdi
leaq 0xf3c(%rip), %rsi       # 0x71f3
callq 0x2150
movq %r15, %rdi
movl $0x64, %esi
callq 0x21b0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2090
movl $0xf, %edx
movq %r15, %rdi
leaq 0xf00(%rip), %rsi       # 0x7202
callq 0x2150
movq %r14, %rdi
callq 0x3d78
movq %r14, %rdi
movq %rax, %rsi
callq 0x3f1c
movq %r15, %rdi
movl %eax, %esi
callq 0x21b0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2090
movq %r14, %rdi
xorl %esi, %esi
callq 0x4368
movq %r14, %rdi
callq 0x3e38
movq %rax, %rdi
movl $0x32, %esi
callq 0x2e6e
movq %r14, %rdi
callq 0x3dc8
movq %rax, %rdi
movl $0x64, %esi
callq 0x2e6e
movq %r14, %rdi
callq 0x42fc
movq %rbx, %rdi
callq 0x2a5a
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x48fa
testb %al, %al
leaq -0xa0(%rbp), %r12
leaq 0xe58(%rip), %r13       # 0x720a
jne 0x650c
movq %r14, %rdi
callq 0x47b8
movq %r12, -0xb0(%rbp)
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
leaq 0xe3a(%rip), %rsi       # 0x7212
leaq 0xe37(%rip), %rdx       # 0x7216
callq 0x28cc
movq %rbx, %rdi
callq 0x6058
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
movq -0x30(%rbp), %rbx
je 0x640b
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
movl $0x1, %esi
callq 0x3f48
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x48fa
testb %al, %al
jne 0x650c
movq %r14, %rdi
callq 0x47b8
leaq -0x80(%rbp), %r12
movq %r12, -0x90(%rbp)
leaq -0x90(%rbp), %rbx
movq %rbx, %rdi
leaq 0xdc6(%rip), %rsi       # 0x7217
leaq 0xdc3(%rip), %rdx       # 0x721b
callq 0x28cc
movq %rbx, %rdi
callq 0x6058
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
movq -0x30(%rbp), %rbx
je 0x6481
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
movl $0x1, %esi
callq 0x42a0
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x48fa
testb %al, %al
jne 0x650c
movq %r14, %rdi
callq 0x47b8
leaq -0x60(%rbp), %r12
movq %r12, -0x70(%rbp)
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
leaq 0xd5f(%rip), %rsi       # 0x721c
leaq 0xd5d(%rip), %rdx       # 0x7221
callq 0x28cc
movq %rbx, %rdi
callq 0x6058
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
movq -0x30(%rbp), %rbx
je 0x64ea
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
movl $0x1, %esi
callq 0x42ce
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x48fa
movq %r14, %rdi
callq 0x47b8
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2090
movq %r14, %rdi
callq 0x43c8
cmpl $0x1, %eax
je 0x654e
testl %eax, %eax
jne 0x6562
movq %r14, %rdi
callq 0x3bae
jmp 0x655a
movq %r14, %rdi
callq 0x3bae
addq $0x8, %rax
movq (%rax), %rdi
callq 0x393a
movq %r14, %rdi
callq 0x3ba4
testl %eax, %eax
movq %r15, %rbx
leaq 0xcac(%rip), %r15       # 0x7222
jle 0x6624
xorl %r12d, %r12d
movl $0x7, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2150
movq %rbx, %rdi
movl %r12d, %esi
callq 0x21b0
movq %rax, %r13
movl $0x9, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2150
movq %r14, %rdi
callq 0x3bae
movq (%rax,%r12,8), %rdi
callq 0x3944
movq %r13, %rdi
movl %eax, %esi
callq 0x21b0
movq %rax, %r13
movl $0x6, %edx
movq %rax, %rdi
leaq 0xc52(%rip), %rsi       # 0x722c
callq 0x2150
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r13, %rdi
leaq 0xc09(%rip), %r13       # 0x720a
callq 0x2040
movq %rax, %rdi
callq 0x2090
incq %r12
movq %r14, %rdi
callq 0x3ba4
cltq
cmpq %rax, %r12
jl 0x657f
movq 0x39b5(%rip), %rdi      # 0x9fe0
callq 0x21e0
movq %r14, %rdi
callq 0x3bae
movq (%rax), %rdi
callq 0x2a0a
testl %eax, %eax
leaq -0x40(%rbp), %r12
movq %rbx, %r15
jne 0x61ed
movq %r14, %rbx
movq 0x3977(%rip), %r14      # 0x9fd0
leaq 0xbd3(%rip), %rsi       # 0x7233
movl $0xf, %edx
movq %r14, %rdi
callq 0x2150
movq %rbx, %rdi
callq 0x3bae
movq (%rax), %rdi
callq 0x2a0a
testl %eax, %eax
leaq 0xbbd(%rip), %rax       # 0x7243
leaq 0xbbf(%rip), %rsi       # 0x724c
cmoveq %rax, %rsi
movl $0x8, %edx
movq %r14, %rdi
callq 0x2150
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x3c76
movl $0x1e0, %esi            # imm = 0x1E0
movq %rbx, %rdi
callq 0x2140
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x1e0, %esi            # imm = 0x1E0
movq %rbx, %rdi
jmp 0x674d
movq %rax, %r14
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x6752
movq -0x60(%rbp), %rsi
jmp 0x674a
movq %rax, %r14
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x6752
movq -0x80(%rbp), %rsi
jmp 0x674a
movq %rax, %r14
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0x6752
movq -0xa0(%rbp), %rsi
jmp 0x674a
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x6752
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
callq 0x21c0