// File: /workspace/github_cpp_makefile_star2_O2/tenup-coin[P]seeder/netbase.cpp
// Function: ConnectSocket(CService const&, unsigned int&, int)
bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
{
    const proxyType &proxy = proxyInfo[addrDest.GetNetwork()];

    // no proxy needed
    if (!proxy.second)
        return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout);

    SOCKET hSocket = INVALID_SOCKET;

    // first connect to proxy server
    if (!ConnectSocketDirectly(proxy.first, hSocket, nTimeout))
        return false;

    // do socks negotiation
    switch (proxy.second) {
    case 4:
        if (!Socks4(addrDest, hSocket))
            return false;
        break;
    case 5:
        if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket))
            return false;
        break;
    default:
        return false;
    }

    hSocketRet = hSocket;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x7416
movl %eax, %eax
imulq $0x18, %rax, %rax
leaq 0x162db(%rip), %r15     # 0x1d410
cmpl $0x0, 0x14(%rax,%r15)
je 0x7291
addq %rax, %r15
movq %rsp, %rsi
orl $-0x1, (%rsi)
movq %r15, %rdi
movl %ebp, %edx
callq 0x745c
testb %al, %al
je 0x7399
movl 0x14(%r15), %eax
cmpl $0x5, %eax
je 0x72ab
cmpl $0x4, %eax
jne 0x7399
leaq 0xb495(%rip), %rsi      # 0x1260e
leaq 0x98(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3180
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x8ea0
leaq 0x20(%rsp), %rdi
callq 0x31d0
leaq 0x98(%rsp), %rdi
callq 0x31d0
movq %r14, %rdi
callq 0x8392
testb %al, %al
je 0x72ec
movabsq $0x72657375000000, %rax # imm = 0x72657375000000
movq %rax, 0x4d(%rsp)
movq $0x104, 0x48(%rsp)      # imm = 0x104
leaq 0x44(%rsp), %rdx
movl $0x10, (%rdx)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x85f4
testb %al, %al
je 0x7315
cmpw $0x2, 0x10(%rsp)
jne 0x7315
movzwl 0x12(%rsp), %eax
leaq 0x48(%rsp), %rsi
movw %ax, 0x2(%rsi)
movl 0x14(%rsp), %eax
movl %eax, 0x4(%rsi)
movl (%rsp), %edi
pushq $0xd
popq %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x31f0
cmpl $0xd, %eax
jne 0x7340
movl (%rsp), %edi
leaq 0x8(%rsp), %rsi
pushq $0x8
popq %rdx
xorl %ecx, %ecx
callq 0x3130
cmpq $0x8, %rax
jne 0x736b
cmpb $0x5a, 0x9(%rsp)
jne 0x73a9
leaq 0xb45c(%rip), %rsi      # 0x126bb
leaq 0x78(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3180
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x8ea0
leaq 0x20(%rsp), %rdi
callq 0x31d0
leaq 0x78(%rsp), %rdi
callq 0x31d0
jmp 0x72e0
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x745c
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x7d1a
movzwl 0x10(%r14), %esi
movq %rsp, %rdx
movq %r15, %rdi
callq 0x7721
movl %eax, %ebp
leaq 0x58(%rsp), %rdi
callq 0x31d0
testb %bpl, %bpl
je 0x7399
movl (%rsp), %eax
movl %eax, (%rbx)
movb $0x1, %al
jmp 0x739b
movq %rsp, %rdi
callq 0x94a0
leaq 0xb329(%rip), %rsi      # 0x12624
leaq 0x138(%rsp), %rbx
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x3180
movq %rbx, %rdi
jmp 0x7394
movq %rsp, %rdi
callq 0x94a0
leaq 0xb31e(%rip), %rsi      # 0x12642
leaq 0x118(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3180
leaq 0x118(%rsp), %rdi
jmp 0x7394
movq %rsp, %rdi
callq 0x94a0
leaq 0xb318(%rip), %rsi      # 0x12667
leaq 0xf8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3180
leaq 0xf8(%rsp), %rdi
jmp 0x7394
movq %rsp, %rdi
callq 0x94a0
leaq 0xb304(%rip), %rsi      # 0x1267e
leaq 0xd8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3180
leaq 0xd8(%rsp), %rdi
callq 0x31d0
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rdi
callq 0x94a0
cmpb $0x5b, 0x9(%rsp)
je 0x7399
leaq 0xb2dc(%rip), %rsi      # 0x1269b
leaq 0xb8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x3180
leaq 0xb8(%rsp), %rdi
jmp 0x7394
jmp 0x740b
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x7404
jmp 0x740b
jmp 0x740b
jmp 0x740b
jmp 0x740b
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x7404
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x31d0
jmp 0x740e
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3690