// File: /workspace/github_cpp_makefile_star2_O2/milzar[P]Multiplayer-Hangman-Game/src/client.cpp
// Function: main
int main(int argc, char *argv[]){
    if(argc < 4){
        cout<<"Invalid arguments"<<endl;
        return 0;
    }

    cout<<argv[3]<<"\tRunning"<<endl;
    Client myclient(argv[1],argv[2]);
    myclient.forward(argv[3]);
    cout<<"Received:\t"<<myclient.receive()<<endl;
    cout<<"Waiting for other players......"<<endl;
    string  res = myclient.receive();
    GameData game(1);
    game.deserialize(res);
    game.render();
    //Game started
    while(true){
        //Play or wait
        // cout<<"Waiting for server command"<<endl;
        string str = myclient.receive();

        if(str == "play"){
            string req="";
            cout<<"Your turn : Enter choice"<<endl;
            cin>>req;
            //TODO
            //Check if req is an already guessed character
            //If so read input again
            myclient.forward(req);
        }
        else if(str == "wait"){
            cout<<"Waiting for other player"<<endl;
        }
        else{
        }

        string res;
        res=myclient.receive();
        if( res.find("gameover") != string::npos ){
            cout<<"GAME OVER!"<<endl;
            int found = res.find("||");
            cout<<res.substr(8,found)<<" Wins!"<<endl;
            cout<<"Word was:"<<res.substr(found+2);
            // cout<<"Play Again(Y/N)?"<<endl;
            // string again;
            // cin>>again;
            // if(again != "y"){
            //     break;
            // }
            // else{
            //     cout<<"Waiting for next game"<<endl;
            //     while(1);
            // }

            return 0;

        }
        else{
            game.deserialize(res);
            game.render();
        }

    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
cmpl $0x3, %edi
jg 0x2472
movq 0x3b77(%rip), %rdi      # 0x5fd0
leaq 0x1ba4(%rip), %rsi      # 0x4004
callq 0x21d0
movq %rax, %rdi
callq 0x2110
jmp 0x27bd
movq %rsi, %rbx
movq 0x18(%rsi), %rsi
movq 0x3b50(%rip), %r14      # 0x5fd0
movq %r14, %rdi
callq 0x21d0
leaq 0x1b87(%rip), %rsi      # 0x4016
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2110
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
leaq 0x4(%rsp), %r15
movq %r15, %rdi
callq 0x2e18
movq 0x18(%rbx), %rsi
movq %r15, %rdi
callq 0x2f20
leaq 0x1b58(%rip), %rsi      # 0x401f
movq %r14, %rdi
callq 0x21d0
movq %rax, %rbx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2f80
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2190
movq %rax, %rdi
callq 0x2110
leaq 0x28(%rsp), %rdi
callq 0x2100
movq 0x3aca(%rip), %rdi      # 0x5fd0
leaq 0x1b1d(%rip), %rsi      # 0x402a
callq 0x21d0
movq %rax, %rdi
callq 0x2110
leaq 0x28(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x2f80
leaq 0x68(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x2930
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2250
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2a8e
leaq 0x48(%rsp), %rdi
callq 0x2100
leaq 0x68(%rsp), %rdi
callq 0x29c2
leaq 0xe8(%rsp), %r13
leaq 0x4(%rsp), %r14
leaq 0xa8(%rsp), %rbp
leaq 0xc8(%rsp), %r12
movq %r13, %rdi
movq %r14, %rsi
callq 0x2f80
movq %r13, %rdi
leaq 0x1ab0(%rip), %rsi      # 0x404a
callq 0x2851
testb %al, %al
leaq 0x8(%rsp), %r15
je 0x260c
movq %r15, %rdi
leaq 0x1a77(%rip), %rsi      # 0x4029
movq %rbp, %rdx
callq 0x285e
movq 0x3a0f(%rip), %rdi      # 0x5fd0
leaq 0x1a87(%rip), %rsi      # 0x404f
callq 0x21d0
movq %rax, %rdi
callq 0x2110
movq 0x3a04(%rip), %rdi      # 0x5fe0
movq %r15, %rsi
callq 0x2230
movq %r12, %rdi
movq %r15, %rsi
callq 0x2250
movq %r14, %rdi
movq %r12, %rsi
callq 0x2ebe
movq %r12, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2100
jmp 0x263a
movq %r13, %rdi
leaq 0x1a52(%rip), %rsi      # 0x4068
callq 0x2851
testb %al, %al
je 0x263a
movq 0x39aa(%rip), %rdi      # 0x5fd0
leaq 0x1a40(%rip), %rsi      # 0x406d
callq 0x21d0
movq %rax, %rdi
callq 0x2110
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2f80
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2220
movq %rbp, %rdi
callq 0x2100
movq %r15, %rdi
leaq 0x1a0f(%rip), %rsi      # 0x4086
xorl %edx, %edx
callq 0x22e0
movq %r15, %rsi
movq %rax, %r15
cmpq $-0x1, %rax
je 0x275a
movq 0x393b(%rip), %rdi      # 0x5fd0
leaq 0x19f3(%rip), %rsi      # 0x408f
callq 0x21d0
movq %rax, %rdi
callq 0x2110
movq %r14, %rbx
leaq 0x8(%rsp), %r12
movq %r12, %rdi
leaq 0x19df(%rip), %rsi      # 0x409a
xorl %edx, %edx
callq 0x22e0
movq %rax, %r14
movslq %r14d, %rcx
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x8
popq %rdx
callq 0x21f0
movq 0x38f3(%rip), %rdi      # 0x5fd0
movq %rbp, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x19ae(%rip), %rsi      # 0x409d
callq 0x21d0
movq %rax, %rdi
callq 0x2110
movq %rbp, %rdi
callq 0x2100
movq 0x38c5(%rip), %rdi      # 0x5fd0
leaq 0x1992(%rip), %rsi      # 0x40a4
callq 0x21d0
movq %rax, %r12
shlq $0x20, %r14
movabsq $0x200000000, %rax      # imm = 0x200000000
addq %rax, %r14
sarq $0x20, %r14
movq %rbp, %rdi
leaq 0x8(%rsp), %rsi
movq %r14, %rdx
pushq $-0x1
popq %rcx
callq 0x21f0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2190
movq %rbx, %r14
movq %rbp, %rdi
callq 0x2100
jmp 0x278f
leaq 0x88(%rsp), %rdi
callq 0x2250
leaq 0x68(%rsp), %r12
movq %r12, %rdi
leaq 0x88(%rsp), %rbx
movq %rbx, %rsi
callq 0x2a8e
movq %rbx, %rdi
callq 0x2100
movq %r12, %rdi
callq 0x29c2
leaq 0x8(%rsp), %rdi
callq 0x2100
movq %r13, %rdi
callq 0x2100
cmpq $-0x1, %r15
leaq 0xc8(%rsp), %r12
je 0x2585
leaq 0x28(%rsp), %rdi
callq 0x2100
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x283a
jmp 0x280a
jmp 0x280a
jmp 0x280a
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x281c
jmp 0x27fd
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x281c
movq %rax, %rbx
jmp 0x2832
jmp 0x2825
jmp 0x2825
jmp 0x2825
jmp 0x2811
movq %rax, %rbx
jmp 0x283f
jmp 0x2825
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x2100
jmp 0x2828
jmp 0x2825
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2100
leaq 0xe8(%rsp), %rdi
callq 0x2100
leaq 0x28(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x22a0