#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*/ SHA256(unsigned char const *, int, void *);
int SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
void hmac_sha256(const unsigned char *text, int text_len,
                 const unsigned char *key, int key_len, void *digest) {
  unsigned char k_ipad[65];
  unsigned char k_opad[65];
  unsigned char tk[SHA256_DIGEST_LENGTH];
  unsigned char tk2[SHA256_DIGEST_LENGTH];
  unsigned char bufferIn[1024];
  unsigned char bufferOut[1024];
  int i;
  if (key_len > 64) {
    SHA256(key, key_len, tk);
    key = tk;
    key_len = SHA256_DIGEST_LENGTH;
  }
  memset(k_ipad, 0, sizeof k_ipad);
  memset(k_opad, 0, sizeof k_opad);
  memcpy(k_ipad, key, key_len);
  memcpy(k_opad, key, key_len);
  for (i = 0; i < 64; i++) {
    k_ipad[i] ^= 0x36;
    k_opad[i] ^= 0x5c;
  }
  memset(bufferIn, 0x00, 1024);
  memcpy(bufferIn, k_ipad, 64);
  memcpy(bufferIn + 64, text, text_len);
  SHA256(bufferIn, 64 + text_len, tk2);
  memset(bufferOut, 0x00, 1024);
  memcpy(bufferOut, k_opad, 64);
  memcpy(bufferOut + 64, tk2, SHA256_DIGEST_LENGTH);
  SHA256(bufferOut, 64 + SHA256_DIGEST_LENGTH, digest);
}


x86 assembly (clang, -O0):
<hmac_sha256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x900,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0xc8(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x8f8(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0xd0(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x8f0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xd8(%rbp)
cmpl   $0x40,-0x1c(%rbp)
jle    11da <hmac_sha256+0xaa>
mov    -0x8f8(%rbp),%rdx
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <SHA256@plt>
mov    -0x8f8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1040 <memset@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1040 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x8e4(%rbp)
cmpl   $0x40,-0x8e4(%rbp)
jge    1277 <hmac_sha256+0x147>
movslq -0x8e4(%rbp),%rax
movzbl -0x70(%rbp,%rax,1),%ecx
xor    $0x36,%ecx
mov    %cl,-0x70(%rbp,%rax,1)
movslq -0x8e4(%rbp),%rax
movzbl -0xc0(%rbp,%rax,1),%ecx
ff
xor    $0x5c,%ecx
mov    %cl,-0xc0(%rbp,%rax,1)
mov    -0x8e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8e4(%rbp)
jmp    122a <hmac_sha256+0xfa>
lea    -0x4e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x4e0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
lea    -0x4e0(%rbp),%rdi
add    $0x40,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8f0(%rbp),%rdx
lea    -0x4e0(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x40,%esi
call   1030 <SHA256@plt>
lea    -0x8e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x8e0(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x8f0(%rbp),%rsi
lea    -0x8e0(%rbp),%rdi
add    $0x40,%rdi
mov    0x2ccd(%rip),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
lea    -0x8e0(%rbp),%rdi
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
add    $0x40,%esi
mov    -0x28(%rbp),%rdx
call   1030 <SHA256@plt>
mov    -0xc8(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hmac_sha256>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8b8,%rsp
mov    %r8,-0x48(%rbp)
mov    %ecx,%r14d
mov    %esi,-0x2c(%rbp)
mov    %rdi,-0x38(%rbp)
mov    %rsp,-0x40(%rbp)
mov    0x2e83(%rip),%rbx
mov    (%rbx),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    (%rbx),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x41,%ecx
jl     119b <hmac_sha256+0x6b>
mov    %rdx,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
call   1030 <SHA256@plt>
mov    (%rbx),%r14d
jmp    119e <hmac_sha256+0x6e>
mov    %rdx,%r13
lea    -0xe0(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1040 <memset@plt>
lea    -0x90(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1050 <memcpy@plt>
movaps 0xe13(%rip),%xmm0
movaps -0xe0(%rbp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,-0xe0(%rbp)
movaps 0xe0b(%rip),%xmm1
movaps -0x90(%rbp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,-0x90(%rbp)
movaps -0xd0(%rbp),%xmm2
xorps  %xmm0,%xmm2
movaps %xmm2,-0xd0(%rbp)
movaps -0x80(%rbp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,-0x80(%rbp)
movaps -0xc0(%rbp),%xmm2
xorps  %xmm0,%xmm2
movaps %xmm2,-0xc0(%rbp)
movaps -0x70(%rbp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,-0x70(%rbp)
xorps  -0xb0(%rbp),%xmm0
movaps %xmm0,-0xb0(%rbp)
xorps  -0x60(%rbp),%xmm1
movaps %xmm1,-0x60(%rbp)
lea    -0x8e0(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
lea    -0x8a0(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%ebx
mov    %ebx,%edx
call   1050 <memcpy@plt>
add    $0x40,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
call   1030 <SHA256@plt>
lea    -0x4e0(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
lea    -0x90(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
lea    -0x4a0(%rbp),%rdi
mov    0x2cf9(%rip),%rbx
mov    (%rbx),%edx
mov    %r12,%rsi
call   1050 <memcpy@plt>
mov    (%rbx),%esi
add    $0x40,%esi
mov    %r14,%rdi
mov    -0x48(%rbp),%rdx
call   1030 <SHA256@plt>
mov    -0x40(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
define void @hmac_sha256(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [65 x i8]
%12 = alloca [65 x i8]
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
%16 = alloca [1024 x i8]
%17 = alloca [1024 x i8]
%18 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%19 = load i32, i32* @SHA256_DIGEST_LENGTH
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %13
%22 = alloca i8, i64 %20
store i64 %20, i64* %14
%23 = load i32, i32* @SHA256_DIGEST_LENGTH
%24 = zext i32 %23 to i64
%25 = alloca i8, i64 %24
store i64 %24, i64* %15
%26 = load i32, i32* %9
%27 = icmp sgt i32 %26, 64
br i1 %27, label %28, label %33
28: ; preds = %5
%29 = load i8*, i8** %8
%30 = load i32, i32* %9
%31 = call i32 @SHA256(i8* %29, i32 %30, i8* %22)
store i8* %22, i8** %8
%32 = load i32, i32* @SHA256_DIGEST_LENGTH
store i32 %32, i32* %9
br label %33
33: ; preds = %28, %5
%34 = getelementptr inbounds [65 x i8], [65 x i8]* %11, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 65)
%36 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%37 = call i32 @memset(i8* %36, i32 0, i32 65)
%38 = getelementptr inbounds [65 x i8], [65 x i8]* %11, i64 0, i64 0
%39 = load i8*, i8** %8
%40 = load i32, i32* %9
%41 = call i32 @memcpy(i8* %38, i8* %39, i32 %40)
%42 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%43 = load i8*, i8** %8
%44 = load i32, i32* %9
%45 = call i32 @memcpy(i8* %42, i8* %43, i32 %44)
store i32 0, i32* %18
br label %46
46: ; preds = %64, %33
%47 = load i32, i32* %18
%48 = icmp slt i32 %47, 64
br i1 %48, label %49, label %67
49: ; preds = %46
%50 = load i32, i32* %18
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [65 x i8], [65 x i8]* %11, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = xor i32 %54, 54
%56 = trunc i32 %55 to i8
store i8 %56, i8* %52
%57 = load i32, i32* %18
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = xor i32 %61, 92
%63 = trunc i32 %62 to i8
store i8 %63, i8* %59
br label %64
64: ; preds = %49
%65 = load i32, i32* %18
%66 = add nsw i32 %65, 1
store i32 %66, i32* %18
br label %46
67: ; preds = %46
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%69 = call i32 @memset(i8* %68, i32 0, i32 1024)
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%71 = getelementptr inbounds [65 x i8], [65 x i8]* %11, i64 0, i64 0
%72 = call i32 @memcpy(i8* %70, i8* %71, i32 64)
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%74 = getelementptr inbounds i8, i8* %73, i64 64
%75 = load i8*, i8** %6
%76 = load i32, i32* %7
%77 = call i32 @memcpy(i8* %74, i8* %75, i32 %76)
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%79 = load i32, i32* %7
%80 = add nsw i32 64, %79
%81 = call i32 @SHA256(i8* %78, i32 %80, i8* %25)
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%83 = call i32 @memset(i8* %82, i32 0, i32 1024)
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%85 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%86 = call i32 @memcpy(i8* %84, i8* %85, i32 64)
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%88 = getelementptr inbounds i8, i8* %87, i64 64
%89 = load i32, i32* @SHA256_DIGEST_LENGTH
%90 = call i32 @memcpy(i8* %88, i8* %25, i32 %89)
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%92 = load i32, i32* @SHA256_DIGEST_LENGTH
%93 = add nsw i32 64, %92
%94 = load i8*, i8** %10
%95 = call i32 @SHA256(i8* %91, i32 %93, i8* %94)
%96 = load i8*, i8** %13
ret void
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
define void @hmac_sha256(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca [65 x i8]
%7 = alloca [65 x i8]
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = getelementptr inbounds [65 x i8], [65 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @SHA256_DIGEST_LENGTH
%13 = zext i32 %12 to i64
%14 = tail call i8* @llvm.stacksave()
%15 = alloca i8, i64 %13
%16 = load i32, i32* @SHA256_DIGEST_LENGTH
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%21 = icmp sgt i32 %3, 64
br i1 %21, label %22, label %25
22: ; preds = %5
%23 = call i32 @SHA256(i8* %2, i32 %3, i8* %15)
%24 = load i32, i32* @SHA256_DIGEST_LENGTH
br label %25
25: ; preds = %22, %5
%26 = phi i32 [ %24, %22 ], [ %3, %5 ]
%27 = phi i8* [ %15, %22 ], [ %2, %5 ]
%28 = call i32 @memset(i8* %10, i32 0, i32 65)
%29 = call i32 @memset(i8* %11, i32 0, i32 65)
%30 = call i32 @memcpy(i8* %10, i8* %27, i32 %26)
%31 = call i32 @memcpy(i8* %11, i8* %27, i32 %26)
%32 = bitcast [65 x i8]* %6 to <16 x i8>*
%33 = load <16 x i8>, <16 x i8>* %32
%34 = xor <16 x i8> %33, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
%35 = bitcast [65 x i8]* %6 to <16 x i8>*
store <16 x i8> %34, <16 x i8>* %35
%36 = bitcast [65 x i8]* %7 to <16 x i8>*
%37 = load <16 x i8>, <16 x i8>* %36
%38 = xor <16 x i8> %37, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
%39 = bitcast [65 x i8]* %7 to <16 x i8>*
store <16 x i8> %38, <16 x i8>* %39
%40 = getelementptr inbounds [65 x i8], [65 x i8]* %6, i64 0, i64 16
%41 = bitcast i8* %40 to <16 x i8>*
%42 = load <16 x i8>, <16 x i8>* %41
%43 = xor <16 x i8> %42, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
%44 = bitcast i8* %40 to <16 x i8>*
store <16 x i8> %43, <16 x i8>* %44
%45 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 16
%46 = bitcast i8* %45 to <16 x i8>*
%47 = load <16 x i8>, <16 x i8>* %46
%48 = xor <16 x i8> %47, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
%49 = bitcast i8* %45 to <16 x i8>*
store <16 x i8> %48, <16 x i8>* %49
%50 = getelementptr inbounds [65 x i8], [65 x i8]* %6, i64 0, i64 32
%51 = bitcast i8* %50 to <16 x i8>*
%52 = load <16 x i8>, <16 x i8>* %51
%53 = xor <16 x i8> %52, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
%54 = bitcast i8* %50 to <16 x i8>*
store <16 x i8> %53, <16 x i8>* %54
%55 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 32
%56 = bitcast i8* %55 to <16 x i8>*
%57 = load <16 x i8>, <16 x i8>* %56
%58 = xor <16 x i8> %57, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
%59 = bitcast i8* %55 to <16 x i8>*
store <16 x i8> %58, <16 x i8>* %59
%60 = getelementptr inbounds [65 x i8], [65 x i8]* %6, i64 0, i64 48
%61 = bitcast i8* %60 to <16 x i8>*
%62 = load <16 x i8>, <16 x i8>* %61
%63 = xor <16 x i8> %62, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
%64 = bitcast i8* %60 to <16 x i8>*
store <16 x i8> %63, <16 x i8>* %64
%65 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 48
%66 = bitcast i8* %65 to <16 x i8>*
%67 = load <16 x i8>, <16 x i8>* %66
%68 = xor <16 x i8> %67, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
%69 = bitcast i8* %65 to <16 x i8>*
store <16 x i8> %68, <16 x i8>* %69
%70 = call i32 @memset(i8* %19, i32 0, i32 1024)
%71 = call i32 @memcpy(i8* %19, i8* %10, i32 64)
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 64
%73 = call i32 @memcpy(i8* %72, i8* %0, i32 %1)
%74 = add nsw i32 %1, 64
%75 = call i32 @SHA256(i8* %19, i32 %74, i8* %18)
%76 = call i32 @memset(i8* %20, i32 0, i32 1024)
%77 = call i32 @memcpy(i8* %20, i8* %11, i32 64)
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 64
%79 = load i32, i32* @SHA256_DIGEST_LENGTH
%80 = call i32 @memcpy(i8* %78, i8* %18, i32 %79)
%81 = load i32, i32* @SHA256_DIGEST_LENGTH
%82 = add nsw i32 %81, 64
%83 = call i32 @SHA256(i8* %20, i32 %82, i8* %4)
ret void
}