// File: /workspace/github_cpp_makefile_star2_O1/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 0xb3ef(%rip), %rsi      # 0x13700
leaq 0xb3fd(%rip), %rdx      # 0x13715
leaq 0x2f0(%rsp), %r15
movq %r15, %rdi
callq 0x5b6c
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x8335
callq 0x33d0
cmpq $0x100, 0x8(%r14)       # imm = 0x100
jb 0x8378
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8351
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x2e0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb3b2(%rip), %rsi      # 0x13716
leaq 0xb3bc(%rip), %rdx      # 0x13727
leaq 0x2d0(%rsp), %rbx
jmp 0x85b5
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 0x8515
movl (%rbx), %edi
leaq 0x6(%rsp), %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x2, %rax
jne 0x854b
cmpb $0x5, 0x6(%rsp)
jne 0x8581
cmpb $0x0, 0x7(%rsp)
jne 0x8581
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xb361(%rip), %rsi      # 0x13743
leaq 0xb35c(%rip), %rdx      # 0x13745
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x5b6c
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 0x85de
movl (%rbx), %edi
leaq 0x2(%rsp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x4, %rax
jne 0x8624
cmpb $0x5, 0x2(%rsp)
jne 0x8667
cmpb $0x0, 0x3(%rsp)
je 0x86cc
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x84c1
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movzbl 0x3(%rsp), %eax
decl %eax
cmpl $0x7, %eax
ja 0x88c1
leaq 0xadb8(%rip), %rcx      # 0x13290
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x200(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb271(%rip), %rsi      # 0x13765
leaq 0xb286(%rip), %rdx      # 0x13781
leaq 0x1f0(%rsp), %rdi
callq 0x5b6c
movq 0x1f0(%rsp), %rdi
jmp 0x86a8
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8527
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x2c0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb15d(%rip), %rsi      # 0x13697
leaq 0xb16c(%rip), %rdx      # 0x136ad
leaq 0x2b0(%rsp), %rbx
jmp 0x85b5
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x855d
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x2a0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb13e(%rip), %rsi      # 0x136ae
leaq 0xb153(%rip), %rdx      # 0x136ca
leaq 0x290(%rsp), %rbx
jmp 0x85b5
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8593
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x280(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xb182(%rip), %rsi      # 0x13728
leaq 0xb195(%rip), %rdx      # 0x13742
leaq 0x270(%rsp), %rbx
movq %rbx, %rdi
callq 0x5b6c
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x85ca
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 0x85f0
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x260(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb094(%rip), %rsi      # 0x13697
leaq 0xb0a3(%rip), %rdx      # 0x136ad
leaq 0x250(%rsp), %rdi
callq 0x5b6c
movq 0x250(%rsp), %rdi
jmp 0x86a8
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8636
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x240(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb065(%rip), %rsi      # 0x136ae
leaq 0xb07a(%rip), %rdx      # 0x136ca
leaq 0x230(%rsp), %rdi
callq 0x5b6c
movq 0x230(%rsp), %rdi
jmp 0x86a8
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8679
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x220(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb0ba(%rip), %rsi      # 0x13746
leaq 0xb0d1(%rip), %rdx      # 0x13764
leaq 0x210(%rsp), %rdi
callq 0x5b6c
movq 0x210(%rsp), %rdi
cmpq %rbx, %rdi
je 0x86b2
callq 0x33d0
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x85cc
callq 0x33d0
jmp 0x85cc
cmpb $0x0, 0x4(%rsp)
je 0x8716
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x86e5
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0xe0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb17f(%rip), %rsi      # 0x13877
leaq 0xb197(%rip), %rdx      # 0x13896
leaq 0xd0(%rsp), %rdi
callq 0x5b6c
movq 0xd0(%rsp), %rdi
jmp 0x86a8
movzbl 0x5(%rsp), %eax
movl (%rbx), %edi
cmpl $0x4, %eax
je 0x8930
cmpl $0x3, %eax
je 0x88f5
cmpl $0x1, %eax
jne 0x89d6
leaq 0x310(%rsp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x4, %rax
jmp 0x8948
leaq 0x180(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb07d(%rip), %rsi      # 0x137e5
leaq 0xb095(%rip), %rdx      # 0x13804
leaq 0x170(%rsp), %rdi
callq 0x5b6c
movq 0x170(%rsp), %rdi
jmp 0x86a8
leaq 0x1c0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb00a(%rip), %rsi      # 0x137a6
leaq 0xb023(%rip), %rdx      # 0x137c6
leaq 0x1b0(%rsp), %rdi
callq 0x5b6c
movq 0x1b0(%rsp), %rdi
jmp 0x86a8
leaq 0x1a0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xaff7(%rip), %rsi      # 0x137c7
leaq 0xb00d(%rip), %rdx      # 0x137e4
leaq 0x190(%rsp), %rdi
callq 0x5b6c
movq 0x190(%rsp), %rdi
jmp 0x86a8
leaq 0x120(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xb036(%rip), %rsi      # 0x1383a
leaq 0xb056(%rip), %rdx      # 0x13861
leaq 0x110(%rsp), %rdi
callq 0x5b6c
movq 0x110(%rsp), %rdi
jmp 0x86a8
leaq 0x1e0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xaf4a(%rip), %rsi      # 0x13782
leaq 0xaf66(%rip), %rdx      # 0x137a5
leaq 0x1d0(%rsp), %rdi
callq 0x5b6c
movq 0x1d0(%rsp), %rdi
jmp 0x86a8
leaq 0x160(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xaf99(%rip), %rsi      # 0x13805
leaq 0xafaa(%rip), %rdx      # 0x1381d
leaq 0x150(%rsp), %rdi
callq 0x5b6c
movq 0x150(%rsp), %rdi
jmp 0x86a8
leaq 0x140(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xaf7e(%rip), %rsi      # 0x1381e
leaq 0xaf92(%rip), %rdx      # 0x13839
leaq 0x130(%rsp), %rdi
callq 0x5b6c
movq 0x130(%rsp), %rdi
jmp 0x86a8
leaq 0x100(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xaf8e(%rip), %rsi      # 0x13862
leaq 0xaf9b(%rip), %rdx      # 0x13876
leaq 0xf0(%rsp), %rdi
callq 0x5b6c
movq 0xf0(%rsp), %rdi
jmp 0x86a8
leaq 0x310(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x1, %rax
jne 0x8a51
leaq 0x310(%rsp), %rsi
movsbq (%rsi), %r14
movl (%rbx), %edi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x3140
cmpq %r14, %rax
jmp 0x8948
leaq 0x310(%rsp), %rsi
movl $0x10, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x10, %rax
setne %al
movl (%rbx), %edi
testb %al, %al
je 0x898f
cmpl $-0x1, %edi
je 0x8961
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x80(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xaf23(%rip), %rsi      # 0x13897
leaq 0xaf34(%rip), %rdx      # 0x138af
leaq 0x70(%rsp), %rdi
callq 0x5b6c
movq 0x70(%rsp), %rdi
jmp 0x8a80
leaq 0x310(%rsp), %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x3140
cmpq $0x2, %rax
jne 0x8a17
leaq 0x40(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xaef7(%rip), %rsi      # 0x138b0
leaq 0xaf04(%rip), %rdx      # 0x138c4
leaq 0x30(%rsp), %rdi
callq 0x5b6c
movq 0x30(%rsp), %rdi
movb $0x1, %bl
jmp 0x8a82
cmpl $-0x1, %edi
je 0x89e6
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0xa0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xae7e(%rip), %rsi      # 0x13877
leaq 0xae96(%rip), %rdx      # 0x13896
leaq 0x90(%rsp), %rdi
callq 0x5b6c
movq 0x90(%rsp), %rdi
jmp 0x8a80
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0x8a29
callq 0x36e0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x60(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xae5e(%rip), %rsi      # 0x13897
leaq 0xae6f(%rip), %rdx      # 0x138af
leaq 0x50(%rsp), %rdi
callq 0x5b6c
movq 0x50(%rsp), %rdi
jmp 0x8a80
leaq 0xc0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xae33(%rip), %rsi      # 0x13897
leaq 0xae44(%rip), %rdx      # 0x138af
leaq 0xb0(%rsp), %rdi
callq 0x5b6c
movq 0xb0(%rsp), %rdi
xorl %ebx, %ebx
cmpq %r14, %rdi
je 0x86b4
callq 0x33d0
jmp 0x86b4
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
jmp 0x8ac1
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x8ad3
callq 0x33d0
movq %rbx, %rdi
callq 0x3650
nop