// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
cmpl $0x3, %edi
jg 0x2499
movq 0x3b77(%rip), %rbx      # 0x5fd0
leaq 0x1ba4(%rip), %rsi      # 0x4004
movl $0x11, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
jmp 0x2a6f
movq %rsi, %r14
movq 0x18(%rsi), %rbx
testq %rbx, %rbx
je 0x24c1
movq %rbx, %rdi
callq 0x20d0
movq 0x3b1c(%rip), %rdi      # 0x5fd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x24df
movq 0x3b08(%rip), %rax      # 0x5fd0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x2290
movq 0x3aea(%rip), %rbx      # 0x5fd0
leaq 0x1b29(%rip), %rsi      # 0x4016
movl $0x8, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
leaq 0xc(%rsp), %r15
movq %r15, %rdi
callq 0x329a
movq 0x18(%r14), %rsi
movq %r15, %rdi
callq 0x33a8
leaq 0x1ad6(%rip), %rsi      # 0x401f
movl $0xa, %edx
movq %rbx, %rdi
callq 0x21f0
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x3408
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x21f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x25ba
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x1a69(%rip), %rsi      # 0x402a
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq 0x50(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x3408
leaq 0xf8(%rsp), %rdi
movl $0x1, %esi
callq 0x2cc8
leaq 0xe8(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %rdi
callq 0x2ba6
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x2e82
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x266e
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0xf8(%rsp), %rdi
callq 0x2d74
leaq 0x20(%rsp), %r14
leaq 0xb8(%rsp), %r15
leaq 0xc(%rsp), %rbp
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r15, %rdi
movq %rbp, %rsi
callq 0x3408
movq %r15, %rdi
leaq 0x199e(%rip), %rsi      # 0x404a
callq 0x20a0
testl %eax, %eax
je 0x270c
movq %r15, %rdi
leaq 0x19a9(%rip), %rsi      # 0x4068
callq 0x20a0
testl %eax, %eax
jne 0x27e3
movl $0x18, %edx
movq %rbx, %rdi
leaq 0x1992(%rip), %rsi      # 0x406d
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
jmp 0x27e3
movq %r14, 0x10(%rsp)
movq %r12, %rdi
leaq 0x190e(%rip), %rdx      # 0x4029
movq %rdx, %rsi
callq 0x2c36
movl $0x18, %edx
movq %rbx, %rdi
leaq 0x191d(%rip), %rsi      # 0x404f
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x387b(%rip), %rdi      # 0x5fe0
movq %r12, %rsi
callq 0x2210
leaq 0xa0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0x2ba6
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x3346
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x27cc
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x27e3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %r14, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3408
movq %r12, %rdi
movq %r13, %rsi
callq 0x2200
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2828
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21b0
movl $0x8, %ecx
movq %r12, %rdi
leaq 0x184f(%rip), %rsi      # 0x4086
xorl %edx, %edx
callq 0x22a0
movq %rax, 0xb0(%rsp)
cmpq $-0x1, %rax
je 0x29a3
movl $0xa, %edx
movq %rbx, %rdi
leaq 0x1830(%rip), %rsi      # 0x408f
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movl $0x2, %ecx
movq %r12, %rdi
leaq 0x1800(%rip), %rsi      # 0x409a
xorl %edx, %edx
callq 0x22a0
movq %rax, %r15
movslq %r15d, %rcx
movl $0x8, %edx
movq %r13, %rdi
movq %r12, %rsi
callq 0x21d0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x21f0
movq %rax, %r14
movl $0x6, %edx
movq %rax, %rdi
leaq 0x17c2(%rip), %rsi      # 0x409d
callq 0x21f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2923
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21b0
movl $0x9, %edx
movq %rbx, %rdi
leaq 0x1772(%rip), %rsi      # 0x40a4
callq 0x21f0
shlq $0x20, %r15
movabsq $0x200000000, %rax      # imm = 0x200000000
addq %rax, %r15
sarq $0x20, %r15
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq $-0x1, %rcx
callq 0x21d0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbx, %rdi
leaq 0x20(%rsp), %r14
callq 0x21f0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2994
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0xb8(%rsp), %r15
leaq 0xc(%rsp), %rbp
jmp 0x2a08
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x2ba6
leaq 0xf8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2e82
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x29fb
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0xf8(%rsp), %rdi
callq 0x2d74
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x2a1f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x2a44
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x21b0
cmpq $-0x1, 0xb0(%rsp)
je 0x2697
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2a6f
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21b0
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2b82
movq 0xe8(%rsp), %rsi
jmp 0x2b7a
jmp 0x2b16
jmp 0x2b16
movq %rax, %r15
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x2b8c
jmp 0x2b0f
movq %rax, %r15
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2b46
movq 0xa0(%rsp), %rsi
jmp 0x2afa
movq %rax, %r15
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2b46
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x2b46
jmp 0x2b1d
jmp 0x2b0a
jmp 0x2b0a
movq %rax, %r15
jmp 0x2b3c
movq %rax, %r15
jmp 0x2b5d
jmp 0x2b43
movq %rax, %r15
jmp 0x2b82
jmp 0x2b43
movq %rax, %r15
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2b3c
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x20(%rsp), %r14
jmp 0x2b46
movq %rax, %r15
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x2b5d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x2b82
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2b9e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %r15, %rdi
callq 0x22b0