// File: /workspace/github_cpp_makefile_star2_O3/tenup-coin[P]seeder/netbase.cpp
// Function: Socks5(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, unsigned int&)
bool static Socks5(string strDest, int port, SOCKET& hSocket)
{
    printf("SOCKS5 connecting %s\n", strDest.c_str());
    if (strDest.size() > 255)
    {
        closesocket(hSocket);
        return error("Hostname too long");
    }
    char pszSocks5Init[] = "\5\1\0";
    char *pszSocks5 = pszSocks5Init;
    ssize_t nSize = sizeof(pszSocks5Init) - 1;

    ssize_t ret = send(hSocket, pszSocks5, nSize, MSG_NOSIGNAL);
    if (ret != nSize)
    {
        closesocket(hSocket);
        return error("Error sending to proxy");
    }
    char pchRet1[2];
    if (recv(hSocket, pchRet1, 2, 0) != 2)
    {
        closesocket(hSocket);
        return error("Error reading proxy response");
    }
    if (pchRet1[0] != 0x05 || pchRet1[1] != 0x00)
    {
        closesocket(hSocket);
        return error("Proxy failed to initialize");
    }
    string strSocks5("\5\1");
    strSocks5 += '\000'; strSocks5 += '\003';
    strSocks5 += static_cast<char>(std::min((int)strDest.size(), 255));
    strSocks5 += strDest;
    strSocks5 += static_cast<char>((port >> 8) & 0xFF);
    strSocks5 += static_cast<char>((port >> 0) & 0xFF);
    ret = send(hSocket, strSocks5.c_str(), strSocks5.size(), MSG_NOSIGNAL);
    if (ret != (ssize_t)strSocks5.size())
    {
        closesocket(hSocket);
        return error("Error sending to proxy");
    }
    char pchRet2[4];
    if (recv(hSocket, pchRet2, 4, 0) != 4)
    {
        closesocket(hSocket);
        return error("Error reading proxy response");
    }
    if (pchRet2[0] != 0x05)
    {
        closesocket(hSocket);
        return error("Proxy failed to accept request");
    }
    if (pchRet2[1] != 0x00)
    {
        closesocket(hSocket);
        switch (pchRet2[1])
        {
            case 0x01: return error("Proxy error: general failure");
            case 0x02: return error("Proxy error: connection not allowed");
            case 0x03: return error("Proxy error: network unreachable");
            case 0x04: return error("Proxy error: host unreachable");
            case 0x05: return error("Proxy error: connection refused");
            case 0x06: return error("Proxy error: TTL expired");
            case 0x07: return error("Proxy error: protocol error");
            case 0x08: return error("Proxy error: address type not supported");
            default:   return error("Proxy error: unknown");
        }
    }
    if (pchRet2[2] != 0x00)
    {
        closesocket(hSocket);
        return error("Error: malformed proxy response");
    }
    char pchRet3[256];
    switch (pchRet2[3])
    {
        case 0x01: ret = recv(hSocket, pchRet3, 4, 0) != 4; break;
        case 0x04: ret = recv(hSocket, pchRet3, 16, 0) != 16; break;
        case 0x03:
        {
            ret = recv(hSocket, pchRet3, 1, 0) != 1;
            if (ret)
                return error("Error reading from proxy");
            int nRecv = pchRet3[0];
            ret = recv(hSocket, pchRet3, nRecv, 0) != nRecv;
            break;
        }
        default: closesocket(hSocket); return error("Error: malformed proxy response");
    }
    if (ret)
    {
        closesocket(hSocket);
        return error("Error reading from proxy");
    }
    if (recv(hSocket, pchRet3, 2, 0) != 2)
    {
        closesocket(hSocket);
        return error("Error reading from proxy");
    }
    printf("SOCKS5 connected %s\n", strDest.c_str());
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x410, %rsp            # imm = 0x410
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0x300(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xb4f7(%rip), %rsi      # 0x13700
leaq 0xb505(%rip), %rdx      # 0x13715
leaq 0x2f0(%rsp), %r15
movq %r15, %rdi
callq 0x5b14
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x822d
callq 0x33d0
cmpq $0x100, 0x8(%r14)       # imm = 0x100
jb 0x8270
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8249
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x2e0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb4ba(%rip), %rsi      # 0x13716
leaq 0xb4c4(%rip), %rdx      # 0x13727
leaq 0x2d0(%rsp), %rbx
jmp 0x84b0
leaq 0x2c(%rsp), %rsi
movl $0x105, (%rsi)          # imm = 0x105
movl (%rbx), %edi
movl $0x3, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x31e0
cmpq $0x3, %rax
jne 0x8410
movl (%rbx), %edi
leaq 0x6(%rsp), %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x2, %rax
jne 0x8446
cmpb $0x5, 0x6(%rsp)
jne 0x847c
cmpb $0x0, 0x7(%rsp)
jne 0x847c
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xb469(%rip), %rsi      # 0x13743
leaq 0xb464(%rip), %rdx      # 0x13745
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x5b14
movq %r15, %rdi
xorl %esi, %esi
callq 0x3370
leaq 0x8(%rsp), %rdi
movl $0x3, %esi
callq 0x3370
movl 0x8(%r14), %eax
movl $0xff, %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
movsbl %cl, %esi
leaq 0x8(%rsp), %rdi
callq 0x3370
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq 0x8(%rsp), %rdi
callq 0x3120
movl %ebp, %eax
shrl $0x8, %eax
movsbl %al, %esi
leaq 0x8(%rsp), %rdi
callq 0x3370
movsbl %bpl, %esi
leaq 0x8(%rsp), %rdi
callq 0x3370
movl (%rbx), %edi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x31e0
cmpq 0x10(%rsp), %rax
jne 0x84d9
movl (%rbx), %edi
leaq 0x2(%rsp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x4, %rax
jne 0x851f
cmpb $0x5, 0x2(%rsp)
jne 0x8562
movb 0x3(%rsp), %al
testb %al, %al
je 0x85c7
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x83be
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movb 0x3(%rsp), %al
movzbl %al, %eax
decl %eax
cmpl $0x7, %eax
ja 0x87fd
leaq 0xaebd(%rip), %rcx      # 0x13290
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x200(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb376(%rip), %rsi      # 0x13765
leaq 0xb38b(%rip), %rdx      # 0x13781
leaq 0x1f0(%rsp), %rdi
callq 0x5b14
movq 0x1f0(%rsp), %rdi
jmp 0x85a3
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8422
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x2c0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb262(%rip), %rsi      # 0x13697
leaq 0xb271(%rip), %rdx      # 0x136ad
leaq 0x2b0(%rsp), %rbx
jmp 0x84b0
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8458
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x2a0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb243(%rip), %rsi      # 0x136ae
leaq 0xb258(%rip), %rdx      # 0x136ca
leaq 0x290(%rsp), %rbx
jmp 0x84b0
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x848e
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x280(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb287(%rip), %rsi      # 0x13728
leaq 0xb29a(%rip), %rdx      # 0x13742
leaq 0x270(%rsp), %rbx
movq %rbx, %rdi
callq 0x5b14
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x84c5
callq 0x33d0
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x410, %rsp            # imm = 0x410
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x84eb
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x260(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb199(%rip), %rsi      # 0x13697
leaq 0xb1a8(%rip), %rdx      # 0x136ad
leaq 0x250(%rsp), %rdi
callq 0x5b14
movq 0x250(%rsp), %rdi
jmp 0x85a3
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8531
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x240(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb16a(%rip), %rsi      # 0x136ae
leaq 0xb17f(%rip), %rdx      # 0x136ca
leaq 0x230(%rsp), %rdi
callq 0x5b14
movq 0x230(%rsp), %rdi
jmp 0x85a3
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8574
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x220(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb1bf(%rip), %rsi      # 0x13746
leaq 0xb1d6(%rip), %rdx      # 0x13764
leaq 0x210(%rsp), %rdi
callq 0x5b14
movq 0x210(%rsp), %rdi
cmpq %rbx, %rdi
je 0x85ad
callq 0x33d0
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x84c7
callq 0x33d0
jmp 0x84c7
cmpb $0x0, 0x4(%rsp)
je 0x8611
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x85e0
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0xe0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb284(%rip), %rsi      # 0x13877
leaq 0xb29c(%rip), %rdx      # 0x13896
leaq 0xd0(%rsp), %rdi
callq 0x5b14
movq 0xd0(%rsp), %rdi
jmp 0x85a3
movzbl 0x5(%rsp), %eax
movl (%rbx), %edi
cmpl $0x4, %eax
je 0x8872
cmpl $0x3, %eax
je 0x8831
cmpl $0x1, %eax
jne 0x88d9
leaq 0x310(%rsp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x4, %rax
je 0x8890
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8663
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x80(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb221(%rip), %rsi      # 0x13897
leaq 0xb232(%rip), %rdx      # 0x138af
leaq 0x70(%rsp), %rdi
callq 0x5b14
movq 0x70(%rsp), %rdi
jmp 0x8983
leaq 0x180(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb141(%rip), %rsi      # 0x137e5
leaq 0xb159(%rip), %rdx      # 0x13804
leaq 0x170(%rsp), %rdi
callq 0x5b14
movq 0x170(%rsp), %rdi
jmp 0x85a3
leaq 0x1c0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb0ce(%rip), %rsi      # 0x137a6
leaq 0xb0e7(%rip), %rdx      # 0x137c6
leaq 0x1b0(%rsp), %rdi
callq 0x5b14
movq 0x1b0(%rsp), %rdi
jmp 0x85a3
leaq 0x1a0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb0bb(%rip), %rsi      # 0x137c7
leaq 0xb0d1(%rip), %rdx      # 0x137e4
leaq 0x190(%rsp), %rdi
callq 0x5b14
movq 0x190(%rsp), %rdi
jmp 0x85a3
leaq 0x120(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb0fa(%rip), %rsi      # 0x1383a
leaq 0xb11a(%rip), %rdx      # 0x13861
leaq 0x110(%rsp), %rdi
callq 0x5b14
movq 0x110(%rsp), %rdi
jmp 0x85a3
leaq 0x1e0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb00e(%rip), %rsi      # 0x13782
leaq 0xb02a(%rip), %rdx      # 0x137a5
leaq 0x1d0(%rsp), %rdi
callq 0x5b14
movq 0x1d0(%rsp), %rdi
jmp 0x85a3
leaq 0x160(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb05d(%rip), %rsi      # 0x13805
leaq 0xb06e(%rip), %rdx      # 0x1381d
leaq 0x150(%rsp), %rdi
callq 0x5b14
movq 0x150(%rsp), %rdi
jmp 0x85a3
leaq 0x140(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb042(%rip), %rsi      # 0x1381e
leaq 0xb056(%rip), %rdx      # 0x13839
leaq 0x130(%rsp), %rdi
callq 0x5b14
movq 0x130(%rsp), %rdi
jmp 0x85a3
leaq 0x100(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb052(%rip), %rsi      # 0x13862
leaq 0xb05f(%rip), %rdx      # 0x13876
leaq 0xf0(%rsp), %rdi
callq 0x5b14
movq 0xf0(%rsp), %rdi
jmp 0x85a3
leaq 0x310(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x1, %rax
jne 0x8954
leaq 0x310(%rsp), %rsi
movsbq (%rsi), %r14
movl (%rbx), %edi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x3140
cmpq %r14, %rax
jne 0x8651
jmp 0x8890
leaq 0x310(%rsp), %rsi
movl $0x10, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x10, %rax
jne 0x8651
movl (%rbx), %edi
leaq 0x310(%rsp), %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x2, %rax
jne 0x891a
leaq 0x40(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xaff4(%rip), %rsi      # 0x138b0
leaq 0xb001(%rip), %rdx      # 0x138c4
leaq 0x30(%rsp), %rdi
callq 0x5b14
movq 0x30(%rsp), %rdi
movb $0x1, %bl
jmp 0x8985
cmpl $-0x1, %edi
je 0x88e9
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0xa0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xaf7b(%rip), %rsi      # 0x13877
leaq 0xaf93(%rip), %rdx      # 0x13896
leaq 0x90(%rsp), %rdi
callq 0x5b14
movq 0x90(%rsp), %rdi
jmp 0x8983
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x892c
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x60(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xaf5b(%rip), %rsi      # 0x13897
leaq 0xaf6c(%rip), %rdx      # 0x138af
leaq 0x50(%rsp), %rdi
callq 0x5b14
movq 0x50(%rsp), %rdi
jmp 0x8983
leaq 0xc0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xaf30(%rip), %rsi      # 0x13897
leaq 0xaf41(%rip), %rdx      # 0x138af
leaq 0xb0(%rsp), %rdi
callq 0x5b14
movq 0xb0(%rsp), %rdi
xorl %ebx, %ebx
cmpq %r14, %rdi
je 0x85af
callq 0x33d0
jmp 0x85af
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x89d6
callq 0x33d0
movq %rbx, %rdi
callq 0x3650