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

/* Variables and functions */
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ EVP_sha1();
int /*<<< orphan*/ HMAC(int /*<<< orphan*/, char *, int, char *, int, char *,
                        int *);
int /*<<< orphan*/ SHA_DIGEST_LENGTH;
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int main(void) {
  char key[] = "ABC&XYZ";
  int key_len;
  char data[] = "ABCDE";
  int data_len;
  char hmac_sha1[SHA_DIGEST_LENGTH + 1];
  int hmac_sha1_len;
  BIO *mem = NULL;
  BIO *base64 = NULL;
  char base64_str[1024] = {0};
  key_len = strlen(key);
  data_len = strlen(data);
  HMAC(EVP_sha1(), key, key_len, data, data_len, hmac_sha1, &hmac_sha1_len);
  printf("hmac_sha1 = %s\n", hmac_sha1);
  mem = BIO_new(BIO_s_mem());
  base64 = BIO_new(BIO_f_base64());
  BIO_push(base64, mem);
  BIO_write(base64, hmac_sha1, hmac_sha1_len);
  BIO_flush(base64);
  BIO_read(mem, base64_str, 1024);
  printf("base64_str = %s\n", base64_str);
  BIO_free_all(base64);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x5a595826434241,%rax
mov    %rax,-0x10(%rbp)
movw   $0x45,-0x18(%rbp)
movl   $0x44434241,-0x1c(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x458(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
lea    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <EVP_sha1@plt>
mov    -0x458(%rbp),%r9
mov    %eax,%edi
lea    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x1c(%rbp),%rcx
mov    -0x20(%rbp),%r8d
lea    -0x34(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   10a0 <HMAC@plt>
mov    -0x458(%rbp),%rsi
add    $0x10,%rsp
lea    0xd62(%rip),%rdi
call   1080 <printf@plt>
mov    $0x0,%al
call   10e0 <BIO_s_mem@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1070 <BIO_f_base64@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    -0x458(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    -0x34(%rbp),%edx
call   10d0 <BIO_write@plt>
mov    -0x48(%rbp),%rdi
call   10f0 <BIO_flush@plt>
mov    -0x40(%rbp),%rdi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
lea    -0x450(%rbp),%rsi
lea    0xcfd(%rip),%rdi
call   1080 <printf@plt>
mov    -0x48(%rbp),%rdi
call   10c0 <BIO_free_all@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsp,-0x40(%rbp)
movabs $0x5a595826434241,%rax
mov    %rax,-0x48(%rbp)
movw   $0x45,-0x30(%rbp)
movl   $0x44434241,-0x34(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    -0x450(%rbp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1090 <memset@plt>
lea    -0x48(%rbp),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    -0x34(%rbp),%r13
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1060 <EVP_sha1@plt>
sub    $0x8,%rsp
lea    -0x2c(%rbp),%r10
mov    %eax,%edi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r13,%rcx
mov    %r14d,%r8d
mov    %r15,%r9
push   %r10
call   10a0 <HMAC@plt>
add    $0x10,%rsp
lea    0xd85(%rip),%rdi
mov    %r15,%rsi
call   1080 <printf@plt>
xor    %eax,%eax
call   10e0 <BIO_s_mem@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1070 <BIO_f_base64@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <BIO_push@plt>
mov    -0x2c(%rbp),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <BIO_write@plt>
mov    %rbx,%rdi
call   10f0 <BIO_flush@plt>
mov    %r12,%rdi
lea    -0x450(%rbp),%r14
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
lea    0xd2c(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
mov    %rbx,%rdi
call   10c0 <BIO_free_all@plt>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.key = [8 x i8] c"ABC&XYZ\00"
@__const.main.data = [6 x i8] c"ABCDE\00"
@SHA_DIGEST_LENGTH = global i32 0
@.str = [16 x i8] c"hmac_sha1 = %s\0A\00"
@.str.1 = [17 x i8] c"base64_str = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca i32
%4 = alloca [6 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [1024 x i8]
store i32 0, i32* %1
%12 = bitcast [8 x i8]* %2 to i8*
%13 = bitcast [6 x i8]* %4 to i8*
%14 = load i32, i32* @SHA_DIGEST_LENGTH
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %6
%18 = alloca i8, i64 %16
store i64 %16, i64* %7
store i32* null, i32** %9
store i32* null, i32** %10
%19 = bitcast [1024 x i8]* %11 to i8*
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %3
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %5
%24 = call i32 (...) @EVP_sha1()
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%26 = load i32, i32* %3
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @HMAC(i32 %24, i8* %25, i32 %26, i8* %27, i32 %28, i8* %18, i32* %8)
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18)
%31 = call i32 (...) @BIO_s_mem()
%32 = call i32* @BIO_new(i32 %31)
store i32* %32, i32** %9
%33 = call i32 (...) @BIO_f_base64()
%34 = call i32* @BIO_new(i32 %33)
store i32* %34, i32** %10
%35 = load i32*, i32** %10
%36 = load i32*, i32** %9
%37 = call i32 @BIO_push(i32* %35, i32* %36)
%38 = load i32*, i32** %10
%39 = load i32, i32* %8
%40 = call i32 @BIO_write(i32* %38, i8* %18, i32 %39)
%41 = load i32*, i32** %10
%42 = call i32 @BIO_flush(i32* %41)
%43 = load i32*, i32** %9
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%45 = call i32 @BIO_read(i32* %43, i8* %44, i32 1024)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%47 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = load i32*, i32** %10
%49 = call i32 @BIO_free_all(i32* %48)
store i32 0, i32* %1
%50 = load i8*, i8** %6
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@__const.main.data = [6 x i8] c"ABCDE\00"
@SHA_DIGEST_LENGTH = global i32 0
@.str = [16 x i8] c"hmac_sha1 = %s\0A\00"
@.str.1 = [17 x i8] c"base64_str = %s\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [6 x i8]
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast i64* %1 to i8*
store i64 25430983037895233, i64* %1
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @SHA_DIGEST_LENGTH
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = bitcast i32* %3 to i8*
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i32 @strlen(i8* %5)
%15 = call i32 @strlen(i8* %6)
%16 = call i32 (...) @EVP_sha1()
%17 = call i32 @HMAC(i32 %16, i8* %5, i32 %14, i8* %6, i32 %15, i8* %11, i32* %3)
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %11)
%19 = call i32 (...) @BIO_s_mem()
%20 = call i32* @BIO_new(i32 %19)
%21 = call i32 (...) @BIO_f_base64()
%22 = call i32* @BIO_new(i32 %21)
%23 = call i32 @BIO_push(i32* %22, i32* %20)
%24 = load i32, i32* %3
%25 = call i32 @BIO_write(i32* %22, i8* %11, i32 %24)
%26 = call i32 @BIO_flush(i32* %22)
%27 = call i32 @BIO_read(i32* %20, i8* %13, i32 1024)
%28 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%29 = call i32 @BIO_free_all(i32* %22)
ret i32 0
}