// File: /workspace/github_cpp_makefile_star2_O3/caelumcao[P]CWebSocketServer/cresponse.cpp
// Function: CResponse::handshark(int, char const*, unsigned int)
int CResponse::handshark(int fd, const char *buf, unsigned int len)
{
    std::string key(buf, len);
    key += MAGIC_KEY;
    SHA1 sha;
    unsigned int message_digest[5];
    sha.Reset();
    sha << key.c_str();
    sha.Result(message_digest);
    for (int i = 0; i < 5; i++)
        message_digest[i] = htonl(message_digest[i]);
    key = base64_encode(reinterpret_cast<const unsigned char*>(message_digest), 20);
    std::string msg;
    msg.append("HTTP/1.1 101 Switching Protocols\r\n");
    msg.append("Connection: Upgrade\r\n");
    msg.append("Sec-WebSocket-Accept: ");
    msg += (key + "\r\n");
    msg.append("Upgrade: websocket\r\n\r\n");
    return write(fd, msg.c_str(), msg.size());
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %esi, %ebx
movq %rdi, %r14
movl %ecx, %eax
leaq 0x50(%rsp), %r12
movq %r12, -0x10(%r12)
addq %rdx, %rax
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0x5c4e
movq (%r14), %rsi
movq %r15, %rdi
callq 0x23f0
leaq 0x78(%rsp), %rdi
callq 0x63a2
leaq 0x78(%rsp), %rdi
callq 0x642c
movq 0x40(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x66c0
leaq 0x78(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x64a0
xorl %eax, %eax
movl 0x60(%rsp,%rax,4), %ecx
bswapl %ecx
movl %ecx, 0x60(%rsp,%rax,4)
incq %rax
cmpq $0x5, %rax
jne 0x5a8e
movq %rsp, %rdi
leaq 0x60(%rsp), %rsi
movl $0x14, %edx
callq 0x5daf
leaq 0x40(%rsp), %rdi
movq %rsp, %r14
movq %r14, %rsi
callq 0x22c0
movq (%r14), %rdi
leaq 0x10(%rsp), %r14
cmpq %r14, %rdi
je 0x5add
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
movq %rsp, %rdi
movq %r14, (%rdi)
movq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
leaq 0x26bc(%rip), %rsi      # 0x81b2
callq 0x23f0
leaq 0x26d3(%rip), %rsi      # 0x81d5
movq %rsp, %rdi
callq 0x23f0
leaq 0x26da(%rip), %rsi      # 0x81eb
movq %rsp, %rdi
callq 0x23f0
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0x5ce4
leaq 0x26d6(%rip), %rsi      # 0x8216
leaq 0x20(%rsp), %rdi
callq 0x23f0
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rsp, %rdi
callq 0x20a0
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x5b73
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2240
leaq 0x2688(%rip), %rsi      # 0x8202
movq %rsp, %rdi
callq 0x23f0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movl %ebx, %edi
callq 0x20d0
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x5bab
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
leaq 0x78(%rsp), %rdi
callq 0x63d0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x5bcc
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2240
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x5bdf
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x5c0e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2240
jmp 0x5c0e
jmp 0x5c0b
jmp 0x5c06
jmp 0x5c01
movq %rax, %rbx
jmp 0x5c2e
movq %rax, %rbx
jmp 0x5c24
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x5c24
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2240
leaq 0x78(%rsp), %rdi
callq 0x63d0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x5c45
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x2390
nop