// File: /workspace/github_cpp_makefile_star2_O1/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 0x7f2a
movl %eax, %eax
leaq (%rax,%rax,2), %rax
leaq 0x14917(%rip), %rcx     # 0x1c3e0
cmpl $0x0, 0x14(%rcx,%rax,8)
je 0x7c28
leaq (%rcx,%rax,8), %r15
leaq 0x8(%rsp), %rsi
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
movq %r15, %rdi
movl %ebp, %edx
callq 0x7f8f
testb %al, %al
je 0x7e20
movl 0x14(%r15), %eax
cmpl $0x5, %eax
je 0x7c46
cmpl $0x4, %eax
jne 0x7e20
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 0xbaf6(%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 0xa07a
leaq 0x48(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x7b86
callq 0x33d0
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x7b95
callq 0x33d0
movl 0x8(%r14), %eax
movl $0xffff0000, %ecx       # imm = 0xFFFF0000
xorq %rax, %rcx
orq (%r14), %rcx
je 0x7c99
movl 0x8(%rsp), %edi
cmpl $-0x1, %edi
je 0x7bc0
callq 0x36e0
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
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 0xba63(%rip), %xmm0     # 0x13661
movups %xmm0, 0xd(%rax)
movups 0xba4b(%rip), %xmm0     # 0x13654
movups %xmm0, (%rax)
movq %rcx, 0x8(%r14)
movq (%r14), %rax
movb $0x0, (%rax,%rcx)
movq (%r14), %rdi
cmpq %r15, %rdi
jne 0x7e1b
jmp 0x7e20
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 0x7f8f
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8adc
movzwl 0x10(%r14), %esi
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x82e6
movl %eax, %ebp
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7c83
callq 0x33d0
testb %bpl, %bpl
je 0x7e20
movl 0x8(%rsp), %eax
movl %eax, (%rbx)
movb $0x1, %al
jmp 0x7e22
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 0x9664
testb %al, %al
je 0x7d8c
cmpw $0x2, 0x18(%rsp)
jne 0x7d8c
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 0x7dd3
leaq 0xc(%rsp), %rsi
movl $0x8, %edx
movl %ebp, %edi
xorl %ecx, %ecx
callq 0x3140
cmpq $0x8, %rax
jne 0x7e34
cmpb $0x5a, 0xd(%rsp)
jne 0x7e8e
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xb9a2(%rip), %rsi      # 0x136eb
leaq 0xb9af(%rip), %rdx      # 0x136ff
leaq 0x58(%rsp), %rdi
callq 0x5b6c
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0xa07a
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x7d76
callq 0x33d0
movq 0x58(%rsp), %rdi
movb $0x1, %bpl
cmpq %r12, %rdi
jne 0x7e7e
jmp 0x7e83
movl 0x8(%rsp), %edi
cmpl $-0x1, %edi
je 0x7da2
callq 0x36e0
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
leaq 0x128(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb8bd(%rip), %rsi      # 0x13672
leaq 0xb8da(%rip), %rdx      # 0x13696
leaq 0x118(%rsp), %rdi
callq 0x5b6c
movq 0x118(%rsp), %rdi
jmp 0x7e16
cmpl $-0x1, %ebp
je 0x7de7
movl %ebp, %edi
callq 0x36e0
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
leaq 0x108(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb89d(%rip), %rsi      # 0x13697
leaq 0xb8ac(%rip), %rdx      # 0x136ad
leaq 0xf8(%rsp), %rdi
callq 0x5b6c
movq 0xf8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7e20
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 0x7e48
movl %ebp, %edi
callq 0x36e0
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
leaq 0xe8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb853(%rip), %rsi      # 0x136ae
leaq 0xb868(%rip), %rdx      # 0x136ca
leaq 0xd8(%rsp), %rdi
callq 0x5b6c
movq 0xd8(%rsp), %rdi
xorl %ebp, %ebp
cmpq %r14, %rdi
je 0x7e83
callq 0x33d0
testb %bpl, %bpl
jne 0x7c8c
jmp 0x7e20
cmpl $-0x1, %ebp
je 0x7ea2
movl %ebp, %edi
callq 0x36e0
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
cmpb $0x5b, 0xd(%rsp)
jne 0x7ead
xorl %ebp, %ebp
jmp 0x7e83
leaq 0xc8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb80b(%rip), %rsi      # 0x136cb
leaq 0xb823(%rip), %rdx      # 0x136ea
leaq 0xb8(%rsp), %rdi
callq 0x5b6c
movq 0xb8(%rsp), %rdi
jmp 0x7e77
jmp 0x7ef5
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
jne 0x7f1d
jmp 0x7f22
jmp 0x7ef5
jmp 0x7ef5
jmp 0x7ef5
movq %rax, %rbx
jmp 0x7f22
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x7f1d
jmp 0x7f22
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x7f22
callq 0x33d0
movq %rbx, %rdi
callq 0x3650