// File: /workspace/github_cpp_makefile_star2_O3/theuni[P]libbtcnet/src/bareproxy.cpp
// Function: CBareProxy::read_final(bufferevent*, void*)
void CBareProxy::read_final(bufferevent* bev, void* ctx)
{
    CBareProxy* data = static_cast<CBareProxy*>(ctx);
    const CConnection& conn = data->m_proxy_connection;
    evbuffer* input = bufferevent_get_input(bev);
    size_t len = evbuffer_get_length(input);
    int result;
    assert(len >= 8);
    char pchRet2[5] = {};
    result = evbuffer_copyout(input, pchRet2, sizeof(pchRet2));
    assert(result == sizeof(pchRet2));
    (void)result;
    if (pchRet2[0] != 0x05 || pchRet2[1] != 0x00) {
        data->ProxyFailure(0);
        return;
    }
    size_t needSize = 6;
    size_t addrsize;
    int sockaddr_size;
    bool ip = true;
    sockaddr_storage addr;
    memset(&addr, 0, sizeof(addr));
    void* writeip = nullptr;
    switch (pchRet2[3]) {
    case 0x01:
        addrsize = 4;
        addr.ss_family = AF_INET;
        sockaddr_size = sizeof(sockaddr_in);
        reinterpret_cast<sockaddr_in*>(&addr)->sin_port = htons(conn.GetPort());
        writeip = &(reinterpret_cast<sockaddr_in*>(&addr)->sin_addr);
        break;
    case 0x04:
        addrsize = 16;
        addr.ss_family = AF_INET6;
        sockaddr_size = sizeof(sockaddr_in6);
        reinterpret_cast<sockaddr_in6*>(&addr)->sin6_port = htons(conn.GetPort());
        writeip = &(reinterpret_cast<sockaddr_in6*>(&addr)->sin6_addr);
        break;
    case 0x03:
        addrsize = pchRet2[4];
        needSize += 1;
        ip = false;
        sockaddr_size = 0;
        break;
    default:
        data->ProxyFailure(0);
        return;
    }

    needSize += addrsize;

    if (len < needSize) {
        bufferevent_setwatermark(bev, EV_READ, needSize, 0);
        return;
    }

    if (ip) {
        result = evbuffer_drain(input, 4);
        assert(result == 0);
        (void)result;
        result = evbuffer_remove(input, writeip, addrsize);
        assert(result == (int)addrsize);
        (void)result;
        // Throw this away.
        char port[2] = {};
        result = evbuffer_remove(input, port, sizeof(port));
        assert(result == sizeof(port));
        (void)result;
    } else {
        result = evbuffer_drain(input, 5 + addrsize + 2);
        assert(result == 0);
        (void)result;
    }

    CConnection ret = conn;
    if (ip && conn.IsDNS() && conn.GetOptions().doResolve == CConnectionOptions::RESOLVE_ONLY)
        ret = CConnection(conn.GetOptions(), conn.GetNetConfig(), conn.GetProxy(), reinterpret_cast<sockaddr*>(&addr), sockaddr_size);
    data->OnProxySuccess(std::move(data->m_bev), std::move(ret));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x658, %rsp            # imm = 0x658
movq %rsi, %rbx
movq %rdi, %r12
movq 0x8(%rsi), %r14
callq 0x4270
movq %rax, %r15
movq %rax, %rdi
callq 0x43a0
cmpq $0x7, %rax
jbe 0x10597
movq %rax, %r13
leaq 0x3c(%rsp), %rsi
movb $0x0, 0x4(%rsi)
movl $0x0, (%rsi)
movl $0x5, %edx
movq %r15, %rdi
callq 0x4060
cmpl $0x5, %eax
jne 0x105b6
cmpb $0x5, 0x3c(%rsp)
jne 0xff7e
cmpb $0x0, 0x3d(%rsp)
jne 0xff7e
xorps %xmm0, %xmm0
movaps %xmm0, 0x270(%rsp)
movaps %xmm0, 0x260(%rsp)
movaps %xmm0, 0x250(%rsp)
movaps %xmm0, 0x240(%rsp)
movaps %xmm0, 0x230(%rsp)
movaps %xmm0, 0x220(%rsp)
movaps %xmm0, 0x210(%rsp)
movaps %xmm0, 0x200(%rsp)
movzbl 0x3f(%rsp), %eax
cmpl $0x1, %eax
je 0xffdb
cmpl $0x3, %eax
je 0xffa4
cmpl $0x4, %eax
jne 0xff7e
leaq 0x208(%rsp), %rax
movq %rax, 0x48(%rsp)
movl $0x1c, 0x44(%rsp)
movl $0x10, %ebp
movw $0xa, %ax
jmp 0xfff9
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0xff8c
callq 0x10d46
movq $0x0, 0x10(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x10(%rax)
jmp 0x10585
movsbq 0x40(%rsp), %rdx
addq $0x7, %rdx
cmpq %rdx, %r13
jb 0x1001e
movq %r15, %rdi
movq %rdx, %rsi
callq 0x43e0
testl %eax, %eax
jne 0x10632
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0x756a
jmp 0x10204
leaq 0x204(%rsp), %rax
movq %rax, 0x48(%rsp)
movl $0x10, 0x44(%rsp)
movl $0x4, %ebp
movw $0x2, %ax
movw %ax, 0x200(%rsp)
movq %r14, %rdi
callq 0x62ec
rolw $0x8, %ax
movw %ax, 0x202(%rsp)
leaq 0x6(%rbp), %rdx
cmpq %rdx, %r13
jae 0x10032
movq %r12, %rdi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x40c0
jmp 0x10585
movl $0x4, %esi
movq %r15, %rdi
callq 0x43e0
testl %eax, %eax
jne 0x105d5
movq %r15, %rdi
movq 0x48(%rsp), %rsi
movq %rbp, %rdx
callq 0x4440
cmpl %ebp, %eax
jne 0x105f4
leaq 0x88(%rsp), %rsi
movw $0x0, (%rsi)
movl $0x2, %edx
movq %r15, %rdi
callq 0x4440
cmpl $0x2, %eax
jne 0x10613
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0x756a
movq %r14, %rdi
callq 0x6156
testb %al, %al
je 0x10204
movq %r14, %rdi
callq 0x6fa8
cmpl $0x2, 0x4(%rax)
jne 0x10204
movq %r14, %rdi
callq 0x6fa8
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x1c(%rax), %xmm2
movups %xmm2, 0x6c(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq %r14, %rdi
callq 0x6fb0
movq %rax, %r15
movups (%rax), %xmm0
leaq 0x290(%rsp), %rdi
movaps %xmm0, -0x10(%rdi)
movq %rax, %rsi
addq $0x10, %rsi
callq 0x4ffe
movups 0x28(%r15), %xmm0
movups %xmm0, 0x2a8(%rsp)
movq %r14, %rdi
callq 0x6fa2
leaq 0x430(%rsp), %rdi
movq %rax, %rsi
callq 0x7684
movups 0x6c(%rsp), %xmm0
movups %xmm0, 0x1c(%rsp)
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x4e0(%rsp), %rdi
leaq 0x280(%rsp), %rsi
leaq 0x430(%rsp), %rdx
leaq 0x200(%rsp), %rcx
movl 0x44(%rsp), %r8d
callq 0x697c
leaq 0x88(%rsp), %rdi
leaq 0x4e0(%rsp), %r14
movq %r14, %rsi
callq 0x10732
movq %r14, %rdi
callq 0x4e48
leaq 0x4c0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1019e
callq 0x4340
leaq 0x4a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x101b4
callq 0x4340
leaq 0x480(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x101ca
callq 0x4340
movq 0x458(%rsp), %rdi
testq %rdi, %rdi
je 0x101dc
callq 0x4340
leaq 0x440(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x101f2
callq 0x4340
movq 0x290(%rsp), %rdi
testq %rdi, %rdi
je 0x10204
callq 0x4340
leaq 0x2c8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x98(%rsp), %rdx
movq -0x10(%rdx), %rcx
cmpq %rdx, %rcx
je 0x1023b
movq %rcx, 0x2b8(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x2c8(%rsp)
jmp 0x10241
movups (%rdx), %xmm0
movups %xmm0, (%rax)
leaq 0xd8(%rsp), %rax
movq -0x48(%rax), %rsi
leaq 0x308(%rsp), %rcx
movq %rsi, -0x48(%rcx)
movq %rdx, -0x50(%rax)
xorl %edx, %edx
movq %rdx, -0x48(%rax)
movb $0x0, -0x40(%rax)
movl -0x30(%rax), %esi
movl %esi, -0x30(%rcx)
movb -0x2c(%rax), %sil
movb %sil, -0x2c(%rcx)
movups -0x28(%rax), %xmm0
movups %xmm0, -0x28(%rcx)
movq -0x18(%rax), %rsi
movq %rsi, -0x18(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, -0x28(%rax)
movq %rdx, -0x18(%rax)
movq %rcx, -0x10(%rcx)
movq -0x10(%rax), %rdx
cmpq %rax, %rdx
je 0x102b7
movq %rdx, 0x2f8(%rsp)
movq 0xd8(%rsp), %rcx
movq %rcx, 0x308(%rsp)
jmp 0x102bd
movups (%rax), %xmm0
movups %xmm0, (%rcx)
leaq 0xf8(%rsp), %rdx
movq -0x28(%rdx), %rdi
movq -0x10(%rdx), %rsi
leaq 0x328(%rsp), %rcx
movq %rdi, -0x28(%rcx)
movq %rax, -0x30(%rdx)
movq $0x0, -0x28(%rdx)
movb $0x0, -0x20(%rdx)
movq %rcx, -0x10(%rcx)
cmpq %rdx, %rsi
je 0x1030c
movq %rsi, 0x318(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x328(%rsp)
jmp 0x10312
movups (%rdx), %xmm0
movups %xmm0, (%rcx)
leaq 0x88(%rsp), %rax
movq 0x68(%rax), %rsi
leaq 0x2b8(%rsp), %rcx
movq %rsi, 0x68(%rcx)
movq %rdx, 0x60(%rax)
xorl %edx, %edx
movq %rdx, 0x68(%rax)
movb $0x0, 0x70(%rax)
movl 0x80(%rax), %esi
movl %esi, 0x80(%rcx)
movb 0x84(%rax), %sil
movb %sil, 0x84(%rcx)
movups 0x88(%rax), %xmm0
movups %xmm0, 0x88(%rcx)
movq 0x98(%rax), %rsi
movq %rsi, 0x98(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x88(%rax)
movq %rdx, 0x98(%rax)
movl $0xb0, %edx
leaq (%rcx,%rdx), %rsi
movq %rsi, 0xa0(%rcx)
movq 0xa0(%rax), %rdi
addq %rax, %rdx
cmpq %rdx, %rdi
je 0x103b8
movq %rdi, 0x358(%rsp)
movq 0x138(%rsp), %rsi
movq %rsi, 0x368(%rsp)
jmp 0x103be
movups (%rdx), %xmm0
movups %xmm0, (%rsi)
movq 0x130(%rsp), %rdi
movq 0x148(%rsp), %rsi
movq %rdi, 0x360(%rsp)
movq %rdx, 0x128(%rsp)
movq $0x0, 0x130(%rsp)
movb $0x0, 0x138(%rsp)
movl $0xd0, %edx
leaq (%rcx,%rdx), %rdi
movq %rdi, 0x378(%rsp)
addq %rax, %rdx
cmpq %rdx, %rsi
je 0x10425
movq %rsi, 0x378(%rsp)
movq 0x158(%rsp), %rsi
movq %rsi, 0x388(%rsp)
jmp 0x1042b
movups (%rdx), %xmm0
movups %xmm0, (%rdi)
leaq 0x10(%rbx), %rsi
movq 0x150(%rsp), %r8
movq 0x168(%rsp), %rdi
movq %r8, 0x380(%rsp)
movq %rdx, 0x148(%rsp)
movq $0x0, 0x150(%rsp)
movb $0x0, 0x158(%rsp)
movl $0xf0, %edx
addq %rdx, %rcx
movq %rcx, 0x398(%rsp)
addq %rdx, %rax
cmpq %rax, %rdi
je 0x10495
movq %rdi, 0x398(%rsp)
movq 0x178(%rsp), %rcx
movq %rcx, 0x3a8(%rsp)
jmp 0x1049b
movups (%rax), %xmm0
movups %xmm0, (%rcx)
movq 0x170(%rsp), %rcx
leaq 0x2b8(%rsp), %rdx
movq %rcx, 0xe8(%rdx)
movq %rax, 0x168(%rsp)
xorl %eax, %eax
movq %rax, 0x170(%rsp)
movb $0x0, 0x178(%rsp)
movb 0x188(%rsp), %cl
movb %cl, 0x100(%rdx)
movl 0x190(%rsp), %ecx
movl %ecx, 0x108(%rdx)
movups 0x198(%rsp), %xmm0
movups %xmm0, 0x110(%rdx)
movups 0x1a8(%rsp), %xmm0
movups %xmm0, 0x120(%rdx)
movups 0x1b4(%rsp), %xmm0
movups %xmm0, 0x12c(%rdx)
movups 0x1c8(%rsp), %xmm0
movups %xmm0, 0x140(%rdx)
movups 0x1d8(%rsp), %xmm0
movups %xmm0, 0x150(%rdx)
movq 0x1e8(%rsp), %rcx
movq %rcx, 0x160(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x1d8(%rsp)
movq %rax, 0x1e8(%rsp)
movups 0x1f0(%rsp), %xmm0
movups %xmm0, 0x168(%rdx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq 0x2b8(%rsp), %rdi
callq 0x4e48
leaq 0x88(%rsp), %rdi
callq 0x4e48
addq $0x658, %rsp            # imm = 0x658
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a64(%rip), %rdi      # 0x14002
leaq 0x3952(%rip), %rsi      # 0x13ef7
leaq 0x3a5f(%rip), %rcx      # 0x1400b
movl $0x8a, %edx
callq 0x4260
leaq 0x3a88(%rip), %rdi      # 0x14045
leaq 0x3933(%rip), %rsi      # 0x13ef7
leaq 0x3a40(%rip), %rcx      # 0x1400b
movl $0x8d, %edx
callq 0x4260
leaq 0x231e(%rip), %rdi      # 0x128fa
leaq 0x3914(%rip), %rsi      # 0x13ef7
leaq 0x3a21(%rip), %rcx      # 0x1400b
movl $0xbd, %edx
callq 0x4260
leaq 0x3a64(%rip), %rdi      # 0x1405f
leaq 0x38f5(%rip), %rsi      # 0x13ef7
leaq 0x3a02(%rip), %rcx      # 0x1400b
movl $0xc0, %edx
callq 0x4260
leaq 0x3a5d(%rip), %rdi      # 0x14077
leaq 0x38d6(%rip), %rsi      # 0x13ef7
leaq 0x39e3(%rip), %rcx      # 0x1400b
movl $0xc5, %edx
callq 0x4260
leaq 0x22c1(%rip), %rdi      # 0x128fa
leaq 0x38b7(%rip), %rsi      # 0x13ef7
leaq 0x39c4(%rip), %rcx      # 0x1400b
movl $0xc9, %edx
callq 0x4260
movq %rax, %rbx
leaq 0x430(%rsp), %rdi
callq 0x779c
jmp 0x10666
movq %rax, %rbx
movq 0x290(%rsp), %rdi
testq %rdi, %rdi
je 0x10691
callq 0x4340
jmp 0x10691
jmp 0x1068e
movq %rax, %rbx
leaq 0x2b8(%rsp), %rdi
callq 0x4e48
jmp 0x10691
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4e48
movq %rbx, %rdi
callq 0x4640