// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0xaf93(%rip), %rsi      # 0x126d0
leaq 0x3f8(%rsp), %r15
leaq 0x30(%rsp), %rdx
movq %r15, %rdi
callq 0x3180
movq %r15, %rdi
callq 0x31d0
cmpq $0x100, 0x8(%r14)       # imm = 0x100
jb 0x7780
movq %rbx, %rdi
callq 0x94a0
leaq 0xaf73(%rip), %rsi      # 0x126e6
leaq 0x3d8(%rsp), %rbx
jmp 0x7936
leaq 0x2c(%rsp), %rsi
movl $0x105, (%rsi)          # imm = 0x105
movl (%rbx), %edi
pushq $0x3
popq %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x31f0
cmpq $0x3, %rax
jne 0x78ed
movl (%rbx), %edi
leaq 0x6(%rsp), %rsi
pushq $0x2
popq %rdx
xorl %ecx, %ecx
callq 0x3130
cmpq $0x2, %rax
jne 0x7906
cmpb $0x5, 0x6(%rsp)
jne 0x791f
cmpb $0x0, 0x7(%rsp)
jne 0x791f
leaq 0xaf37(%rip), %rsi      # 0x12713
leaq 0x8(%rsp), %r15
leaq 0x30(%rsp), %rdx
movq %r15, %rdi
callq 0x3180
movq %r15, %rdi
xorl %esi, %esi
callq 0x3380
leaq 0x8(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x3380
movl 0x8(%r14), %eax
movl $0xff, %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
movsbl %cl, %esi
leaq 0x8(%rsp), %rdi
callq 0x3380
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x3730
movl %ebp, %eax
shrl $0x8, %eax
movsbl %al, %esi
leaq 0x8(%rsp), %rdi
callq 0x3380
movsbl %bpl, %esi
leaq 0x8(%rsp), %rdi
callq 0x3380
movl (%rbx), %edi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x31f0
cmpq 0x10(%rsp), %rax
jne 0x795d
movl (%rbx), %edi
leaq 0x2(%rsp), %rsi
pushq $0x4
popq %rdx
xorl %ecx, %ecx
callq 0x3130
cmpq $0x4, %rax
jne 0x7988
cmpb $0x5, 0x2(%rsp)
jne 0x79b3
cmpb $0x0, 0x3(%rsp)
je 0x79f2
movq %rbx, %rdi
callq 0x94a0
movzbl 0x3(%rsp), %eax
decl %eax
cmpl $0x7, %eax
ja 0x7b97
leaq 0xa9a2(%rip), %rcx      # 0x12260
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xae67(%rip), %rsi      # 0x12735
leaq 0x2f8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x2f8(%rsp), %rdi
jmp 0x79dc
movq %rbx, %rdi
callq 0x94a0
leaq 0xad6b(%rip), %rsi      # 0x12667
leaq 0x3b8(%rsp), %rbx
jmp 0x7936
movq %rbx, %rdi
callq 0x94a0
leaq 0xad69(%rip), %rsi      # 0x1267e
leaq 0x398(%rsp), %rbx
jmp 0x7936
movq %rbx, %rdi
callq 0x94a0
leaq 0xadca(%rip), %rsi      # 0x126f8
leaq 0x378(%rsp), %rbx
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x3180
movq %rbx, %rdi
callq 0x31d0
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x94a0
leaq 0xacfb(%rip), %rsi      # 0x12667
leaq 0x358(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x358(%rsp), %rdi
jmp 0x79dc
movq %rbx, %rdi
callq 0x94a0
leaq 0xace7(%rip), %rsi      # 0x1267e
leaq 0x338(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x338(%rsp), %rdi
jmp 0x79dc
movq %rbx, %rdi
callq 0x94a0
leaq 0xad54(%rip), %rsi      # 0x12716
leaq 0x318(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x318(%rsp), %rdi
callq 0x31d0
xorl %ebx, %ebx
leaq 0x8(%rsp), %rdi
callq 0x31d0
jmp 0x794d
cmpb $0x0, 0x4(%rsp)
je 0x7a24
movq %rbx, %rdi
callq 0x94a0
leaq 0xae3f(%rip), %rsi      # 0x12847
leaq 0x1d8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x1d8(%rsp), %rdi
jmp 0x79dc
movzbl 0x5(%rsp), %eax
cmpl $0x4, %eax
je 0x7bf8
cmpl $0x3, %eax
je 0x7bbd
cmpl $0x1, %eax
jne 0x7c57
movl (%rbx), %edi
leaq 0x30(%rsp), %rsi
pushq $0x4
popq %rdx
xorl %ecx, %ecx
callq 0x3130
cmpq $0x4, %rax
je 0x7c13
movq %rbx, %rdi
callq 0x94a0
leaq 0xadf9(%rip), %rsi      # 0x12867
leaq 0x178(%rsp), %rdi
leaq 0x1(%rsp), %rdx
callq 0x3180
leaq 0x178(%rsp), %rdi
jmp 0x79dc
leaq 0xad21(%rip), %rsi      # 0x127b5
leaq 0x278(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x278(%rsp), %rdi
jmp 0x79dc
leaq 0xacbc(%rip), %rsi      # 0x12776
leaq 0x2b8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x2b8(%rsp), %rdi
jmp 0x79dc
leaq 0xacb7(%rip), %rsi      # 0x12797
leaq 0x298(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x298(%rsp), %rdi
jmp 0x79dc
leaq 0xad04(%rip), %rsi      # 0x1280a
leaq 0x218(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x218(%rsp), %rdi
jmp 0x79dc
leaq 0xac26(%rip), %rsi      # 0x12752
leaq 0x2d8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x2d8(%rsp), %rdi
jmp 0x79dc
leaq 0xac83(%rip), %rsi      # 0x127d5
leaq 0x258(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x258(%rsp), %rdi
jmp 0x79dc
leaq 0xac76(%rip), %rsi      # 0x127ee
leaq 0x238(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x238(%rsp), %rdi
jmp 0x79dc
leaq 0xac94(%rip), %rsi      # 0x12832
leaq 0x1f8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3180
leaq 0x1f8(%rsp), %rdi
jmp 0x79dc
movl (%rbx), %edi
leaq 0x30(%rsp), %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x3130
cmpq $0x1, %rax
jne 0x7cb3
leaq 0x30(%rsp), %rsi
movsbq (%rsi), %r14
movl (%rbx), %edi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x3130
cmpq %r14, %rax
jne 0x7a5f
jmp 0x7c13
movl (%rbx), %edi
leaq 0x30(%rsp), %rsi
pushq $0x10
popq %rdx
xorl %ecx, %ecx
callq 0x3130
cmpq $0x10, %rax
jne 0x7a5f
movl (%rbx), %edi
leaq 0x30(%rsp), %rsi
pushq $0x2
popq %rdx
xorl %ecx, %ecx
callq 0x3130
cmpq $0x2, %rax
jne 0x7c85
leaq 0xac4f(%rip), %rsi      # 0x12880
leaq 0x138(%rsp), %rdi
leaq 0x1(%rsp), %rdx
callq 0x3180
leaq 0x138(%rsp), %rdi
callq 0x31d0
movb $0x1, %bl
jmp 0x79e3
movq %rbx, %rdi
callq 0x94a0
leaq 0xabe1(%rip), %rsi      # 0x12847
leaq 0x198(%rsp), %rdi
leaq 0x1(%rsp), %rdx
callq 0x3180
leaq 0x198(%rsp), %rdi
jmp 0x79dc
movq %rbx, %rdi
callq 0x94a0
leaq 0xabd3(%rip), %rsi      # 0x12867
leaq 0x158(%rsp), %rdi
leaq 0x1(%rsp), %rdx
callq 0x3180
leaq 0x158(%rsp), %rdi
jmp 0x79dc
leaq 0xabad(%rip), %rsi      # 0x12867
leaq 0x1b8(%rsp), %rdi
leaq 0x1(%rsp), %rdx
callq 0x3180
leaq 0x1b8(%rsp), %rdi
jmp 0x79dc
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
jmp 0x7d05
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x31d0
movq %rbx, %rdi
callq 0x3690