// File: /workspace/github_cpp_makefile_star2_O1/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 $0x148, %rsp            # imm = 0x148
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, 0x28(%rsp)
movq %rax, (%rdi)
movq (%rsi), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
callq 0x72f4
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), %rsi
movq %rsi, 0x40(%rbx)
movq (%r15), %rcx
leaq 0x10(%r15), %rax
cmpq %rax, %rcx
je 0x5c74
movq %rcx, (%rdx)
movq (%rax), %rcx
movq %rcx, (%rsi)
jmp 0x5c7a
movups (%rax), %xmm0
movups %xmm0, (%rsi)
movq %rdx, 0x18(%rsp)
leaq 0x20(%rbx), %r14
movq 0x8(%r15), %rcx
movq %rcx, 0x48(%rbx)
movq %rax, (%r15)
movq $0x0, 0x8(%r15)
movb $0x0, 0x10(%r15)
movl $0x80, 0x14(%rsp)
cmpq $0x0, 0x8(%rbx)
je 0x5d0f
movq %rsi, 0x20(%rsp)
leaq 0x28(%rbx), %r15
movq (%rbx), %rdi
leaq 0xc8(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0x4160
testl %eax, %eax
je 0x5df1
movq %rbx, %rdi
movl $0x3a, %esi
movq $-0x1, %rdx
callq 0x46e0
movq %rax, %r12
cmpq $-0x1, %rax
je 0x5e14
leaq -0x1(%r12), %rdx
movq %rbx, %rdi
movl $0x3a, %esi
callq 0x46e0
cmpq $-0x1, %rax
sete %al
jmp 0x5e16
leaq 0x60(%rsp), %r13
movq %r13, -0x10(%r13)
xorl %r15d, %r15d
movq %r15, -0x8(%r13)
movb %r15b, (%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r13)
movq %r15, 0x28(%r13)
leaq 0xa0(%rsp), %rbp
movb %r15b, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq %rbp, -0x10(%rbp)
movq %r15, -0x8(%rbp)
movb %r15b, (%rbp)
leaq 0x50(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4430
movb 0x24(%r12), %al
movb %al, 0x4(%r14)
movl 0x20(%r12), %eax
movl %eax, (%r14)
movq 0x28(%rbx), %rdi
movq 0x28(%r12), %rax
movq %rax, 0x28(%rbx)
movq 0x30(%r12), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%r12), %rax
movq %rax, 0x38(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%r12)
movq %r15, 0x38(%r12)
testq %rdi, %rdi
je 0x5da6
callq 0x4340
movq 0x18(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x4430
movq 0x90(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5dca
callq 0x4340
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x5dd9
callq 0x4340
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x601c
callq 0x4340
jmp 0x601c
movzwl 0xc8(%rsp), %eax
cmpl $0xa, %eax
je 0x5e07
cmpl $0x2, %eax
jne 0x5eb0
leaq 0xca(%rsp), %rax
jmp 0x5eb2
movb $0x1, %al
testq %r12, %r12
sete %cl
cmpq $-0x1, %r12
je 0x5f5e
orb %al, %cl
je 0x5f5e
leaq 0x1(%r12), %rdx
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq $-0x1, %rcx
movq %r15, 0x8(%rsp)
callq 0x4380
cmpq $0x0, 0x58(%rsp)
je 0x5f12
movw $0x0, (%r14)
movq 0x50(%rsp), %rbp
callq 0x4040
movq %rax, %r13
movl (%rax), %eax
movl %eax, 0x10(%rsp)
movl $0x0, (%r13)
leaq 0x30(%rsp), %r15
movq %rbp, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x4120
cmpq %rbp, (%r15)
je 0x602e
movl (%r13), %ecx
testl %ecx, %ecx
je 0x5efe
cmpl $0x22, %ecx
jne 0x5f06
leaq 0xc374(%rip), %rdi      # 0x1221f
callq 0x44c0
xorl %eax, %eax
testq %rax, %rax
je 0x5ec4
cmpw $0x0, (%rax)
jne 0x5ec4
rolw $0x8, %bp
movw %bp, (%rax)
movq $0x0, 0x8(%rbx)
movq (%rbx), %rax
xorl %ecx, %ecx
movb %cl, (%rax)
movw $0x0, 0x20(%rbx)
movb %cl, 0x22(%rbx)
movslq 0x14(%rsp), %rax
leaq 0xc8(%rsp,%rax), %rdx
leaq 0xc8(%rsp), %rsi
movq %r15, %rdi
callq 0x7384
jmp 0x601c
movl 0x10(%rsp), %ecx
movl %ecx, (%r13)
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x5f12
movw %ax, (%r14)
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4380
leaq 0x30(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4430
movq (%r15), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x5f46
callq 0x4340
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq 0x8(%rsp), %r15
je 0x5f5e
callq 0x4340
movq 0x8(%rbx), %r14
cmpq $0x7, %r14
jb 0x5f97
leaq -0x6(%r14), %rdx
leaq 0x50(%rsp), %rdi
movl $0x6, %ecx
movq %rbx, %rsi
callq 0x4380
leaq 0xc21b(%rip), %rsi      # 0x121a0
leaq 0x50(%rsp), %rdi
callq 0x40e0
testl %eax, %eax
sete %bpl
jmp 0x5f99
xorl %ebp, %ebp
cmpq $0x7, %r14
jb 0x5fb2
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5fb2
callq 0x4340
testb %bpl, %bpl
je 0x601c
movb $0x0, 0x7(%rsp)
movq 0x8(%rbx), %rcx
addq $-0x6, %rcx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4380
movq 0x30(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x7b01
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x5ffc
callq 0x4340
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x600f
callq 0x4340
cmpb $0x0, 0x7(%rsp)
jne 0x601c
movw $0x100, 0x22(%rbx)      # imm = 0x100
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc1ea(%rip), %rdi      # 0x1221f
callq 0x4230
cmpl $0x0, (%r13)
jne 0x6049
movl 0x10(%rsp), %ecx
movl %ecx, (%r13)
movq %rax, %rdi
callq 0x4170
callq 0x45c0
jmp 0x5f12
jmp 0x606e
movq %r15, 0x8(%rsp)
movq %rax, %r12
leaq 0x40(%rsp), %rax
jmp 0x6076
jmp 0x608c
movq %rax, %r12
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6094
callq 0x4340
jmp 0x6094
jmp 0x608c
jmp 0x6091
jmp 0x608c
movq %r15, 0x8(%rsp)
movq %rax, %r12
movq 0x18(%rsp), %rax
movq (%rax), %rdi
cmpq 0x20(%rsp), %rdi
je 0x60a8
callq 0x4340
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x60ba
callq 0x4340
movq (%rbx), %rdi
cmpq 0x28(%rsp), %rdi
je 0x60c9
callq 0x4340
movq %r12, %rdi
callq 0x4640
nop