#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 unsigned char uint8_t;
typedef int /*<<< orphan*/ k_pad;

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sha256_vector(int, unsigned char **, size_t *,
                                 unsigned char *);
void hmac_sha256_vector(uint8_t *key, size_t key_len, size_t num_elem,
                        uint8_t *addr[], size_t *len, uint8_t *mac) {
  unsigned char k_pad[64];
  unsigned char tk[32];
  uint8_t *_addr[6];
  size_t _len[6], i;
  if (num_elem > 5) {
    return;
  }
  if (key_len > 64) {
    sha256_vector(1, &key, &key_len, tk);
    key = tk;
    key_len = 32;
  }
  memset(k_pad, 0, sizeof(k_pad));
  memcpy(k_pad, key, key_len);
  for (i = 0; i < 64; i++)
    k_pad[i] ^= 0x36;
  _addr[0] = k_pad;
  _len[0] = 64;
  for (i = 0; i < num_elem; i++) {
    _addr[i + 1] = addr[i];
    _len[i + 1] = len[i];
  }
  sha256_vector(1 + num_elem, _addr, _len, mac);
  for (i = 0; i < 64; i++)
    k_pad[i] ^= 0x6A;
  _addr[0] = k_pad;
  _len[0] = 64;
  _addr[1] = mac;
  _len[1] = 32;
  sha256_vector(2, _addr, _len, mac);
}


x86 assembly (clang, -O0):
<hmac_sha256_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x5,-0x18(%rbp)
jbe    1163 <hmac_sha256_vector+0x33>
jmp    132f <hmac_sha256_vector+0x1ff>
cmpq   $0x40,-0x10(%rbp)
jbe    119a <hmac_sha256_vector+0x6a>
lea    -0x90(%rbp),%rcx
mov    $0x1,%edi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <sha256_vector@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x8(%rbp)
movq   $0x20,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
movq   $0x0,-0xf8(%rbp)
cmpq   $0x40,-0xf8(%rbp)
40
jae    11fe <hmac_sha256_vector+0xce>
mov    -0xf8(%rbp),%rax
movzbl -0x70(%rbp,%rax,1),%ecx
xor    $0x36,%ecx
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
jmp    11c6 <hmac_sha256_vector+0x96>
lea    -0x70(%rbp),%rax
mov    %rax,-0xc0(%rbp)
movq   $0x40,-0xf0(%rbp)
movq   $0x0,-0xf8(%rbp)
mov    -0xf8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1283 <hmac_sha256_vector+0x153>
mov    -0x20(%rbp),%rax
mov    -0xf8(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0xf8(%rbp),%rax
mov    %rcx,-0xb8(%rbp,%rax,8)
ff
mov    -0x28(%rbp),%rax
mov    -0xf8(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0xf8(%rbp),%rax
mov    %rcx,-0xe8(%rbp,%rax,8)
ff
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
jmp    121f <hmac_sha256_vector+0xef>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edi
lea    -0xc0(%rbp),%rsi
lea    -0xf0(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1050 <sha256_vector@plt>
movq   $0x0,-0xf8(%rbp)
cmpq   $0x40,-0xf8(%rbp)
40
jae    12e7 <hmac_sha256_vector+0x1b7>
mov    -0xf8(%rbp),%rax
movzbl -0x70(%rbp,%rax,1),%ecx
xor    $0x6a,%ecx
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
jmp    12af <hmac_sha256_vector+0x17f>
lea    -0x70(%rbp),%rax
mov    %rax,-0xc0(%rbp)
movq   $0x40,-0xf0(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0xb8(%rbp)
movq   $0x20,-0xe8(%rbp)
lea    -0xc0(%rbp),%rsi
lea    -0xf0(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x2,%edi
call   1050 <sha256_vector@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hmac_sha256_vector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rdi,0x8(%rsp)
mov    %rsi,(%rsp)
cmp    $0x5,%rdx
ja     12b2 <hmac_sha256_vector+0x182>
mov    %r9,%r14
mov    %r8,%r12
mov    %rcx,%r13
mov    %rdx,%rbx
cmp    $0x41,%rsi
jb     1190 <hmac_sha256_vector+0x60>
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
lea    0xb0(%rsp),%r15
mov    $0x1,%edi
mov    %r15,%rcx
call   1050 <sha256_vector@plt>
mov    %r15,0x8(%rsp)
movq   $0x20,(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %r15,%rdi
call   1040 <memcpy@plt>
movaps 0xe44(%rip),%xmm0
movaps 0x10(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
movaps 0x20(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x20(%rsp)
movaps 0x30(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x30(%rsp)
xorps  0x40(%rsp),%xmm0
movaps %xmm0,0x40(%rsp)
mov    %r15,0x50(%rsp)
movq   $0x40,0x80(%rsp)
test   %rbx,%rbx
je     122e <hmac_sha256_vector+0xfe>
lea    0x58(%rsp),%rdi
lea    0x0(,%rbx,8),%rbp
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
lea    0x88(%rsp),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
add    $0x1,%ebx
lea    0x50(%rsp),%r12
lea    0x80(%rsp),%r13
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1050 <sha256_vector@plt>
movaps 0xdbb(%rip),%xmm0
movaps 0x10(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
movaps 0x20(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x20(%rsp)
movaps 0x30(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x30(%rsp)
xorps  0x40(%rsp),%xmm0
movaps %xmm0,0x40(%rsp)
mov    %r15,0x50(%rsp)
mov    %r14,0x58(%rsp)
movaps 0xd89(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
mov    $0x2,%edi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1050 <sha256_vector@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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