// File: 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
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x25ed
movq 0x4a0a(%rip), %rdi      # 0x6fd0
leaq 0x2a37(%rip), %rsi      # 0x5004
callq 0x2230
movq %rax, %rdi
movq 0x49e4(%rip), %rsi      # 0x6fc0
callq 0x2260
movl $0x0, -0x4(%rbp)
jmp 0x2c33
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq 0x49d4(%rip), %rdi      # 0x6fd0
movq %rdi, -0x1e8(%rbp)
callq 0x2230
movq %rax, %rdi
leaq 0x2a04(%rip), %rsi      # 0x5016
callq 0x2230
movq %rax, %rdi
movq 0x499f(%rip), %rsi      # 0x6fc0
callq 0x2260
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
leaq -0x14(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x3b30
movq -0x1e0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x3d10
movq -0x1e8(%rbp), %rdi
leaq 0x29bb(%rip), %rsi      # 0x501f
callq 0x2230
movq -0x1e0(%rbp), %rsi
movq %rax, -0x1d8(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x3db0
movq -0x1d8(%rbp), %rdi
movq -0x1d0(%rbp), %rsi
callq 0x21f0
movq %rax, -0x1c8(%rbp)
jmp 0x26a3
movq -0x1c8(%rbp), %rdi
movq 0x490f(%rip), %rsi      # 0x6fc0
callq 0x2260
jmp 0x26b8
leaq -0x38(%rbp), %rdi
callq 0x2160
movq 0x4908(%rip), %rdi      # 0x6fd0
leaq 0x295b(%rip), %rsi      # 0x502a
callq 0x2230
movq %rax, %rdi
movq 0x48e2(%rip), %rsi      # 0x6fc0
callq 0x2260
leaq -0x68(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x3db0
leaq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x2c50
jmp 0x2703
leaq -0xa8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2110
jmp 0x2715
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x32d0
jmp 0x272a
leaq -0xa8(%rbp), %rdi
callq 0x2160
leaq -0x88(%rbp), %rdi
callq 0x3140
jmp 0x2744
jmp 0x2746
jmp 0x2748
leaq -0xc8(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x3db0
jmp 0x275a
leaq 0x28e9(%rip), %rsi      # 0x504a
leaq -0xc8(%rbp), %rdi
callq 0x2c80
movb %al, -0x1e9(%rbp)
jmp 0x2775
movb -0x1e9(%rbp), %al
testb $0x1, %al
jne 0x2784
jmp 0x2907
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x23c0
movq -0x1f8(%rbp), %rdx
leaq 0x2884(%rip), %rsi      # 0x5029
leaq -0xe8(%rbp), %rdi
callq 0x2cb0
jmp 0x27b3
leaq -0xe9(%rbp), %rdi
callq 0x2280
movq 0x480a(%rip), %rdi      # 0x6fd0
leaq 0x2882(%rip), %rsi      # 0x504f
callq 0x2230
movq %rax, -0x200(%rbp)
jmp 0x27db
movq -0x200(%rbp), %rdi
movq 0x47d7(%rip), %rsi      # 0x6fc0
callq 0x2260
jmp 0x27f0
movq 0x47e9(%rip), %rdi      # 0x6fe0
leaq -0xe8(%rbp), %rsi
callq 0x22f0
jmp 0x2805
leaq -0x110(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x2110
jmp 0x281a
leaq -0x14(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3c40
jmp 0x282c
leaq -0x110(%rbp), %rdi
callq 0x2160
leaq -0xe8(%rbp), %rdi
callq 0x2160
jmp 0x2965
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2160
jmp 0x2c3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2c28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2c1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x2160
jmp 0x2c1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2bf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe9(%rbp), %rdi
callq 0x2280
jmp 0x2bf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x28f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x2160
leaq -0xe8(%rbp), %rdi
callq 0x2160
jmp 0x2bf7
leaq 0x275a(%rip), %rsi      # 0x5068
leaq -0xc8(%rbp), %rdi
callq 0x2c80
movb %al, -0x201(%rbp)
jmp 0x2922
movb -0x201(%rbp), %al
testb $0x1, %al
jne 0x292e
jmp 0x2961
movq 0x469b(%rip), %rdi      # 0x6fd0
leaq 0x2731(%rip), %rsi      # 0x506d
callq 0x2230
movq %rax, -0x210(%rbp)
jmp 0x294a
movq -0x210(%rbp), %rdi
movq 0x4668(%rip), %rsi      # 0x6fc0
callq 0x2260
jmp 0x295f
jmp 0x2963
jmp 0x2963
jmp 0x2965
leaq -0x130(%rbp), %rdi
callq 0x2330
leaq -0x150(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x3db0
jmp 0x2983
leaq -0x130(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x22d0
leaq -0x150(%rbp), %rdi
callq 0x2160
leaq -0x130(%rbp), %rdi
leaq 0x26d6(%rip), %rsi      # 0x5086
xorl %eax, %eax
movl %eax, %edx
callq 0x2400
cmpq $-0x1, %rax
je 0x2b58
movq 0x4606(%rip), %rdi      # 0x6fd0
leaq 0x26be(%rip), %rsi      # 0x508f
callq 0x2230
movq %rax, -0x218(%rbp)
jmp 0x29df
movq -0x218(%rbp), %rdi
movq 0x45d3(%rip), %rsi      # 0x6fc0
callq 0x2260
jmp 0x29f4
leaq 0x269f(%rip), %rsi      # 0x509a
xorl %eax, %eax
movl %eax, %edx
leaq -0x130(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x2400
movq -0x220(%rbp), %rsi
movl %eax, -0x154(%rbp)
movslq -0x154(%rbp), %rcx
leaq -0x178(%rbp), %rdi
movl $0x8, %edx
callq 0x2250
jmp 0x2a39
movq 0x4590(%rip), %rdi      # 0x6fd0
leaq -0x178(%rbp), %rsi
callq 0x21f0
movq %rax, -0x228(%rbp)
jmp 0x2a55
movq -0x228(%rbp), %rdi
leaq 0x263a(%rip), %rsi      # 0x509d
callq 0x2230
movq %rax, -0x230(%rbp)
jmp 0x2a71
movq -0x230(%rbp), %rdi
movq 0x4541(%rip), %rsi      # 0x6fc0
callq 0x2260
jmp 0x2a86
leaq -0x178(%rbp), %rdi
callq 0x2160
movq 0x4537(%rip), %rdi      # 0x6fd0
leaq 0x2604(%rip), %rsi      # 0x50a4
callq 0x2230
movq %rax, -0x238(%rbp)
jmp 0x2aae
movl -0x154(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rdx
leaq -0x198(%rbp), %rdi
leaq -0x130(%rbp), %rsi
movq $-0x1, %rcx
callq 0x2250
jmp 0x2ad6
movq -0x238(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x21f0
jmp 0x2aeb
leaq -0x198(%rbp), %rdi
callq 0x2160
movl $0x0, -0x4(%rbp)
movl $0x1, -0x19c(%rbp)
jmp 0x2bc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2beb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x2160
jmp 0x2beb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x2160
jmp 0x2beb
leaq -0x1c0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x2110
jmp 0x2b6d
leaq -0x88(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x32d0
jmp 0x2b82
leaq -0x1c0(%rbp), %rdi
callq 0x2160
leaq -0x88(%rbp), %rdi
callq 0x3140
jmp 0x2b9c
jmp 0x2bb8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x2160
jmp 0x2beb
movl $0x0, -0x19c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x2160
leaq -0xc8(%rbp), %rdi
callq 0x2160
movl -0x19c(%rbp), %eax
testl %eax, %eax
jne 0x2c05
jmp 0x2be6
jmp 0x2746
leaq -0x130(%rbp), %rdi
callq 0x2160
leaq -0xc8(%rbp), %rdi
callq 0x2160
jmp 0x2c1c
leaq -0x88(%rbp), %rdi
callq 0x2d60
leaq -0x68(%rbp), %rdi
callq 0x2160
jmp 0x2c33
leaq -0x88(%rbp), %rdi
callq 0x2d60
leaq -0x68(%rbp), %rdi
callq 0x2160
jmp 0x2c3f
movl -0x4(%rbp), %eax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x23b0
nopl (%rax,%rax)