// File: /workspace/github_cpp_makefile_star2_O1/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 0x3f9a
leaq 0x3679(%rip), %rsi      # 0x9135
movq %rax, %rdi
callq 0x4cb0
leaq 0x3740(%rip), %rsi      # 0x920b
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x8d62
cmpq $0x0, 0x40(%rsp)
jne 0x5b7f
callq 0x3f9a
leaq 0x35b2(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4cb0
leaq 0x3716(%rip), %rsi      # 0x9222
movq %rax, %rdi
callq 0x4cb0
leaq 0x39f3(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0xe8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3704(%rip), %rsi      # 0x9242
leaq 0x3719(%rip), %rdx      # 0x925e
leaq 0xd8(%rsp), %rdi
callq 0x4048
leaq 0xd8(%rsp), %rsi
movq %r14, %rdi
callq 0x82c0
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5b7f
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 0x5c2b
callq 0x3f9a
leaq 0x3506(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4cb0
leaq 0x3501(%rip), %rsi      # 0x90b9
movq %rax, %rdi
callq 0x4cb0
leaq 0x3947(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0xc8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3675(%rip), %rsi      # 0x925f
leaq 0x3685(%rip), %rdx      # 0x9276
leaq 0xb8(%rsp), %rdi
callq 0x4048
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x82c0
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5c2b
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x32f0
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movw $0x2, (%rsp)
movq 0x38(%rsp), %rdi
callq 0x3350
movq %rax, %r14
testq %rax, %rax
jne 0x5ce1
leaq 0x28(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3619(%rip), %rsi      # 0x9277
leaq 0x3638(%rip), %rdx      # 0x929d
leaq 0x18(%rsp), %rdi
callq 0x4048
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 0x3fb8
leaq 0x98(%rsp), %rsi
movq %r15, %rdi
callq 0x82c0
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5cca
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x32f0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x5ce1
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32f0
movq 0x18(%r14), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movw $0x611e, 0x2(%rsp)      # imm = 0x611E
callq 0x39ee
movq %rax, %rdi
callq 0x82a6
callq 0x39ee
movq %rax, %rdi
callq 0x76a2
callq 0x39ee
movq %rax, %r14
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3574(%rip), %rsi      # 0x929e
leaq 0x357a(%rip), %rdx      # 0x92ab
leaq 0x78(%rsp), %rdi
callq 0x4048
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
movl $0xa, %edx
callq 0x7b56
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x5d67
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32f0
callq 0x39ee
movq %rax, %rdi
callq 0x77a4
movl $0x2, %edi
callq 0x3230
movl (%rbx), %edi
movq %rsp, %rsi
movl $0x10, %edx
callq 0x3250
testl %eax, %eax
jns 0x5e10
callq 0x3f9a
leaq 0x3312(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4cb0
leaq 0x3500(%rip), %rsi      # 0x92ac
movq %rax, %rdi
callq 0x4cb0
leaq 0x3753(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x34d1(%rip), %rsi      # 0x92ac
leaq 0x34da(%rip), %rdx      # 0x92bc
leaq 0x58(%rsp), %rdi
callq 0x4048
leaq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0x82c0
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x5e10
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x32f0
movl (%rbx), %ebx
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x5e29
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 0x5ef3
movq 0x68(%rsp), %rsi
jmp 0x5ee2
jmp 0x5ef0
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5ebc
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x32f0
jmp 0x5ebc
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5ef3
movq 0xc8(%rsp), %rsi
jmp 0x5ee2
jmp 0x5ef0
jmp 0x5ef0
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5ef3
movq 0xe8(%rsp), %rsi
jmp 0x5ee2
jmp 0x5ef0
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x5ef3
movq 0x28(%rsp), %rsi
jmp 0x5ee2
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x5ef3
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32f0
jmp 0x5ef3
jmp 0x5ef0
jmp 0x5ef0
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x5f0a
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x32f0
movq %rbx, %rdi
callq 0x34b0