// File: /workspace/github_cpp_makefile_star2_O3/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 0x3a10
movq %rbx, %r15
movq %rbx, %rdi
callq 0x3c4e
movq (%rax), %rbx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x2a54
cmpl $0x2, %r14d
jl 0x61d7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2a4a
movq %rbx, -0x30(%rbp)
movq %r15, %r14
movq %r15, %rdi
callq 0x3c4e
movq (%rax), %rdi
callq 0x2a0e
testl %eax, %eax
je 0x6663
leaq -0x40(%rbp), %r12
movq 0x3dcf(%rip), %r15      # 0x9fd0
movq %r14, %rdi
callq 0x3c4e
movq 0x8(%rax), %rdi
callq 0x2a0e
testl %eax, %eax
je 0x6663
movq %r14, %rdi
callq 0x3b12
movq %r14, %rdi
callq 0x5056
movq %r14, %rdi
callq 0x3da8
movq %r12, -0x50(%rbp)
leaq -0x50(%rbp), %r13
movq %r13, %rdi
leaq 0xf8e(%rip), %rsi       # 0x71d2
leaq 0xf98(%rip), %rdx       # 0x71e3
callq 0x28cc
movq %r13, %rdi
callq 0x606c
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
movq -0x30(%rbp), %rbx
je 0x6271
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2140
movl $0xe, %edx
movq %r15, %rdi
leaq 0xf64(%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 0xf28(%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 0xeec(%rip), %rsi       # 0x7202
callq 0x2150
movq %r14, %rdi
callq 0x3e18
movq %r14, %rdi
movq %rax, %rsi
callq 0x3fae
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 0x43de
movq %r14, %rdi
callq 0x3ed2
movq %rax, %rdi
movl $0x32, %esi
callq 0x2f68
movq %r14, %rdi
callq 0x3e68
movq %rax, %rdi
movl $0x64, %esi
callq 0x2f68
movq %r14, %rdi
callq 0x4368
movq %rbx, %rdi
callq 0x2a5e
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x4944
testb %al, %al
leaq -0xa0(%rbp), %r12
leaq 0xe44(%rip), %r13       # 0x720a
jne 0x6520
movq %r14, %rdi
callq 0x4802
movq %r12, -0xb0(%rbp)
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
leaq 0xe26(%rip), %rsi       # 0x7212
leaq 0xe23(%rip), %rdx       # 0x7216
callq 0x28cc
movq %rbx, %rdi
callq 0x606c
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
movq -0x30(%rbp), %rbx
je 0x641f
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
movl $0x1, %esi
callq 0x3fda
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4944
testb %al, %al
jne 0x6520
movq %r14, %rdi
callq 0x4802
leaq -0x80(%rbp), %r12
movq %r12, -0x90(%rbp)
leaq -0x90(%rbp), %rbx
movq %rbx, %rdi
leaq 0xdb2(%rip), %rsi       # 0x7217
leaq 0xdaf(%rip), %rdx       # 0x721b
callq 0x28cc
movq %rbx, %rdi
callq 0x606c
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
movq -0x30(%rbp), %rbx
je 0x6495
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
movl $0x1, %esi
callq 0x431c
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4944
testb %al, %al
jne 0x6520
movq %r14, %rdi
callq 0x4802
leaq -0x60(%rbp), %r12
movq %r12, -0x70(%rbp)
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
leaq 0xd4b(%rip), %rsi       # 0x721c
leaq 0xd49(%rip), %rdx       # 0x7221
callq 0x28cc
movq %rbx, %rdi
callq 0x606c
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
movq -0x30(%rbp), %rbx
je 0x64fe
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
movl $0x1, %esi
callq 0x4342
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4944
movq %r14, %rdi
callq 0x4802
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 0x443e
cmpl $0x1, %eax
je 0x6562
testl %eax, %eax
jne 0x6576
movq %r14, %rdi
callq 0x3c4e
jmp 0x656e
movq %r14, %rdi
callq 0x3c4e
addq $0x8, %rax
movq (%rax), %rdi
callq 0x39fa
movq %r14, %rdi
callq 0x3c44
testl %eax, %eax
movq %r15, %rbx
leaq 0xc98(%rip), %r15       # 0x7222
jle 0x6638
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 0x3c4e
movq (%rax,%r12,8), %rdi
callq 0x3a04
movq %r13, %rdi
movl %eax, %esi
callq 0x21b0
movq %rax, %r13
movl $0x6, %edx
movq %rax, %rdi
leaq 0xc3e(%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 0xbf5(%rip), %r13       # 0x720a
callq 0x2040
movq %rax, %rdi
callq 0x2090
incq %r12
movq %r14, %rdi
callq 0x3c44
cltq
cmpq %rax, %r12
jl 0x6593
movq 0x39a1(%rip), %rdi      # 0x9fe0
callq 0x21e0
movq %r14, %rdi
callq 0x3c4e
movq (%rax), %rdi
callq 0x2a0e
testl %eax, %eax
leaq -0x40(%rbp), %r12
movq %rbx, %r15
jne 0x6201
movq %r14, %rbx
movq 0x3963(%rip), %r14      # 0x9fd0
leaq 0xbbf(%rip), %rsi       # 0x7233
movl $0xf, %edx
movq %r14, %rdi
callq 0x2150
movq %rbx, %rdi
callq 0x3c4e
movq (%rax), %rdi
callq 0x2a0e
testl %eax, %eax
leaq 0xba9(%rip), %rax       # 0x7243
leaq 0xbab(%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 0x3d16
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 0x6761
movq %rax, %r14
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x6766
movq -0x60(%rbp), %rsi
jmp 0x675e
movq %rax, %r14
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x6766
movq -0x80(%rbp), %rsi
jmp 0x675e
movq %rax, %r14
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0x6766
movq -0xa0(%rbp), %rsi
jmp 0x675e
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x6766
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
callq 0x21c0