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

/* Variables and functions */
int /*<<< orphan*/ librock_sha256Init(void *);
int /*<<< orphan*/ librock_sha256StoreFinal(unsigned char *, void *);
int /*<<< orphan*/ librock_sha256Update(void *, unsigned char const *, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ memset(char *, char, int);
void librock_hmacSha256(unsigned char *digest, const char *key, int cbKey,
                        const char *toSign, int cbToSign) {
  char keyBuffer[64];
  char padBuffer[64];
  char context[13 * 8 + 64];
  unsigned int i = 0;
  void *pContext = &context[0];
  librock_sha256Init(pContext);
  memset(keyBuffer, '\0', sizeof(keyBuffer));
  if (cbKey > 64) {
    librock_sha256Update(pContext, (unsigned char *)key, cbKey);
    librock_sha256StoreFinal((unsigned char *)keyBuffer, pContext);
  } else {
    memcpy(keyBuffer, key, cbKey);
  }
  librock_sha256Init(pContext);
  for (i = 0; i < sizeof(padBuffer); i++) {
    padBuffer[i] = keyBuffer[i] ^ 0x36;
  }
  librock_sha256Update(pContext, (const unsigned char *)padBuffer,
                       sizeof(padBuffer));
  librock_sha256Update(pContext, (const unsigned char *)toSign, cbToSign);
  librock_sha256StoreFinal((unsigned char *)digest, pContext);
  for (i = 0; i < sizeof(keyBuffer); i++) {
    keyBuffer[i] = keyBuffer[i] ^ 0x5c;
  }
  librock_sha256Init(pContext);
  librock_sha256Update(pContext, (const unsigned char *)keyBuffer,
                       sizeof(keyBuffer));
  librock_sha256Update(pContext, (const unsigned char *)digest, 32);
  librock_sha256StoreFinal((unsigned char *)digest, pContext);
}


x86 assembly (clang, -O0):
<librock_hmacSha256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x164(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    -0x170(%rbp),%rdi
call   1050 <librock_sha256Init@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
cmpl   $0x40,-0x14(%rbp)
jle    11d4 <librock_hmacSha256+0x84>
mov    -0x170(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <librock_sha256Update@plt>
lea    -0x70(%rbp),%rdi
mov    -0x170(%rbp),%rsi
call   1070 <librock_sha256StoreFinal@plt>
jmp    11e4 <librock_hmacSha256+0x94>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x170(%rbp),%rdi
call   1050 <librock_sha256Init@plt>
movl   $0x0,-0x164(%rbp)
mov    -0x164(%rbp),%eax
cmp    $0x40,%rax
jae    123b <librock_hmacSha256+0xeb>
mov    -0x164(%rbp),%eax
movsbl -0x70(%rbp,%rax,1),%eax
xor    $0x36,%eax
mov    %al,%cl
mov    -0x164(%rbp),%eax
mov    %cl,-0xb0(%rbp,%rax,1)
mov    -0x164(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x164(%rbp)
jmp    11fa <librock_hmacSha256+0xaa>
mov    -0x170(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    $0x40,%edx
call   1040 <librock_sha256Update@plt>
mov    -0x170(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <librock_sha256Update@plt>
mov    -0x8(%rbp),%rdi
mov    -0x170(%rbp),%rsi
call   1070 <librock_sha256StoreFinal@plt>
movl   $0x0,-0x164(%rbp)
mov    -0x164(%rbp),%eax
cmp    $0x40,%rax
jae    12be <librock_hmacSha256+0x16e>
mov    -0x164(%rbp),%eax
movsbl -0x70(%rbp,%rax,1),%eax
xor    $0x5c,%eax
mov    %al,%cl
mov    -0x164(%rbp),%eax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x164(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x164(%rbp)
jmp    1280 <librock_hmacSha256+0x130>
mov    -0x170(%rbp),%rdi
call   1050 <librock_sha256Init@plt>
mov    -0x170(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x40,%edx
call   1040 <librock_sha256Update@plt>
mov    -0x170(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x20,%edx
call   1040 <librock_sha256Update@plt>
mov    -0x8(%rbp),%rdi
mov    -0x170(%rbp),%rsi
call   1070 <librock_sha256StoreFinal@plt>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<librock_hmacSha256>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0x80(%rsp),%rdi
call   1050 <librock_sha256Init@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
cmp    $0x41,%ebp
jl     11b2 <librock_hmacSha256+0x62>
lea    0x80(%rsp),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <librock_sha256Update@plt>
mov    %rsp,%rdi
mov    %r13,%rsi
call   1070 <librock_sha256StoreFinal@plt>
jmp    11bf <librock_hmacSha256+0x6f>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <librock_sha256Init@plt>
movaps 0xe2a(%rip),%xmm0
movaps (%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x40(%rsp)
movaps 0x10(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x50(%rsp)
movaps 0x20(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x60(%rsp)
xorps  0x30(%rsp),%xmm0
movaps %xmm0,0x70(%rsp)
lea    0x40(%rsp),%rsi
mov    %rbp,%rdi
mov    $0x40,%edx
call   1040 <librock_sha256Update@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <librock_sha256Update@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1070 <librock_sha256StoreFinal@plt>
movaps 0xdd8(%rip),%xmm0
movaps (%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,(%rsp)
movaps 0x10(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
movaps 0x20(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x20(%rsp)
xorps  0x30(%rsp),%xmm0
movaps %xmm0,0x30(%rsp)
mov    %rbp,%rdi
call   1050 <librock_sha256Init@plt>
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0x40,%edx
call   1040 <librock_sha256Update@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x20,%edx
call   1040 <librock_sha256Update@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1070 <librock_sha256StoreFinal@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @librock_hmacSha256(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca [64 x i8]
%7 = alloca [64 x i8]
%8 = alloca [168 x i8]
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [168 x i8], [168 x i8]* %8, i64 0, i64 0
%12 = call i32 @librock_sha256Init(i8* %11)
%13 = call i32 @memset(i8* %9, i8 signext 0, i32 64)
%14 = icmp sgt i32 %2, 64
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = call i32 @librock_sha256Update(i8* %11, i8* %1, i32 %2)
%17 = call i32 @librock_sha256StoreFinal(i8* %9, i8* %11)
br label %20
18: ; preds = %5
%19 = call i32 @memcpy(i8* %9, i8* %1, i32 %2)
br label %20
20: ; preds = %18, %15
%21 = call i32 @librock_sha256Init(i8* %11)
%22 = bitcast [64 x i8]* %6 to <16 x i8>*
%23 = load <16 x i8>, <16 x i8>* %22
%24 = xor <16 x i8> %23, <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>
%25 = bitcast [64 x i8]* %7 to <16 x i8>*
store <16 x i8> %24, <16 x i8>* %25
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 16
%27 = bitcast i8* %26 to <16 x i8>*
%28 = load <16 x i8>, <16 x i8>* %27
%29 = xor <16 x i8> %28, <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>
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 16
%31 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> %29, <16 x i8>* %31
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 32
%33 = bitcast i8* %32 to <16 x i8>*
%34 = load <16 x i8>, <16 x i8>* %33
%35 = xor <16 x i8> %34, <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>
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 32
%37 = bitcast i8* %36 to <16 x i8>*
store <16 x i8> %35, <16 x i8>* %37
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 48
%39 = bitcast i8* %38 to <16 x i8>*
%40 = load <16 x i8>, <16 x i8>* %39
%41 = xor <16 x i8> %40, <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>
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 48
%43 = bitcast i8* %42 to <16 x i8>*
store <16 x i8> %41, <16 x i8>* %43
%44 = call i32 @librock_sha256Update(i8* %11, i8* %10, i32 64)
%45 = call i32 @librock_sha256Update(i8* %11, i8* %3, i32 %4)
%46 = call i32 @librock_sha256StoreFinal(i8* %0, i8* %11)
%47 = bitcast [64 x i8]* %6 to <16 x i8>*
%48 = load <16 x i8>, <16 x i8>* %47
%49 = xor <16 x i8> %48, <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>
%50 = bitcast [64 x i8]* %6 to <16 x i8>*
store <16 x i8> %49, <16 x i8>* %50
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 16
%52 = bitcast i8* %51 to <16 x i8>*
%53 = load <16 x i8>, <16 x i8>* %52
%54 = xor <16 x i8> %53, <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>
%55 = bitcast i8* %51 to <16 x i8>*
store <16 x i8> %54, <16 x i8>* %55
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 32
%57 = bitcast i8* %56 to <16 x i8>*
%58 = load <16 x i8>, <16 x i8>* %57
%59 = xor <16 x i8> %58, <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>
%60 = bitcast i8* %56 to <16 x i8>*
store <16 x i8> %59, <16 x i8>* %60
%61 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 48
%62 = bitcast i8* %61 to <16 x i8>*
%63 = load <16 x i8>, <16 x i8>* %62
%64 = xor <16 x i8> %63, <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>
%65 = bitcast i8* %61 to <16 x i8>*
store <16 x i8> %64, <16 x i8>* %65
%66 = call i32 @librock_sha256Init(i8* %11)
%67 = call i32 @librock_sha256Update(i8* %11, i8* %9, i32 64)
%68 = call i32 @librock_sha256Update(i8* %11, i8* %0, i32 32)
%69 = call i32 @librock_sha256StoreFinal(i8* %0, i8* %11)
ret void
}