#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *websock_accept_key(char *, char const *, size_t);
char *websock_accept_handshake(char *__restrict dest,
                               const char *__restrict sec_key,
                               size_t sec_key_len) {
  static const char handshake_reply[] = "HTTP/1.1 101 Switching Protocols\r\n"
                                        "Upgrade: websocket\r\n"
                                        "Connection: Upgrade\r\n"
                                        "Sec-WebSocket-Accept: ";
  memcpy(dest, handshake_reply, sizeof handshake_reply - 1);
  dest += sizeof handshake_reply - 1;
  dest = websock_accept_key(dest, sec_key, sec_key_len);
  memcpy(dest, "\r\n\r\n", 4);
  dest += 4;
  return dest;
}


x86 assembly (clang, -O0):
<websock_accept_handshake>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec1(%rip),%rsi
mov    $0x61,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x61,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <websock_accept_key@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeed(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<websock_accept_handshake>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xecb(%rip),%rsi
mov    $0x61,%edx
call   1040 <memcpy@plt>
add    $0x61,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <websock_accept_key@plt>
mov    %rax,%rbx
lea    0xf07(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x4,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@websock_accept_handshake.handshake_reply = internal constant [98 x i8] c"HTTP/1.1 101 Switching Protocols\0D\0AUpgrade: websocket\0D\0AConnection: Upgrade\0D\0ASec-WebSocket-Accept: \00"
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @websock_accept_handshake(i8* noalias %0, i8* noalias %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i8*, i8** %4
%8 = call i32 @memcpy(i8* %7, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @websock_accept_handshake.handshake_reply, i64 0, i64 0), i32 97)
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 97
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i8* @websock_accept_key(i8* %11, i8* %12, i64 %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = call i32 @memcpy(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 4
store i8* %18, i8** %4
%19 = load i8*, i8** %4
ret i8* %19
}

LLVM IR (-O2):
@websock_accept_handshake.handshake_reply = internal constant [98 x i8] c"HTTP/1.1 101 Switching Protocols\0D\0AUpgrade: websocket\0D\0AConnection: Upgrade\0D\0ASec-WebSocket-Accept: \00"
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @websock_accept_handshake(i8* noalias %0, i8* noalias %1, i64 %2) {
%4 = tail call i32 @memcpy(i8* %0, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @websock_accept_handshake.handshake_reply, i64 0, i64 0), i32 97)
%5 = getelementptr inbounds i8, i8* %0, i64 97
%6 = tail call i8* @websock_accept_key(i8* %5, i8* %1, i64 %2)
%7 = tail call i32 @memcpy(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = getelementptr inbounds i8, i8* %6, i64 4
ret i8* %8
}