// File: /workspace/github_cpp_makefile_star2_O3/syky27[P]TicTacToe/src/DNNetworkConnection.cpp
// Function: DNNetworkConnection::connectToServer()
int DNNetworkConnection::connectToServer()
{
    /* get address from user */
    string remoteAddr;
    int port = 7777;
    DNLogService::sharedObject() << "INFO => " << "Enter remote address: ";
    DNWindow::getInstance().enterServerIPAdress(remoteAddr);

    if (remoteAddr.length() == 0) {
        DNLogService::sharedObject() << "ERROR => " << "Bad input! -- ip address sucked" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Empty ip address  -- exiting"));
    }

    if ((sockDesc = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
        DNLogService::sharedObject() << "ERROR => " << "Can not create socket!" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Cannot create socket!!!"));
    }

    
    sockaddr_in addr;
    memset(&addr, 0, sizeof (addr));
    addr.sin_family = AF_INET;
    hostent * host;
    if ((host = gethostbyname(remoteAddr . c_str())) == NULL) {
        string fekalError("Cannot Resolve Hostname -- exiting !!!");
        DNWindow::getInstance().terminateWithErrorMessage(fekalError);
    }
    addr.sin_addr.s_addr = *((unsigned long *) host -> h_addr_list[0]);
    addr.sin_port = htons(port);

    DNWindow::getInstance().clearScreen();
    DNWindow::getInstance().drawHeader();
    DNWindow::getInstance().middleString(string("Connecting..."), 10);
    DNWindow::getInstance().refreshDN();
    sleep(2);
    
    
    if (connect(sockDesc, (sockaddr *) & addr, sizeof ( addr)) < 0) {
        DNLogService::sharedObject() << "ERROR => " << "Can not connect!" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Can not connect!"));
    }

    return sockDesc;


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %rbx
leaq 0x48(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
callq 0x3f98
leaq 0x366f(%rip), %rsi      # 0x9135
movq %rax, %rdi
callq 0x4ca4
leaq 0x3736(%rip), %rsi      # 0x920b
movq %rax, %rdi
callq 0x4ca4
callq 0x39ee
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x8d52
cmpq $0x0, 0x40(%rsp)
jne 0x5b89
callq 0x3f98
leaq 0x35a8(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4ca4
leaq 0x370c(%rip), %rsi      # 0x9222
movq %rax, %rdi
callq 0x4ca4
leaq 0x39e9(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4ca4
callq 0x39ee
movq %rax, %r14
leaq 0xe8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x36fa(%rip), %rsi      # 0x9242
leaq 0x370f(%rip), %rdx      # 0x925e
leaq 0xd8(%rsp), %rdi
callq 0x404c
leaq 0xd8(%rsp), %rsi
movq %r14, %rdi
callq 0x82b0
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5b89
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x32f0
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x30a0
movl %eax, (%rbx)
testl %eax, %eax
jns 0x5c35
callq 0x3f98
leaq 0x34fc(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4ca4
leaq 0x34f7(%rip), %rsi      # 0x90b9
movq %rax, %rdi
callq 0x4ca4
leaq 0x393d(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4ca4
callq 0x39ee
movq %rax, %r14
leaq 0xc8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x366b(%rip), %rsi      # 0x925f
leaq 0x367b(%rip), %rdx      # 0x9276
leaq 0xb8(%rsp), %rdi
callq 0x404c
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x82b0
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5c35
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x32f0
movq $0x0, 0x10(%rsp)
movw $0x2, 0x8(%rsp)
movq 0x38(%rsp), %rdi
callq 0x3350
movq %rax, %r14
testq %rax, %rax
jne 0x5cee
leaq 0x28(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x360c(%rip), %rsi      # 0x9277
leaq 0x362b(%rip), %rdx      # 0x929d
leaq 0x18(%rsp), %rdi
callq 0x404c
callq 0x39ee
movq %rax, %r15
leaq 0xa8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x3fb6
leaq 0x98(%rsp), %rsi
movq %r15, %rdi
callq 0x82b0
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5cd7
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x32f0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x5cee
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32f0
movq 0x18(%r14), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movw $0x611e, 0xa(%rsp)      # imm = 0x611E
callq 0x39ee
movq %rax, %rdi
callq 0x8296
callq 0x39ee
movq %rax, %rdi
callq 0x7692
callq 0x39ee
movq %rax, %r14
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3567(%rip), %rsi      # 0x929e
leaq 0x356d(%rip), %rdx      # 0x92ab
leaq 0x78(%rsp), %rdi
callq 0x404c
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
movl $0xa, %edx
callq 0x7b46
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x5d74
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32f0
callq 0x39ee
movq %rax, %rdi
callq 0x7794
movl $0x2, %edi
callq 0x3230
movl (%rbx), %edi
leaq 0x8(%rsp), %rsi
movl $0x10, %edx
callq 0x3250
testl %eax, %eax
jns 0x5e1f
callq 0x3f98
leaq 0x3303(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4ca4
leaq 0x34f1(%rip), %rsi      # 0x92ac
movq %rax, %rdi
callq 0x4ca4
leaq 0x3744(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4ca4
callq 0x39ee
movq %rax, %r14
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x34c2(%rip), %rsi      # 0x92ac
leaq 0x34cb(%rip), %rdx      # 0x92bc
leaq 0x58(%rsp), %rdi
callq 0x404c
leaq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0x82b0
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x5e1f
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x32f0
movl (%rbx), %ebx
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x5e38
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x32f0
movl %ebx, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x5f02
movq 0x68(%rsp), %rsi
jmp 0x5ef1
jmp 0x5eff
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5ecb
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x32f0
jmp 0x5ecb
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5f02
movq 0xc8(%rsp), %rsi
jmp 0x5ef1
jmp 0x5eff
jmp 0x5eff
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5f02
movq 0xe8(%rsp), %rsi
jmp 0x5ef1
jmp 0x5eff
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x5f02
movq 0x28(%rsp), %rsi
jmp 0x5ef1
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x5f02
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32f0
jmp 0x5f02
jmp 0x5eff
jmp 0x5eff
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x5f19
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x32f0
movq %rbx, %rdi
callq 0x34b0
nop