// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x7e22
movl %eax, %eax
leaq (%rax,%rax,2), %rax
leaq 0x149e3(%rip), %rcx     # 0x1c3e0
cmpl $0x0, 0x14(%rcx,%rax,8)
je 0x7b54
leaq (%rcx,%rax,8), %r15
leaq 0x8(%rsp), %rsi
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
movq %r15, %rdi
movl %ebp, %edx
callq 0x7e87
testb %al, %al
je 0x7d7c
movl 0x14(%r15), %eax
cmpl $0x5, %eax
je 0x7b72
cmpl $0x4, %eax
jne 0x7d7c
leaq 0x88(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x38(%rsp), %r15
movq $0x15, (%r15)
leaq 0x78(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x3680
movq %rax, (%r12)
movq (%r15), %rcx
movq %rcx, 0x10(%r12)
movups 0xbbc2(%rip), %xmm0     # 0x1363e
movups %xmm0, (%rax)
movabsq $0xa732520676e6974, %rdx # imm = 0xA732520676E6974
movq %rdx, 0xd(%rax)
movq %rcx, 0x8(%r12)
movq (%r12), %rax
movb $0x0, (%rax,%rcx)
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x9f0c
leaq 0x48(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x7aba
callq 0x33d0
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x7ac9
callq 0x33d0
movl 0x8(%r14), %eax
movl $0xffff0000, %ecx       # imm = 0xFFFF0000
xorq %rax, %rcx
orq (%r14), %rcx
je 0x7bc5
movl 0x8(%rsp), %edi
cmpl $-0x1, %edi
je 0x7aec
callq 0x36e0
leaq 0x148(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x38(%rsp), %rbx
movq $0x1d, (%rbx)
leaq 0x138(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x3680
movq %rax, (%r14)
movq (%rbx), %rcx
movq %rcx, 0x10(%r14)
movups 0xbb37(%rip), %xmm0     # 0x13661
movups %xmm0, 0xd(%rax)
movups 0xbb1f(%rip), %xmm0     # 0x13654
movups %xmm0, (%rax)
movq %rcx, 0x8(%r14)
movq (%r14), %rax
movb $0x0, (%rax,%rcx)
movq (%r14), %rdi
cmpq %r15, %rdi
jne 0x7d77
jmp 0x7d7c
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7e87
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x89de
movzwl 0x10(%r14), %esi
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x81de
movl %eax, %ebp
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7baf
callq 0x33d0
testb %bpl, %bpl
je 0x7d7c
movl 0x8(%rsp), %ebp
movl %ebp, (%rbx)
movb $0x1, %al
jmp 0x7d7e
movabsq $0x72657375000000, %rax # imm = 0x72657375000000
movq %rax, 0x2d(%rsp)
movq $0x104, 0x28(%rsp)      # imm = 0x104
leaq 0x14(%rsp), %rdx
movl $0x10, (%rdx)
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x951e
testb %al, %al
je 0x7cbb
cmpw $0x2, 0x18(%rsp)
jne 0x7cbb
movzwl 0x1a(%rsp), %eax
leaq 0x28(%rsp), %rsi
movw %ax, 0x2(%rsi)
movl 0x1c(%rsp), %eax
movl %eax, 0x4(%rsi)
movl 0x8(%rsp), %ebp
movl $0xd, %edx
movl %ebp, %edi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x31e0
cmpl $0xd, %eax
jne 0x7cfa
leaq 0xc(%rsp), %rsi
movl $0x8, %edx
movl %ebp, %edi
xorl %ecx, %ecx
callq 0x3140
cmpq $0x8, %rax
jne 0x7d37
movb 0xd(%rsp), %al
cmpb $0x5a, %al
jne 0x7d90
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xba75(%rip), %rsi      # 0x136eb
leaq 0xba82(%rip), %rdx      # 0x136ff
leaq 0x58(%rsp), %rdi
callq 0x5b14
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x9f0c
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x7ca3
callq 0x33d0
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x7bbc
callq 0x33d0
jmp 0x7bbc
movl 0x8(%rsp), %edi
cmpl $-0x1, %edi
je 0x7cc9
callq 0x36e0
leaq 0x128(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb996(%rip), %rsi      # 0x13672
leaq 0xb9b3(%rip), %rdx      # 0x13696
leaq 0x118(%rsp), %rdi
callq 0x5b14
movq 0x118(%rsp), %rdi
jmp 0x7d72
cmpl $-0x1, %ebp
je 0x7d06
movl %ebp, %edi
callq 0x36e0
leaq 0x108(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb97e(%rip), %rsi      # 0x13697
leaq 0xb98d(%rip), %rdx      # 0x136ad
leaq 0xf8(%rsp), %rdi
callq 0x5b14
movq 0xf8(%rsp), %rdi
jmp 0x7d72
cmpl $-0x1, %ebp
je 0x7d43
movl %ebp, %edi
callq 0x36e0
leaq 0xe8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb958(%rip), %rsi      # 0x136ae
leaq 0xb96d(%rip), %rdx      # 0x136ca
leaq 0xd8(%rsp), %rdi
callq 0x5b14
movq 0xd8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7d7c
callq 0x33d0
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x1, %ebp
je 0x7da0
movl %ebp, %edi
callq 0x36e0
movb 0xd(%rsp), %al
cmpb $0x5b, %al
je 0x7d7c
leaq 0xc8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb914(%rip), %rsi      # 0x136cb
leaq 0xb92c(%rip), %rdx      # 0x136ea
leaq 0xb8(%rsp), %rdi
callq 0x5b14
movq 0xb8(%rsp), %rdi
jmp 0x7d72
jmp 0x7dec
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
jne 0x7e14
jmp 0x7e19
jmp 0x7dec
jmp 0x7dec
jmp 0x7dec
movq %rax, %rbx
jmp 0x7e19
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x7e14
jmp 0x7e19
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x7e19
callq 0x33d0
movq %rbx, %rdi
callq 0x3650
nop