// File: theuni[P]libbtcnet/src/bareproxy.cpp
// Function: CBareProxy::write_auth(bufferevent*, CProxyAuth const&)
bool CBareProxy::write_auth(bufferevent* bev, const CProxyAuth& auth)
{
    const std::string& username = auth.GetUsername();
    const std::string& password = auth.GetPassword();
    // Perform username/password authentication (as described in RFC1929)
    std::vector<uint8_t> vAuth;
    vAuth.push_back(0x01);
    if (username.size() > 255 || password.size() > 255)
        return false;
    vAuth.push_back(username.size());
    vAuth.insert(vAuth.end(), username.begin(), username.end());
    vAuth.push_back(password.size());
    vAuth.insert(vAuth.end(), password.begin(), password.end());
    bufferevent_setwatermark(bev, EV_READ, 2, 0);
    bufferevent_write(bev, &vAuth[0], vAuth.size());
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9420
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9430
movq %rax, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x71a0
movq -0xc0(%rbp), %rdi
movb $0x1, -0x41(%rbp)
leaq -0x41(%rbp), %rsi
callq 0xceb0
jmp 0x1fa13
movq -0x20(%rbp), %rdi
callq 0x5330
cmpq $0xff, %rax
ja 0x1fa35
movq -0x28(%rbp), %rdi
callq 0x5330
cmpq $0xff, %rax
jbe 0x1fa5f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
jmp 0x1fbf5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5c60
jmp 0x1fc0c
movq -0x20(%rbp), %rdi
callq 0x5330
movb %al, -0x59(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x59(%rbp), %rsi
callq 0xceb0
jmp 0x1fa7a
leaq -0x40(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x74a0
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x20390
movq -0x20(%rbp), %rdi
callq 0x53f0
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5790
movq -0xd0(%rbp), %rdi
movq %rax, -0x80(%rbp)
movq -0x68(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rcx
callq 0x202e0
movq %rax, -0xc8(%rbp)
jmp 0x1fad6
movq -0xc8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rdi
callq 0x5330
movb %al, -0x89(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x89(%rbp), %rsi
callq 0xceb0
jmp 0x1fb05
leaq -0x40(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x74a0
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x20390
movq -0x28(%rbp), %rdi
callq 0x53f0
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x5790
movq -0xe0(%rbp), %rdi
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq -0xb0(%rbp), %rcx
callq 0x202e0
movq %rax, -0xd8(%rbp)
jmp 0x1fb79
movq -0xd8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movl $0x2, %esi
movl $0x2, %edx
callq 0x50f0
jmp 0x1fba0
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x1e6a0
movq -0xf8(%rbp), %rdi
movq %rax, -0xe8(%rbp)
callq 0x6b00
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq %rax, %rdx
callq 0x5240
jmp 0x1fbea
movb $0x1, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5c60
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x5710
nopw %cs:(%rax,%rax)