#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 */
typedef int /*<<< orphan*/ sha1_bytes;

/* Variables and functions */
int /*<<< orphan*/ SHA1(unsigned char const *, int const, unsigned char *);
char *cwebsocket_base64_encode(unsigned char const *, int);
int /*<<< orphan*/ memcpy(char *, char const *, int const);
int strlen(char const *);
char *cwebsocket_create_key_challenge_response(const char *seckey) {
  const char *GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
  const int seckey_len = strlen(seckey);
  const int total_len = seckey_len + 36;
  char sha1buf[total_len];
  memcpy(sha1buf, seckey, seckey_len);
  memcpy(&sha1buf[seckey_len], GUID, 36);
  unsigned char sha1_bytes[20];
  SHA1((const unsigned char *)sha1buf, total_len, sha1_bytes);
  return cwebsocket_base64_encode((const unsigned char *)sha1_bytes,
                                  sizeof(sha1_bytes));
}


x86 assembly (clang, -O0):
<cwebsocket_create_key_challenge_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x24,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x48(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   1060 <SHA1@plt>
lea    -0x40(%rbp),%rdi
mov    $0x14,%esi
call   1040 <cwebsocket_base64_encode@plt>
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cwebsocket_create_key_challenge_response>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%r12d
lea    0x24(%r12),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movslq %r12d,%rdi
add    %rbx,%rdi
lea    0xe75(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%r15
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1060 <SHA1@plt>
mov    %r15,%rdi
mov    $0x14,%esi
call   1040 <cwebsocket_base64_encode@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"258EAFA5-E914-47DA-95CA-C5AB0DC85B11\00"
define i8* @cwebsocket_create_key_challenge_response(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [20 x i8]
store i8* %0, i8** %2
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %3
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 36
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
%17 = load i8*, i8** %2
%18 = load i32, i32* %4
%19 = call i32 @memcpy(i8* %16, i8* %17, i32 %18)
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %16, i64 %21
%23 = load i8*, i8** %3
%24 = call i32 @memcpy(i8* %22, i8* %23, i32 36)
%25 = load i32, i32* %5
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%27 = call i32 @SHA1(i8* %16, i32 %25, i8* %26)
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%29 = call i8* @cwebsocket_base64_encode(i8* %28, i32 20)
%30 = load i8*, i8** %6
ret i8* %29
}

LLVM IR (-O2):
@.str = [37 x i8] c"258EAFA5-E914-47DA-95CA-C5AB0DC85B11\00"
define i8* @cwebsocket_create_key_challenge_response(i8* %0) {
%2 = alloca [20 x i8]
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 36
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @memcpy(i8* %6, i8* %0, i32 %3)
%8 = sext i32 %3 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = call i32 @memcpy(i8* %9, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 36)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%12 = call i32 @SHA1(i8* %6, i32 %4, i8* %11)
%13 = call i8* @cwebsocket_base64_encode(i8* %11, i32 20)
ret i8* %13
}