// File: /workspace/github_cpp_makefile_star2_O3/theuni[P]libbtcnet/src/connection.cpp
// Function: CConnectionBase::CConnectionBase(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned short)
CConnectionBase::CConnectionBase(std::string hostIn, unsigned short portIn)
    : host(hostIn), port(portIn), isDns(true), isOnion(false), isSet(true), connection_string(std::move(hostIn))
{
    sockaddr_storage saddr;
    int addrsize = sizeof(saddr);

    if (host.empty()) {
        *this = CConnectionBase();
        return;
    }

    if (evutil_parse_sockaddr_port(host.c_str(), reinterpret_cast<sockaddr*>(&saddr), &addrsize) == 0) {
        unsigned short* pport = nullptr;
        if (saddr.ss_family == AF_INET) {
            pport = &(reinterpret_cast<sockaddr_in*>(&saddr)->sin_port);

        } else if (saddr.ss_family == AF_INET6) {
            pport = &(reinterpret_cast<sockaddr_in6*>(&saddr)->sin6_port);
        }
        if ((pport != nullptr) && *pport == 0)
            *pport = ntohs(portIn);
        host.clear();
        port = 0;
        isDns = false;
        addr.assign(reinterpret_cast<unsigned char*>(&saddr), reinterpret_cast<unsigned char*>(&saddr) + addrsize);
    } else {
        size_t colon = host.find_last_of(':');
        bool fHaveColon = colon != host.npos;
        bool fMultiColon = fHaveColon && (host.find_last_of(':', colon - 1) != host.npos);
        if (fHaveColon && (colon == 0 || !fMultiColon)) {
            std::string portstr = host.substr(colon + 1);
            if (!portstr.empty()) {
                port = 0;
                try {
                    unsigned long longport = std::stoul(portstr);
                    if (longport <= 65535)
                        port = longport;
                } catch (...) {
                }
            }
            host = host.substr(0, colon);
        }

        if (host.size() > 6 && host.substr(host.size() - 6, 6) == ".onion") {
            bool invalid = false;
            DecodeBase32(host.substr(0, host.size() - 6).c_str(), &invalid);
            if (!invalid) {
                isOnion = true;
                isDns = false;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, 0x18(%rsp)
movq %rax, (%rdi)
movq (%rsi), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
callq 0x7282
movw %bp, 0x20(%rbx)
movw $0x1, 0x22(%rbx)
movb $0x1, 0x24(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rbx)
movq $0x0, 0x38(%rbx)
leaq 0x40(%rbx), %rdx
leaq 0x50(%rbx), %r14
movq %r14, 0x40(%rbx)
movq (%r15), %rcx
leaq 0x10(%r15), %rax
cmpq %rax, %rcx
je 0x5c88
movq %rcx, (%rdx)
movq (%rax), %rcx
movq %rcx, (%r14)
jmp 0x5c8f
movups (%rax), %xmm0
movups %xmm0, (%r14)
movq %rdx, 0x8(%rsp)
leaq 0x20(%rbx), %r13
movq 0x8(%r15), %rcx
movq %rcx, 0x48(%rbx)
movq %rax, (%r15)
movq $0x0, 0x8(%r15)
movb $0x0, 0x10(%r15)
movl $0x80, 0x4(%rsp)
cmpq $0x0, 0x8(%rbx)
je 0x5db0
leaq 0x28(%rbx), %r15
movq (%rbx), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
movq %r15, 0x10(%rsp)
callq 0x4160
testl %eax, %eax
je 0x5e8a
movq %rbx, %rdi
movl $0x3a, %esi
movq $-0x1, %rdx
callq 0x46e0
cmpq $-0x1, %rax
je 0x5f45
movq %rax, %r12
leaq -0x1(%rax), %rdx
movq %rbx, %rdi
movl $0x3a, %esi
callq 0x46e0
cmpq $0x1, %r12
jb 0x5d2b
cmpq $-0x1, %rax
jne 0x5f45
leaq 0x1(%r12), %rdx
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq $-0x1, %rcx
callq 0x4380
cmpq $0x0, 0x48(%rsp)
je 0x5efe
movw $0x0, (%r13)
movq 0x40(%rsp), %rbp
callq 0x4040
movq %rax, %r15
movl (%rax), %eax
movl %eax, (%rsp)
movl $0x0, (%r15)
leaq 0x20(%rsp), %rsi
movq %rbp, %rdi
movl $0xa, %edx
callq 0x4120
leaq 0x20(%rsp), %rcx
cmpq %rbp, (%rcx)
je 0x6008
movl (%r15), %ecx
testl %ecx, %ecx
je 0x5eeb
cmpl $0x22, %ecx
jne 0x5ef1
leaq 0xc474(%rip), %rdi      # 0x1221f
callq 0x44c0
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
xorl %r15d, %r15d
movq %r15, -0x8(%r14)
movb %r15b, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r14)
movq %r15, 0x28(%r14)
leaq 0x90(%rsp), %rbp
movb %r15b, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq %rbp, -0x10(%rbp)
movq %r15, -0x8(%rbp)
movb %r15b, (%rbp)
leaq 0x40(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4430
movl 0x20(%r12), %eax
movl %eax, (%r13)
movb 0x24(%r12), %al
movb %al, 0x4(%r13)
movq 0x28(%rbx), %rdi
movups 0x28(%r12), %xmm0
movups %xmm0, 0x28(%rbx)
movq 0x38(%r12), %rax
movq %rax, 0x38(%rbx)
movq %r15, 0x38(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%r12)
testq %rdi, %rdi
je 0x5e3f
callq 0x4340
movq 0x8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x4430
movq 0x80(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5e63
callq 0x4340
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x5e72
callq 0x4340
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ff6
callq 0x4340
jmp 0x5ff6
movzwl 0xb8(%rsp), %eax
orl $0x8, %eax
cmpl $0xa, %eax
jne 0x5eb1
cmpw $0x0, 0xba(%rsp)
jne 0x5eb1
rolw $0x8, %bp
movw %bp, 0xba(%rsp)
movq $0x0, 0x8(%rbx)
movq (%rbx), %rax
xorl %ecx, %ecx
movb %cl, (%rax)
movw $0x0, 0x20(%rbx)
movb %cl, 0x22(%rbx)
movslq 0x4(%rsp), %rax
leaq 0xb8(%rsp,%rax), %rdx
leaq 0xb8(%rsp), %rsi
movq %r15, %rdi
callq 0x7318
jmp 0x5ff6
movl (%rsp), %ecx
movl %ecx, (%r15)
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x5efe
movw %ax, (%r13)
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4380
leaq 0x20(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4430
movq (%r15), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5f32
callq 0x4340
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5f45
callq 0x4340
movq 0x8(%rbx), %rdx
cmpq $0x7, %rdx
jb 0x5ff6
addq $-0x6, %rdx
leaq 0x40(%rsp), %rdi
movl $0x6, %ecx
movq %rbx, %rsi
callq 0x4380
leaq 0xc230(%rip), %rsi      # 0x121a0
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x40e0
movl %eax, %ebp
movq (%r15), %rdi
leaq 0x50(%rsp), %r15
cmpq %r15, %rdi
je 0x5f91
callq 0x4340
testl %ebp, %ebp
jne 0x5ff6
movb $0x0, 0x20(%rsp)
movq 0x8(%rbx), %rcx
addq $-0x6, %rcx
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4380
movq 0x40(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x7a88
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5fda
callq 0x4340
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x5fe9
callq 0x4340
cmpb $0x0, 0x20(%rsp)
jne 0x5ff6
movw $0x100, 0x22(%rbx)      # imm = 0x100
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc210(%rip), %rdi      # 0x1221f
callq 0x4230
movq %rax, %r12
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
jne 0x6056
jmp 0x6066
jmp 0x6063
cmpl $0x0, (%r15)
jne 0x6031
movl (%rsp), %ecx
movl %ecx, (%r15)
movq %rax, %rdi
callq 0x4170
callq 0x45c0
jmp 0x5efe
jmp 0x6045
movq %rax, %r12
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6066
callq 0x4340
jmp 0x6066
jmp 0x6063
jmp 0x6063
jmp 0x6063
movq %rax, %r12
movq 0x8(%rsp), %rax
movq (%rax), %rdi
cmpq %r14, %rdi
je 0x6078
callq 0x4340
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x608a
callq 0x4340
movq (%rbx), %rdi
cmpq 0x18(%rsp), %rdi
je 0x6099
callq 0x4340
movq %r12, %rdi
callq 0x4640
nop