#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*/ tk;
typedef int /*<<< orphan*/ k_opad;
typedef int /*<<< orphan*/ k_ipad;
typedef int /*<<< orphan*/ MD5_CTX;

/* Variables and functions */
int /*<<< orphan*/ MD5_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Update(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void hmac_md5(unsigned char *buffer, int buffer_len, unsigned char *key,
              int key_len, unsigned char *digest) {
  MD5_CTX context;
  unsigned char k_ipad[65];
  unsigned char k_opad[65];
  unsigned char tk[16];
  int i;
  memset(k_ipad, 0, sizeof(k_ipad));
  memset(k_opad, 0, sizeof(k_opad));
  memset(tk, 0, sizeof(tk));
  if (key_len > 64) {
    MD5_CTX tctx;
    MD5_Init(&tctx);
    MD5_Update(&tctx, key, key_len);
    MD5_Final(tk, &tctx);
    key = tk;
    key_len = 16;
  }
  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;
  }
  MD5_Init(&context);
  MD5_Update(&context, k_ipad, 64);
  MD5_Update(&context, buffer, buffer_len);
  MD5_Final(digest, &context);
  MD5_Init(&context);
  MD5_Update(&context, k_opad, 64);
  MD5_Update(&context, digest, 16);
  MD5_Final(digest, &context);
}


x86 assembly (clang, -O0):
<hmac_md5>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%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    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
cmpl   $0x40,-0x1c(%rbp)
jle    11f1 <hmac_md5+0xa1>
lea    -0xd8(%rbp),%rdi
call   1060 <MD5_Init@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0xd8(%rbp),%rdi
call   1070 <MD5_Update@plt>
lea    -0xd0(%rbp),%rdi
lea    -0xd8(%rbp),%rsi
call   1030 <MD5_Final@plt>
lea    -0xd0(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x10,-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,-0xd4(%rbp)
cmpl   $0x40,-0xd4(%rbp)
jge    128e <hmac_md5+0x13e>
movslq -0xd4(%rbp),%rax
movzbl -0x70(%rbp,%rax,1),%ecx
xor    $0x36,%ecx
mov    %cl,-0x70(%rbp,%rax,1)
movslq -0xd4(%rbp),%rax
movzbl -0xc0(%rbp,%rax,1),%ecx
ff
xor    $0x5c,%ecx
mov    %cl,-0xc0(%rbp,%rax,1)
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1241 <hmac_md5+0xf1>
lea    -0x2c(%rbp),%rdi
call   1060 <MD5_Init@plt>
lea    -0x70(%rbp),%rsi
lea    -0x2c(%rbp),%rdi
mov    $0x40,%edx
call   1070 <MD5_Update@plt>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x2c(%rbp),%rdi
call   1070 <MD5_Update@plt>
mov    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1030 <MD5_Final@plt>
lea    -0x2c(%rbp),%rdi
call   1060 <MD5_Init@plt>
lea    -0xc0(%rbp),%rsi
lea    -0x2c(%rbp),%rdi
mov    $0x40,%edx
call   1070 <MD5_Update@plt>
mov    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdi
mov    $0x10,%edx
call   1070 <MD5_Update@plt>
mov    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1030 <MD5_Final@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hmac_md5>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %r8,%r12
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %esi,(%rsp)
mov    %rdi,0x8(%rsp)
lea    0x60(%rsp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1040 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1040 <memset@plt>
lea    0xb0(%rsp),%r14
mov    $0x10,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
cmp    $0x41,%ebp
jl     11dc <hmac_md5+0x8c>
lea    0x4(%rsp),%r13
mov    %r13,%rdi
call   1060 <MD5_Init@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <MD5_Update@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <MD5_Final@plt>
jmp    11e2 <hmac_md5+0x92>
mov    %ebp,%r15d
mov    %rbx,%r14
lea    0x60(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1040 <memset@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1040 <memset@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
movaps 0xdd3(%rip),%xmm0
movaps 0x60(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x60(%rsp)
movaps 0xdcf(%rip),%xmm1
movaps 0x10(%rsp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,0x10(%rsp)
movaps 0x70(%rsp),%xmm2
xorps  %xmm0,%xmm2
movaps %xmm2,0x70(%rsp)
movaps 0x20(%rsp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,0x20(%rsp)
movaps 0x80(%rsp),%xmm2
xorps  %xmm0,%xmm2
movaps %xmm2,0x80(%rsp)
movaps 0x30(%rsp),%xmm2
xorps  %xmm1,%xmm2
movaps %xmm2,0x30(%rsp)
xorps  0x90(%rsp),%xmm0
movaps %xmm0,0x90(%rsp)
xorps  0x40(%rsp),%xmm1
movaps %xmm1,0x40(%rsp)
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <MD5_Init@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x40,%edx
call   1070 <MD5_Update@plt>
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
mov    (%rsp),%edx
call   1070 <MD5_Update@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <MD5_Final@plt>
mov    %rbp,%rdi
call   1060 <MD5_Init@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1070 <MD5_Update@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x10,%edx
call   1070 <MD5_Update@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <MD5_Final@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hmac_md5(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 i32
%12 = alloca [65 x i8]
%13 = alloca [65 x i8]
%14 = alloca [16 x i8]
%15 = alloca i32
%16 = 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
%17 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 65)
%19 = getelementptr inbounds [65 x i8], [65 x i8]* %13, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 65)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 16)
%23 = load i32, i32* %9
%24 = icmp sgt i32 %23, 64
br i1 %24, label %25, label %33
25: ; preds = %5
%26 = call i32 @MD5_Init(i32* %16)
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = call i32 @MD5_Update(i32* %16, i8* %27, i32 %28)
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%31 = call i32 @MD5_Final(i8* %30, i32* %16)
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
store i8* %32, i8** %8
store i32 16, i32* %9
br label %33
33: ; preds = %25, %5
%34 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 65)
%36 = getelementptr inbounds [65 x i8], [65 x i8]* %13, i64 0, i64 0
%37 = call i32 @memset(i8* %36, i32 0, i32 65)
%38 = getelementptr inbounds [65 x i8], [65 x i8]* %12, 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]* %13, 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* %15
br label %46
46: ; preds = %64, %33
%47 = load i32, i32* %15
%48 = icmp slt i32 %47, 64
br i1 %48, label %49, label %67
49: ; preds = %46
%50 = load i32, i32* %15
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [65 x i8], [65 x i8]* %12, 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* %15
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [65 x i8], [65 x i8]* %13, 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* %15
%66 = add nsw i32 %65, 1
store i32 %66, i32* %15
br label %46
67: ; preds = %46
%68 = call i32 @MD5_Init(i32* %11)
%69 = getelementptr inbounds [65 x i8], [65 x i8]* %12, i64 0, i64 0
%70 = call i32 @MD5_Update(i32* %11, i8* %69, i32 64)
%71 = load i8*, i8** %6
%72 = load i32, i32* %7
%73 = call i32 @MD5_Update(i32* %11, i8* %71, i32 %72)
%74 = load i8*, i8** %10
%75 = call i32 @MD5_Final(i8* %74, i32* %11)
%76 = call i32 @MD5_Init(i32* %11)
%77 = getelementptr inbounds [65 x i8], [65 x i8]* %13, i64 0, i64 0
%78 = call i32 @MD5_Update(i32* %11, i8* %77, i32 64)
%79 = load i8*, i8** %10
%80 = call i32 @MD5_Update(i32* %11, i8* %79, i32 16)
%81 = load i8*, i8** %10
%82 = call i32 @MD5_Final(i8* %81, i32* %11)
ret void
}

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