// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movq 0x8(%rsi), %r15
callq 0x4270
movq %rax, %r14
movq %rax, %rdi
callq 0x43a0
cmpq $0x7, %rax
jbe 0x10948
movq %rax, %rbp
leaq 0x38(%rsp), %rsi
movb $0x0, 0x4(%rsi)
movl $0x0, (%rsi)
movl $0x5, %edx
movq %r14, %rdi
callq 0x4060
cmpl $0x5, %eax
jne 0x10967
cmpb $0x5, 0x38(%rsp)
jne 0x1013a
cmpb $0x0, 0x39(%rsp)
jne 0x1013a
xorps %xmm0, %xmm0
movaps %xmm0, 0x2a0(%rsp)
movaps %xmm0, 0x290(%rsp)
movaps %xmm0, 0x280(%rsp)
movaps %xmm0, 0x270(%rsp)
movaps %xmm0, 0x260(%rsp)
movaps %xmm0, 0x250(%rsp)
movaps %xmm0, 0x240(%rsp)
movaps %xmm0, 0x230(%rsp)
movzbl 0x3b(%rsp), %eax
cmpl $0x4, %eax
je 0x10179
cmpl $0x3, %eax
je 0x10160
cmpl $0x1, %eax
jne 0x1013a
leaq 0x234(%rsp), %r12
movw $0x2, -0x4(%r12)
movq %r15, 0x40(%rsp)
movq %r15, %rdi
callq 0x631c
rolw $0x8, %ax
movw %ax, -0x2(%r12)
movb $0x1, %cl
movl $0x10, %eax
movl $0x4, %r15d
jmp 0x101ad
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x10148
callq 0x10eee
movq $0x0, 0x10(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x10(%rax)
jmp 0x10936
movq %r15, 0x40(%rsp)
movsbq 0x3c(%rsp), %r15
xorl %eax, %eax
movl $0x7, %edx
xorl %ecx, %ecx
xorl %r12d, %r12d
jmp 0x101b2
leaq 0x238(%rsp), %r12
movw $0xa, -0x8(%r12)
movq %r15, 0x40(%rsp)
movq %r15, %rdi
callq 0x631c
rolw $0x8, %ax
movw %ax, -0x6(%r12)
movb $0x1, %cl
movl $0x1c, %eax
movl $0x10, %r15d
movl $0x6, %edx
addq %r15, %rdx
cmpq %rdx, %rbp
jae 0x101ce
movq %r13, %rdi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x40c0
jmp 0x10936
movq %rax, %r13
movq %rcx, %rbp
testb %cl, %cl
je 0x10244
movl $0x4, %esi
movq %r14, %rdi
callq 0x43e0
testl %eax, %eax
jne 0x10986
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x4440
cmpl %r15d, %eax
jne 0x109c4
leaq 0x48(%rsp), %rsi
movw $0x0, (%rsi)
movl $0x2, %edx
movq %r14, %rdi
callq 0x4440
cmpl $0x2, %eax
movq 0x40(%rsp), %r15
je 0x10260
leaq 0x3e53(%rip), %rdi      # 0x1407f
leaq 0x3ccc(%rip), %rsi      # 0x13eff
leaq 0x3dd9(%rip), %rcx      # 0x14013
movl $0xc5, %edx
callq 0x4260
addq $0x7, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x43e0
testl %eax, %eax
movq 0x40(%rsp), %r15
jne 0x109a5
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x75d0
testb %bpl, %bpl
je 0x105a1
movq %r15, %rdi
callq 0x6186
testb %al, %al
je 0x105a1
movq %r15, %rdi
callq 0x701a
cmpl $0x2, 0x4(%rax)
jne 0x105a1
movq %r15, %r12
movq %r15, %rdi
callq 0x701a
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x1c(%rax), %xmm2
movups %xmm2, 0x1dc(%rsp)
movaps %xmm1, 0x1d0(%rsp)
movaps %xmm0, 0x1c0(%rsp)
movq %r12, %rdi
callq 0x7022
movq %rax, %r15
movups (%rax), %xmm0
leaq 0x200(%rsp), %rdi
movaps %xmm0, -0x10(%rdi)
movq %rax, %rsi
addq $0x10, %rsi
callq 0x4ff4
movups 0x28(%r15), %xmm0
movups %xmm0, 0x218(%rsp)
movq %r12, %rdi
callq 0x7014
leaq 0x430(%rsp), %rdi
movq %rax, %rsi
callq 0x76ea
movups 0x1dc(%rsp), %xmm0
movups %xmm0, 0x1c(%rsp)
movaps 0x1c0(%rsp), %xmm0
movaps 0x1d0(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x4e0(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
leaq 0x430(%rsp), %rdx
leaq 0x230(%rsp), %rcx
movl %r13d, %r8d
callq 0x69bc
leaq 0x48(%rsp), %r15
leaq 0x4e0(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x4430
movl 0x20(%r12), %eax
movl %eax, 0x20(%r15)
movb 0x24(%r12), %al
movb %al, 0x24(%r15)
movq 0x28(%r15), %rdi
movq 0x28(%r12), %rax
movq %rax, 0x28(%r15)
movups 0x30(%r12), %xmm0
movups %xmm0, 0x30(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%r12)
movq $0x0, 0x38(%r12)
testq %rdi, %rdi
je 0x103c0
callq 0x4340
leaq 0x88(%rsp), %rdi
leaq 0x520(%rsp), %rsi
callq 0x4430
leaq 0xa8(%rsp), %r13
leaq 0x540(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4430
movl 0x20(%rbp), %eax
movl %eax, 0x20(%r13)
movb 0x24(%rbp), %al
movb %al, 0x24(%r13)
movq 0x28(%r13), %rdi
movq 0x28(%rbp), %rax
movq %rax, 0x28(%r13)
movups 0x30(%rbp), %xmm0
movups %xmm0, 0x30(%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rbp)
movq $0x0, 0x38(%rbp)
testq %rdi, %rdi
je 0x1042c
callq 0x4340
movl $0xa0, %esi
leaq (%r15,%rsi), %rdi
addq %r12, %rsi
callq 0x4430
movl $0xc0, %esi
leaq (%r15,%rsi), %rdi
addq %r12, %rsi
callq 0x4430
movl $0xe0, %eax
addq %rax, %r15
addq %rax, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x4430
movb 0x5e0(%rsp), %al
movb %al, 0x148(%rsp)
movl 0x5e8(%rsp), %eax
movl %eax, 0x150(%rsp)
movups 0x5f0(%rsp), %xmm0
movups %xmm0, 0x158(%rsp)
movups 0x600(%rsp), %xmm0
movups %xmm0, 0x168(%rsp)
movups 0x60c(%rsp), %xmm0
movups %xmm0, 0x174(%rsp)
movups 0x620(%rsp), %xmm0
movups %xmm0, 0x188(%rsp)
movq 0x198(%rsp), %rdi
movups 0x630(%rsp), %xmm0
movups %xmm0, 0x198(%rsp)
movq 0x640(%rsp), %rax
movq %rax, 0x1a8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x630(%rsp)
movq $0x0, 0x640(%rsp)
testq %rdi, %rdi
je 0x10509
callq 0x4340
leaq 0x4e0(%rsp), %rdi
movups 0x168(%rdi), %xmm0
movups %xmm0, 0x1b0(%rsp)
callq 0x4e4e
leaq 0x4c0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1053b
callq 0x4340
leaq 0x4a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10551
callq 0x4340
leaq 0x480(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10567
callq 0x4340
movq 0x458(%rsp), %rdi
testq %rdi, %rdi
je 0x10579
callq 0x4340
leaq 0x440(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1058f
callq 0x4340
movq 0x200(%rsp), %rdi
testq %rdi, %rdi
je 0x105a1
callq 0x4340
leaq 0x2c8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x58(%rsp), %rdx
movq -0x10(%rdx), %rcx
cmpq %rdx, %rcx
je 0x105d2
movq %rcx, 0x2b8(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x2c8(%rsp)
jmp 0x105d8
movups (%rdx), %xmm0
movups %xmm0, (%rax)
leaq 0x98(%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)
movq -0x28(%rax), %rsi
movq %rsi, -0x28(%rcx)
movups -0x20(%rax), %xmm0
movups %xmm0, -0x20(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, -0x28(%rax)
movq %rdx, -0x18(%rax)
movq %rcx, -0x10(%rcx)
movq -0x10(%rax), %rdx
cmpq %rax, %rdx
je 0x1064e
movq %rdx, 0x2f8(%rsp)
movq 0x98(%rsp), %rcx
movq %rcx, 0x308(%rsp)
jmp 0x10654
movups (%rax), %xmm0
movups %xmm0, (%rcx)
leaq 0xb8(%rsp), %rcx
movq -0x28(%rcx), %rdi
movq -0x10(%rcx), %rsi
leaq 0x328(%rsp), %rdx
movq %rdi, -0x28(%rdx)
movq %rax, -0x30(%rcx)
movq $0x0, -0x28(%rcx)
movb $0x0, -0x20(%rcx)
movq %rdx, -0x10(%rdx)
cmpq %rcx, %rsi
je 0x106a3
movq %rsi, 0x318(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x328(%rsp)
jmp 0x106a9
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq 0xb0(%rsp), %rdx
leaq 0x2b8(%rsp), %rax
movq %rdx, 0x68(%rax)
movq %rcx, 0xa8(%rsp)
xorl %ecx, %ecx
movq %rcx, 0xb0(%rsp)
movb $0x0, 0xb8(%rsp)
movl 0xc8(%rsp), %edx
movl %edx, 0x80(%rax)
movb 0xcc(%rsp), %dl
movb %dl, 0x84(%rax)
movq 0xd0(%rsp), %rdx
movq %rdx, 0x88(%rax)
movups 0xd8(%rsp), %xmm0
movups %xmm0, 0x90(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0xd0(%rsp)
movq %rcx, 0xe0(%rsp)
movl $0xb0, %ecx
leaq (%rax,%rcx), %rdx
movq %rdx, 0xa0(%rax)
movq 0xe8(%rsp), %rsi
addq %r14, %rcx
cmpq %rcx, %rsi
je 0x1075c
movq %rsi, 0x358(%rsp)
movq 0xf8(%rsp), %rdx
movq %rdx, 0x368(%rsp)
jmp 0x10762
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq 0xf0(%rsp), %rsi
movq 0x108(%rsp), %rdx
movq %rsi, 0x360(%rsp)
movq %rcx, 0xe8(%rsp)
movq $0x0, 0xf0(%rsp)
movb $0x0, 0xf8(%rsp)
movl $0xd0, %ecx
leaq (%rax,%rcx), %rsi
movq %rsi, 0x378(%rsp)
addq %r14, %rcx
cmpq %rcx, %rdx
je 0x107c9
movq %rdx, 0x378(%rsp)
movq 0x118(%rsp), %rdx
movq %rdx, 0x388(%rsp)
jmp 0x107cf
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
leaq 0x10(%rbx), %rsi
movq 0x110(%rsp), %rdi
movq 0x128(%rsp), %rdx
movq %rdi, 0x380(%rsp)
movq %rcx, 0x108(%rsp)
movq $0x0, 0x110(%rsp)
movb $0x0, 0x118(%rsp)
movl $0xf0, %ecx
addq %rcx, %rax
movq %rax, 0x398(%rsp)
addq %rcx, %r14
cmpq %r14, %rdx
je 0x10839
movq %rdx, 0x398(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x3a8(%rsp)
jmp 0x10840
movups (%r14), %xmm0
movups %xmm0, (%rax)
movq 0x130(%rsp), %rax
leaq 0x2b8(%rsp), %rdx
movq %rax, 0xe8(%rdx)
movq %r14, 0x128(%rsp)
xorl %eax, %eax
movq %rax, 0x130(%rsp)
movb $0x0, 0x138(%rsp)
movb 0x148(%rsp), %cl
movb %cl, 0x100(%rdx)
movl 0x150(%rsp), %ecx
movl %ecx, 0x108(%rdx)
movups 0x158(%rsp), %xmm0
movups %xmm0, 0x110(%rdx)
movups 0x168(%rsp), %xmm0
movups %xmm0, 0x120(%rdx)
movups 0x174(%rsp), %xmm0
movups %xmm0, 0x12c(%rdx)
movups 0x188(%rsp), %xmm0
movups %xmm0, 0x140(%rdx)
movq 0x198(%rsp), %rcx
movq %rcx, 0x150(%rdx)
movq 0x1a0(%rsp), %rcx
movq 0x1a8(%rsp), %rdi
movq %rcx, 0x158(%rdx)
movq %rdi, 0x160(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x198(%rsp)
movq %rax, 0x1a8(%rsp)
movups 0x1b0(%rsp), %xmm0
movups %xmm0, 0x168(%rdx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq 0x2b8(%rsp), %rdi
callq 0x4e4e
leaq 0x48(%rsp), %rdi
callq 0x4e4e
addq $0x658, %rsp            # imm = 0x658
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36bb(%rip), %rdi      # 0x1400a
leaq 0x35a9(%rip), %rsi      # 0x13eff
leaq 0x36b6(%rip), %rcx      # 0x14013
movl $0x8a, %edx
callq 0x4260
leaq 0x36df(%rip), %rdi      # 0x1404d
leaq 0x358a(%rip), %rsi      # 0x13eff
leaq 0x3697(%rip), %rcx      # 0x14013
movl $0x8d, %edx
callq 0x4260
leaq 0x1f71(%rip), %rdi      # 0x128fe
leaq 0x356b(%rip), %rsi      # 0x13eff
leaq 0x3678(%rip), %rcx      # 0x14013
movl $0xbd, %edx
callq 0x4260
leaq 0x1f52(%rip), %rdi      # 0x128fe
leaq 0x354c(%rip), %rsi      # 0x13eff
leaq 0x3659(%rip), %rcx      # 0x14013
movl $0xc9, %edx
callq 0x4260
leaq 0x369c(%rip), %rdi      # 0x14067
leaq 0x352d(%rip), %rsi      # 0x13eff
leaq 0x363a(%rip), %rcx      # 0x14013
movl $0xc0, %edx
callq 0x4260
movq %rax, %rbx
leaq 0x430(%rsp), %rdi
callq 0x7802
jmp 0x109f8
movq %rax, %rbx
movq 0x200(%rsp), %rdi
testq %rdi, %rdi
je 0x10a23
callq 0x4340
jmp 0x10a23
jmp 0x10a0e
movq %rax, %rbx
jmp 0x10a23
movq %rax, %rbx
leaq 0x2b8(%rsp), %rdi
callq 0x4e4e
leaq 0x48(%rsp), %rdi
callq 0x4e4e
movq %rbx, %rdi
callq 0x4640
nop