#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*/ md5sum(unsigned char *, void const *, unsigned long);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned long);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void _hmac(unsigned char *buff, const void *data, unsigned long len,
           const void *key, unsigned long klen,
           void (*func)(unsigned char *, const void *, unsigned long,
                        const void *, unsigned long),
           short alglen) {
  unsigned char okey[64], ikey[64];
  int bcnt;
  memset(ikey, 0, 64);
  memset(okey, 0, 64);
  if (klen < 64) {
    memcpy(ikey, key, klen);
    memcpy(okey, key, klen);
  } else {
    md5sum(okey, key, klen);
    memcpy(ikey, okey, klen);
  }
  for (bcnt = 0; bcnt < 64; bcnt++) {
    ikey[bcnt] ^= 0x36;
    okey[bcnt] ^= 0x5c;
  };
  func(buff, ikey, 64, data, len);
  func(buff, okey, 64, buff, alglen);
}


x86 assembly (clang, -O0):
<_hmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    0x10(%rbp),%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
cmpq   $0x40,-0x28(%rbp)
jae    11af <_hmac+0x7f>
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
jmp    11d4 <_hmac+0xa4>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <md5sum@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
movl   $0x0,-0xb4(%rbp)
cmpl   $0x40,-0xb4(%rbp)
jge    122b <_hmac+0xfb>
movslq -0xb4(%rbp),%rax
movzbl -0xb0(%rbp,%rax,1),%ecx
ff
xor    $0x36,%ecx
mov    %cl,-0xb0(%rbp,%rax,1)
movslq -0xb4(%rbp),%rax
movzbl -0x70(%rbp,%rax,1),%ecx
xor    $0x5c,%ecx
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11de <_hmac+0xae>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x40,%edx
call   *%rax
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x8(%rbp),%rcx
movswq 0x10(%rbp),%r8
mov    $0x40,%edx
call   *%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_hmac>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r9,%r14
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,0x8(%rsp)
mov    %rdi,%r13
movzwl 0xd0(%rsp),%r12d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
lea    0x50(%rsp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
cmp    $0x3f,%rbx
ja     11a0 <_hmac+0x70>
lea    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
lea    0x50(%rsp),%rdi
mov    %rbp,%rsi
jmp    11c4 <_hmac+0x94>
lea    0x50(%rsp),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <md5sum@plt>
lea    0x10(%rsp),%rdi
mov    %r12,%rsi
movzwl 0xd0(%rsp),%r12d
mov    %rbx,%rdx
call   1040 <memcpy@plt>
movaps 0xe2d(%rip),%xmm0
movaps 0x10(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
movaps 0xe29(%rip),%xmm1
movaps 0x50(%rsp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,0x50(%rsp)
movaps 0x20(%rsp),%xmm2
xorps  %xmm0,%xmm2
movaps %xmm2,0x20(%rsp)
movaps 0x60(%rsp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,0x60(%rsp)
movaps 0x30(%rsp),%xmm2
xorps  %xmm0,%xmm2
movaps %xmm2,0x30(%rsp)
movaps 0x70(%rsp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,0x70(%rsp)
xorps  0x40(%rsp),%xmm0
movaps %xmm0,0x40(%rsp)
xorps  0x80(%rsp),%xmm1
movaps %xmm1,0x80(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x40,%edx
mov    %r13,%rdi
mov    0x8(%rsp),%rcx
mov    %r15,%r8
call   *%r14
movswq %r12w,%r8
lea    0x50(%rsp),%rsi
mov    $0x40,%edx
mov    %r13,%rdi
mov    %r13,%rcx
call   *%r14
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_hmac(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4, void (i8*, i8*, i64, i8*, i64)* %5, i16 signext %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca void (i8*, i8*, i64, i8*, i64)*
%14 = alloca i16
%15 = alloca [64 x i8]
%16 = alloca [64 x i8]
%17 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i8* %3, i8** %11
store i64 %4, i64* %12
store void (i8*, i8*, i64, i8*, i64)* %5, void (i8*, i8*, i64, i8*, i64)** %13
store i16 %6, i16* %14
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %16, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 64)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 64)
%22 = load i64, i64* %12
%23 = icmp ult i64 %22, 64
br i1 %23, label %24, label %33
24: ; preds = %7
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %16, i64 0, i64 0
%26 = load i8*, i8** %11
%27 = load i64, i64* %12
%28 = call i32 @memcpy(i8* %25, i8* %26, i64 %27)
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%30 = load i8*, i8** %11
%31 = load i64, i64* %12
%32 = call i32 @memcpy(i8* %29, i8* %30, i64 %31)
br label %42
33: ; preds = %7
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%35 = load i8*, i8** %11
%36 = load i64, i64* %12
%37 = call i32 @md5sum(i8* %34, i8* %35, i64 %36)
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %16, i64 0, i64 0
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%40 = load i64, i64* %12
%41 = call i32 @memcpy(i8* %38, i8* %39, i64 %40)
br label %42
42: ; preds = %33, %24
store i32 0, i32* %17
br label %43
43: ; preds = %61, %42
%44 = load i32, i32* %17
%45 = icmp slt i32 %44, 64
br i1 %45, label %46, label %64
46: ; preds = %43
%47 = load i32, i32* %17
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %16, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = xor i32 %51, 54
%53 = trunc i32 %52 to i8
store i8 %53, i8* %49
%54 = load i32, i32* %17
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = xor i32 %58, 92
%60 = trunc i32 %59 to i8
store i8 %60, i8* %56
br label %61
61: ; preds = %46
%62 = load i32, i32* %17
%63 = add nsw i32 %62, 1
store i32 %63, i32* %17
br label %43
64: ; preds = %43
%65 = load void (i8*, i8*, i64, i8*, i64)*, void (i8*, i8*, i64, i8*, i64)** %13
%66 = load i8*, i8** %8
%67 = getelementptr inbounds [64 x i8], [64 x i8]* %16, i64 0, i64 0
%68 = load i8*, i8** %9
%69 = load i64, i64* %10
%70 = load void (i8*, i8*, i64, i8*, i64)*, void (i8*, i8*, i64, i8*, i64)** %13
%71 = load i8*, i8** %8
%72 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%73 = load i8*, i8** %8
%74 = load i16, i16* %14
%75 = sext i16 %74 to i64
ret void
}

LLVM IR (-O2):
define void @_hmac(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4, void (i8*, i8*, i64, i8*, i64)* nocapture %5, i16 signext %6) {
%8 = alloca [64 x i8]
%9 = alloca [64 x i8]
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 64)
%13 = call i32 @memset(i8* %10, i32 0, i32 64)
%14 = icmp ult i64 %4, 64
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = call i32 @memcpy(i8* %11, i8* %3, i64 %4)
%17 = call i32 @memcpy(i8* %10, i8* %3, i64 %4)
br label %21
18: ; preds = %7
%19 = call i32 @md5sum(i8* %10, i8* %3, i64 %4)
%20 = call i32 @memcpy(i8* %11, i8* %10, i64 %4)
br label %21
21: ; preds = %15, %18
%22 = bitcast [64 x i8]* %9 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]* %9 to <16 x i8>*
store <16 x i8> %24, <16 x i8>* %25
%26 = bitcast [64 x i8]* %8 to <16 x i8>*
%27 = load <16 x i8>, <16 x i8>* %26
%28 = xor <16 x i8> %27, <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>
%29 = bitcast [64 x i8]* %8 to <16 x i8>*
store <16 x i8> %28, <16 x i8>* %29
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 16
%31 = bitcast i8* %30 to <16 x i8>*
%32 = load <16 x i8>, <16 x i8>* %31
%33 = xor <16 x i8> %32, <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>
%34 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> %33, <16 x i8>* %34
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 16
%36 = bitcast i8* %35 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 i8* %35 to <16 x i8>*
store <16 x i8> %38, <16 x i8>* %39
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 32
%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 [64 x i8], [64 x i8]* %8, i64 0, i64 32
%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 [64 x i8], [64 x i8]* %9, i64 0, i64 48
%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 [64 x i8], [64 x i8]* %8, i64 0, i64 48
%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 = sext i16 %6 to i64
ret void
}