#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*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *,
                           char *, char *, char *, char *, char *, char *);
void build_websocket_handshake(char *data) {
  char *hs_get = "GET /chat HTTP/1.1\r\n";
  char *hs_host = "Host: www.example.com\r\n";
  char *hs_upgrade = "Upgrade: Websocket\r\n";
  char *hs_conn = "Connection: Upgrade\r\n";
  char *hs_key = "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n";
  char *hs_origin = "Origin: http://example.com\r\n";
  char *hs_protocol = "Sec-WebSocket-Protocol: chat, superchat\r\n";
  char *hs_version = "Sec-WebSocket-Version: 13\r\n";
  char *hs_device_id = "X-Nomnio-DeviceKey: asddfsdsfgsfghbvrttghhf\r\n";
  char *hs_sub_key = "X-Nomnio-SudirriptionKey: asdfdsdf34rg3dggv34dg\r\n";
  sprintf(data, "%s%s%s%s%s%s%s%s%s%s\r\n", hs_get, hs_host, hs_upgrade,
          hs_conn, hs_key, hs_protocol, hs_version, hs_origin, hs_device_id,
          hs_sub_key);
  printf("handshake_data build\n");
}


x86 assembly (clang, -O0):
<build_websocket_handshake>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,-0x20(%rbp)
lea    0xec5(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xecf(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xedc(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xee6(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xef1(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xf14(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xf26(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xf45(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xf56(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xf79(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    -0x48(%rbp),%r15
mov    -0x58(%rbp),%r14
mov    -0x60(%rbp),%rbx
mov    -0x50(%rbp),%r11
mov    -0x68(%rbp),%r10
mov    -0x70(%rbp),%rax
lea    0xf74(%rip),%rsi
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1040 <sprintf@plt>
lea    0xf62(%rip),%rdi
call   1030 <printf@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_websocket_handshake>:
push   %r15
push   %r14
push   %rbx
lea    0xfeb(%rip),%rax
lea    0xfb6(%rip),%r10
lea    0xf4c(%rip),%r11
lea    0xf8c(%rip),%rbx
lea    0xf5b(%rip),%r14
lea    0xf09(%rip),%r15
lea    0xff3(%rip),%rsi
lea    0xea3(%rip),%rdx
lea    0xeb1(%rip),%rcx
lea    0xec2(%rip),%r8
lea    0xed0(%rip),%r9
push   %rax
push   %r10
push   %r11
push   %rbx
push   %r14
push   %r15
call   1040 <sprintf@plt>
add    $0x30,%rsp
lea    0xfd4(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"GET /chat HTTP/1.1\0D\0A\00"
@.str.1 = [24 x i8] c"Host: www.example.com\0D\0A\00"
@.str.2 = [21 x i8] c"Upgrade: Websocket\0D\0A\00"
@.str.3 = [22 x i8] c"Connection: Upgrade\0D\0A\00"
@.str.4 = [46 x i8] c"Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\0D\0A\00"
@.str.5 = [29 x i8] c"Origin: http://example.com\0D\0A\00"
@.str.6 = [42 x i8] c"Sec-WebSocket-Protocol: chat, superchat\0D\0A\00"
@.str.7 = [28 x i8] c"Sec-WebSocket-Version: 13\0D\0A\00"
@.str.8 = [46 x i8] c"X-Nomnio-DeviceKey: asddfsdsfgsfghbvrttghhf\0D\0A\00"
@.str.9 = [50 x i8] c"X-Nomnio-SudirriptionKey: asdfdsdf34rg3dggv34dg\0D\0A\00"
@.str.10 = [23 x i8] c"%s%s%s%s%s%s%s%s%s%s\0D\0A\00"
@.str.11 = [22 x i8] c"handshake_data build\0A\00"
define void @build_websocket_handshake(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0), i8** %11
store i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.9, i64 0, i64 0), i8** %12
%13 = load i8*, i8** %2
%14 = load i8*, i8** %3
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = load i8*, i8** %7
%19 = load i8*, i8** %9
%20 = load i8*, i8** %10
%21 = load i8*, i8** %8
%22 = load i8*, i8** %11
%23 = load i8*, i8** %12
%24 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %14, i8* %15, i8* %16, i8* %17, i8* %18, i8* %19, i8* %20, i8* %21, i8* %22, i8* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"GET /chat HTTP/1.1\0D\0A\00"
@.str.1 = [24 x i8] c"Host: www.example.com\0D\0A\00"
@.str.2 = [21 x i8] c"Upgrade: Websocket\0D\0A\00"
@.str.3 = [22 x i8] c"Connection: Upgrade\0D\0A\00"
@.str.4 = [46 x i8] c"Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\0D\0A\00"
@.str.5 = [29 x i8] c"Origin: http://example.com\0D\0A\00"
@.str.6 = [42 x i8] c"Sec-WebSocket-Protocol: chat, superchat\0D\0A\00"
@.str.7 = [28 x i8] c"Sec-WebSocket-Version: 13\0D\0A\00"
@.str.8 = [46 x i8] c"X-Nomnio-DeviceKey: asddfsdsfgsfghbvrttghhf\0D\0A\00"
@.str.9 = [50 x i8] c"X-Nomnio-SudirriptionKey: asdfdsdf34rg3dggv34dg\0D\0A\00"
@.str.10 = [23 x i8] c"%s%s%s%s%s%s%s%s%s%s\0D\0A\00"
@str = [21 x i8] c"handshake_data build\00"
define void @build_websocket_handshake(i8* nocapture writeonly %0) {
%2 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.9, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
ret void
}