// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movq %rdi, %rbx
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
callq 0x3c5a
leaq 0x312f(%rip), %rsi      # 0x8135
movq %rax, %rdi
callq 0x4576
leaq 0x31f6(%rip), %rsi      # 0x820b
movq %rax, %rdi
callq 0x4576
callq 0x381e
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0x77fa
cmpq $0x0, 0x48(%rsp)
jne 0x50a7
callq 0x3c5a
leaq 0x306c(%rip), %rsi      # 0x80af
movq %rax, %rdi
callq 0x4576
leaq 0x31d0(%rip), %rsi      # 0x8222
movq %rax, %rdi
callq 0x4576
leaq 0x34ad(%rip), %rsi      # 0x850e
movq %rax, %rdi
callq 0x4576
callq 0x381e
movq %rax, %r14
leaq 0x31ca(%rip), %rsi      # 0x8242
leaq 0xe0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3c1e
leaq 0xe0(%rsp), %rsi
movq %r14, %rdi
callq 0x7060
leaq 0xe0(%rsp), %rdi
callq 0x3170
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
pushq $0x6
popq %rdx
callq 0x3090
movl %eax, (%rbx)
testl %eax, %eax
jns 0x512b
callq 0x3c5a
leaq 0x2fe8(%rip), %rsi      # 0x80af
movq %rax, %rdi
callq 0x4576
leaq 0x2fe3(%rip), %rsi      # 0x80b9
movq %rax, %rdi
callq 0x4576
leaq 0x3429(%rip), %rsi      # 0x850e
movq %rax, %rdi
callq 0x4576
callq 0x381e
movq %rax, %r14
leaq 0x3163(%rip), %rsi      # 0x825f
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3c1e
leaq 0xc0(%rsp), %rsi
movq %r14, %rdi
callq 0x7060
leaq 0xc0(%rsp), %rdi
callq 0x3170
andq $0x0, 0x18(%rsp)
movw $0x2, 0x10(%rsp)
movq 0x40(%rsp), %rdi
callq 0x3350
movq %rax, %r14
testq %rax, %rax
jne 0x51a1
leaq 0x3126(%rip), %rsi      # 0x8277
leaq 0x20(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c1e
callq 0x381e
movq %rax, %r15
leaq 0xa0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x33f0
leaq 0xa0(%rsp), %rsi
movq %r15, %rdi
callq 0x7060
leaq 0xa0(%rsp), %rdi
callq 0x3170
leaq 0x20(%rsp), %rdi
callq 0x3170
movq 0x18(%r14), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x14(%rsp)
movw $0x611e, 0x12(%rsp)     # imm = 0x611E
callq 0x381e
movq %rax, %rdi
callq 0x7046
callq 0x381e
movq %rax, %rdi
callq 0x657a
callq 0x381e
movq %rax, %r14
leaq 0x30c0(%rip), %rsi      # 0x829e
leaq 0x80(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3c1e
leaq 0x80(%rsp), %rsi
pushq $0xa
popq %rdx
movq %r14, %rdi
callq 0x6a20
leaq 0x80(%rsp), %rdi
callq 0x3170
callq 0x381e
movq %rax, %rdi
callq 0x665a
pushq $0x2
popq %rdi
callq 0x3220
movl (%rbx), %edi
leaq 0x10(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x3250
testl %eax, %eax
jns 0x529f
callq 0x3c5a
leaq 0x2e6b(%rip), %rsi      # 0x80af
movq %rax, %rdi
callq 0x4576
leaq 0x3059(%rip), %rsi      # 0x82ac
movq %rax, %rdi
callq 0x4576
leaq 0x32ac(%rip), %rsi      # 0x850e
movq %rax, %rdi
callq 0x4576
callq 0x381e
movq %rax, %r14
leaq 0x3033(%rip), %rsi      # 0x82ac
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3c1e
leaq 0x60(%rsp), %rsi
movq %r14, %rdi
callq 0x7060
leaq 0x60(%rsp), %rdi
callq 0x3170
movl (%rbx), %ebx
leaq 0x40(%rsp), %rdi
callq 0x3170
movl %ebx, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x530d
jmp 0x5318
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3170
jmp 0x52fb
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x530d
jmp 0x5318
jmp 0x5318
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x530d
jmp 0x5318
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x530d
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x3170
jmp 0x531b
jmp 0x5318
jmp 0x5318
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x34d0
nop