#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*/ EVP_MD;

/* Variables and functions */
int EVP_MAX_MD_SIZE;
int /*<<< orphan*/ *EVP_sha1();
int /*<<< orphan*/ HMAC(int /*<<< orphan*/ const *, char *, int,
                        unsigned char const *, int, unsigned char *,
                        unsigned int *);
char *base64decode(char *, size_t);
char *base64encode(char *, unsigned int);
int /*<<< orphan*/ free(char *);
scalar_t__ strlen(char const *);
char *HMACSHA1(const unsigned char *hash_string, void *key, size_t key_len) {
  const EVP_MD *evp_md = EVP_sha1();
  unsigned int md_len;
  unsigned char md[EVP_MAX_MD_SIZE];
  char *newkey = base64decode((char *)key, key_len);
  HMAC(evp_md, newkey, (int)key_len, hash_string,
       (int)strlen((const char *)hash_string), md, &md_len);
  free(newkey);
  return base64encode((char *)md, md_len);
}


x86 assembly (clang, -O0):
<HMACSHA1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
call   1060 <EVP_sha1@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <base64decode@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r9
mov    %eax,%r8d
lea    -0x24(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1080 <HMAC@plt>
add    $0x10,%rsp
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <base64encode@plt>
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HMACSHA1>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <EVP_sha1@plt>
mov    %rax,%r12
mov    %rsp,-0x38(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <base64decode@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1050 <strlen@plt>
sub    $0x8,%rsp
lea    -0x2c(%rbp),%r10
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
mov    %r15,%rcx
mov    %eax,%r8d
mov    %rbx,%r9
push   %r10
call   1080 <HMAC@plt>
add    $0x10,%rsp
mov    %r13,%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%esi
mov    %rbx,%rdi
call   1040 <base64encode@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EVP_MAX_MD_SIZE = global i32 0
define i8* @HMACSHA1(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%12 = call i32* (...) @EVP_sha1()
store i32* %12, i32** %7
%13 = load i32, i32* @EVP_MAX_MD_SIZE
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = call i8* @base64decode(i8* %17, i64 %18)
store i8* %19, i8** %11
%20 = load i32*, i32** %7
%21 = load i8*, i8** %11
%22 = load i64, i64* %6
%23 = trunc i64 %22 to i32
%24 = load i8*, i8** %4
%25 = load i8*, i8** %4
%26 = call i64 @strlen(i8* %25)
%27 = trunc i64 %26 to i32
%28 = call i32 @HMAC(i32* %20, i8* %21, i32 %23, i8* %24, i32 %27, i8* %16, i32* %8)
%29 = load i8*, i8** %11
%30 = call i32 @free(i8* %29)
%31 = load i32, i32* %8
%32 = call i8* @base64encode(i8* %16, i32 %31)
%33 = load i8*, i8** %9
ret i8* %32
}

LLVM IR (-O2):
@EVP_MAX_MD_SIZE = global i32 0
define i8* @HMACSHA1(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = tail call i32* (...) @EVP_sha1()
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @EVP_MAX_MD_SIZE
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = tail call i8* @base64decode(i8* %1, i64 %2)
%12 = trunc i64 %2 to i32
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = trunc i64 %13 to i32
%15 = call i32 @HMAC(i32* %5, i8* %11, i32 %12, i8* %0, i32 %14, i8* %10, i32* %4)
%16 = call i32 @free(i8* %11)
%17 = load i32, i32* %4
%18 = call i8* @base64encode(i8* %10, i32 %17)
ret i8* %18
}