#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EVP_sha256();
unsigned char *HMAC(int /*<<< orphan*/, void *, scalar_t__, unsigned char *,
                    scalar_t__, unsigned char *, int /*<<< orphan*/ *);
unsigned char *calloc(int, int);
scalar_t__ strlen(char *);
unsigned char *hmac_sha256(void *key, ssize_t klen, char *data) {
  unsigned char *r = calloc(32, sizeof(unsigned char));
  return HMAC(EVP_sha256(), key, klen < 0 ? strlen(key) : klen,
              (unsigned char *)data, strlen(data), r, NULL);
}


x86 assembly (clang, -O0):
<hmac_sha256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x20,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <EVP_sha256@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1196 <hmac_sha256+0x56>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
jmp    119e <hmac_sha256+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    %rax,%r8
mov    -0x20(%rbp),%r9
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1050 <HMAC@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hmac_sha256>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x20,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1060 <EVP_sha256@plt>
mov    %eax,%ebp
test   %rbx,%rbx
jns    1180 <hmac_sha256+0x40>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
movq   $0x0,(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %rax,%r8
mov    %r12,%r9
call   1050 <HMAC@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @hmac_sha256(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%8 = call i8* @calloc(i32 32, i32 1)
store i8* %8, i8** %7
%9 = call i32 (...) @EVP_sha256()
%10 = load i8*, i8** %4
%11 = load i64, i64* %5
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
br label %18
16: ; preds = %3
%17 = load i64, i64* %5
br label %18
18: ; preds = %16, %13
%19 = phi i64 [ %15, %13 ], [ %17, %16 ]
%20 = load i8*, i8** %6
%21 = load i8*, i8** %6
%22 = call i64 @strlen(i8* %21)
%23 = load i8*, i8** %7
%24 = call i8* @HMAC(i32 %9, i8* %10, i64 %19, i8* %20, i64 %22, i8* %23, i32* null)
ret i8* %24
}

LLVM IR (-O2):
define i8* @hmac_sha256(i8* %0, i64 %1, i8* %2) {
%4 = tail call dereferenceable_or_null(32) i8* @calloc(i32 32, i32 1)
%5 = tail call i32 (...) @EVP_sha256()
%6 = icmp slt i64 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %9
9: ; preds = %3, %7
%10 = phi i64 [ %8, %7 ], [ %1, %3 ]
%11 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%12 = tail call i8* @HMAC(i32 %5, i8* %0, i64 %10, i8* %2, i64 %11, i8* %4, i32* null)
ret i8* %12
}