#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*/ sha1(unsigned char *, int, unsigned char *);
void hmac(unsigned char *key, unsigned char keylen, unsigned char *msg,
          unsigned char msglen, unsigned char *out) {
  unsigned char ipad = 0x36;
  unsigned char opad = 0x5C;
  unsigned char padded_key[64];
  unsigned char internal_msg[128];
  unsigned char t;
  unsigned char digest[20];
  for (t = 0; t < 64; t++) {
    if (t < keylen) {
      padded_key[t] = key[t];
    } else {
      padded_key[t] = 0;
    }
    internal_msg[t] = padded_key[t];
    internal_msg[t] ^= ipad;
  }
  for (t = 0; t < msglen; t++) {
    internal_msg[64 + t] = msg[t];
  }
  sha1(internal_msg, 64 + msglen, digest);
  for (t = 0; t < 64; t++) {
    internal_msg[t] = padded_key[t];
    internal_msg[t] ^= opad;
  }
  for (t = 0; t < 20; t++) {
    internal_msg[64 + t] = digest[t];
  }
  sha1(internal_msg, 64 + 20, out);
}


x86 assembly (clang, -O0):
<hmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %cl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %r8,-0x28(%rbp)
movb   $0x36,-0x29(%rbp)
movb   $0x5c,-0x2a(%rbp)
movb   $0x0,-0xf1(%rbp)
movzbl -0xf1(%rbp),%eax
cmp    $0x40,%eax
jge    11d6 <hmac+0xc6>
movzbl -0xf1(%rbp),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jge    1182 <hmac+0x72>
mov    -0x8(%rbp),%rax
movzbl -0xf1(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
movzbl -0xf1(%rbp),%eax
mov    %cl,-0x70(%rbp,%rax,1)
jmp    118e <hmac+0x7e>
movzbl -0xf1(%rbp),%eax
movb   $0x0,-0x70(%rbp,%rax,1)
movzbl -0xf1(%rbp),%eax
mov    -0x70(%rbp,%rax,1),%cl
movzbl -0xf1(%rbp),%eax
mov    %cl,-0xf0(%rbp,%rax,1)
movzbl -0x29(%rbp),%edx
movzbl -0xf1(%rbp),%eax
movzbl -0xf0(%rbp,%rax,1),%ecx
ff
xor    %edx,%ecx
mov    %cl,-0xf0(%rbp,%rax,1)
mov    -0xf1(%rbp),%al
add    $0x1,%al
mov    %al,-0xf1(%rbp)
jmp    1141 <hmac+0x31>
movb   $0x0,-0xf1(%rbp)
movzbl -0xf1(%rbp),%eax
movzbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jge    1224 <hmac+0x114>
mov    -0x18(%rbp),%rax
movzbl -0xf1(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
movzbl -0xf1(%rbp),%eax
add    $0x40,%eax
cltq
mov    %cl,-0xf0(%rbp,%rax,1)
mov    -0xf1(%rbp),%al
add    $0x1,%al
mov    %al,-0xf1(%rbp)
jmp    11dd <hmac+0xcd>
lea    -0xf0(%rbp),%rdi
movzbl -0x19(%rbp),%esi
add    $0x40,%esi
lea    -0x110(%rbp),%rdx
call   1030 <sha1@plt>
movb   $0x0,-0xf1(%rbp)
movzbl -0xf1(%rbp),%eax
cmp    $0x40,%eax
jge    129d <hmac+0x18d>
movzbl -0xf1(%rbp),%eax
mov    -0x70(%rbp,%rax,1),%cl
movzbl -0xf1(%rbp),%eax
mov    %cl,-0xf0(%rbp,%rax,1)
movzbl -0x2a(%rbp),%edx
movzbl -0xf1(%rbp),%eax
movzbl -0xf0(%rbp,%rax,1),%ecx
ff
xor    %edx,%ecx
mov    %cl,-0xf0(%rbp,%rax,1)
mov    -0xf1(%rbp),%al
add    $0x1,%al
mov    %al,-0xf1(%rbp)
jmp    1245 <hmac+0x135>
movb   $0x0,-0xf1(%rbp)
movzbl -0xf1(%rbp),%eax
cmp    $0x14,%eax
jge    12e8 <hmac+0x1d8>
movzbl -0xf1(%rbp),%eax
mov    -0x110(%rbp,%rax,1),%cl
movzbl -0xf1(%rbp),%eax
add    $0x40,%eax
cltq
mov    %cl,-0xf0(%rbp,%rax,1)
mov    -0xf1(%rbp),%al
add    $0x1,%al
mov    %al,-0xf1(%rbp)
jmp    12a4 <hmac+0x194>
lea    -0xf0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x54,%esi
call   1030 <sha1@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hmac>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
mov    %r8,%r14
mov    %esi,%r8d
xor    %esi,%esi
jmp    115c <hmac+0x3c>
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%rdi,%rsi,1),%eax
mov    %al,0x21(%rsp,%rsi,1)
xor    $0x36,%al
mov    %al,0x61(%rsp,%rsi,1)
add    $0x1,%rbx
mov    %rbx,%rsi
cmp    $0x40,%rbx
je     118a <hmac+0x6a>
cmp    %r8,%rsi
jae    1170 <hmac+0x50>
movzbl (%rdi,%rsi,1),%ebx
jmp    1172 <hmac+0x52>
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
mov    %bl,0x20(%rsp,%rsi,1)
xor    $0x36,%bl
mov    %bl,0x60(%rsp,%rsi,1)
lea    0x1(%rsi),%rbx
cmp    %r8,%rbx
jb     1140 <hmac+0x20>
xor    %eax,%eax
jmp    1145 <hmac+0x25>
movzbl %cl,%ebx
test   %cl,%cl
je     11a4 <hmac+0x84>
lea    0xa0(%rsp),%rdi
mov    %rdx,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
add    $0x40,%ebx
lea    0x60(%rsp),%r15
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <sha1@plt>
movaps 0xe40(%rip),%xmm0
movaps 0x20(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x60(%rsp)
movaps 0x30(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x70(%rsp)
movaps 0x40(%rsp),%xmm1
xorps  %xmm0,%xmm1
movaps %xmm1,0x80(%rsp)
xorps  0x50(%rsp),%xmm0
movaps %xmm0,0x90(%rsp)
movaps (%rsp),%xmm0
movaps %xmm0,0xa0(%rsp)
mov    0x10(%rsp),%eax
mov    %eax,0xb0(%rsp)
mov    %r15,%rdi
mov    $0x54,%esi
mov    %r14,%rdx
call   1030 <sha1@plt>
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @hmac(i8* %0, i8 zeroext %1, i8* %2, i8 zeroext %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i8
%12 = alloca i8
%13 = alloca [64 x i8]
%14 = alloca [128 x i8]
%15 = alloca i8
%16 = alloca [20 x i8]
store i8* %0, i8** %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i8 %3, i8* %9
store i8* %4, i8** %10
store i8 54, i8* %11
store i8 92, i8* %12
store i8 0, i8* %15
br label %17
17: ; preds = %57, %5
%18 = load i8, i8* %15
%19 = zext i8 %18 to i32
%20 = icmp slt i32 %19, 64
br i1 %20, label %21, label %60
21: ; preds = %17
%22 = load i8, i8* %15
%23 = zext i8 %22 to i32
%24 = load i8, i8* %7
%25 = zext i8 %24 to i32
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %36
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = load i8, i8* %15
%30 = zext i8 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = load i8, i8* %15
%34 = zext i8 %33 to i64
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 %34
store i8 %32, i8* %35
br label %40
36: ; preds = %21
%37 = load i8, i8* %15
%38 = zext i8 %37 to i64
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %36, %27
%41 = load i8, i8* %15
%42 = zext i8 %41 to i64
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = load i8, i8* %15
%46 = zext i8 %45 to i64
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 %46
store i8 %44, i8* %47
%48 = load i8, i8* %11
%49 = zext i8 %48 to i32
%50 = load i8, i8* %15
%51 = zext i8 %50 to i64
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = xor i32 %54, %49
%56 = trunc i32 %55 to i8
store i8 %56, i8* %52
br label %57
57: ; preds = %40
%58 = load i8, i8* %15
%59 = add i8 %58, 1
store i8 %59, i8* %15
br label %17
60: ; preds = %17
store i8 0, i8* %15
br label %61
61: ; preds = %78, %60
%62 = load i8, i8* %15
%63 = zext i8 %62 to i32
%64 = load i8, i8* %9
%65 = zext i8 %64 to i32
%66 = icmp slt i32 %63, %65
br i1 %66, label %67, label %81
67: ; preds = %61
%68 = load i8*, i8** %8
%69 = load i8, i8* %15
%70 = zext i8 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = load i8, i8* %15
%74 = zext i8 %73 to i32
%75 = add nsw i32 64, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 %76
store i8 %72, i8* %77
br label %78
78: ; preds = %67
%79 = load i8, i8* %15
%80 = add i8 %79, 1
store i8 %80, i8* %15
br label %61
81: ; preds = %61
%82 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%83 = load i8, i8* %9
%84 = zext i8 %83 to i32
%85 = add nsw i32 64, %84
%86 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%87 = call i32 @sha1(i8* %82, i32 %85, i8* %86)
store i8 0, i8* %15
br label %88
88: ; preds = %109, %81
%89 = load i8, i8* %15
%90 = zext i8 %89 to i32
%91 = icmp slt i32 %90, 64
br i1 %91, label %92, label %112
92: ; preds = %88
%93 = load i8, i8* %15
%94 = zext i8 %93 to i64
%95 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = load i8, i8* %15
%98 = zext i8 %97 to i64
%99 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 %98
store i8 %96, i8* %99
%100 = load i8, i8* %12
%101 = zext i8 %100 to i32
%102 = load i8, i8* %15
%103 = zext i8 %102 to i64
%104 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 %103
%105 = load i8, i8* %104
%106 = zext i8 %105 to i32
%107 = xor i32 %106, %101
%108 = trunc i32 %107 to i8
store i8 %108, i8* %104
br label %109
109: ; preds = %92
%110 = load i8, i8* %15
%111 = add i8 %110, 1
store i8 %111, i8* %15
br label %88
112: ; preds = %88
store i8 0, i8* %15
br label %113
113: ; preds = %127, %112
%114 = load i8, i8* %15
%115 = zext i8 %114 to i32
%116 = icmp slt i32 %115, 20
br i1 %116, label %117, label %130
117: ; preds = %113
%118 = load i8, i8* %15
%119 = zext i8 %118 to i64
%120 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 %119
%121 = load i8, i8* %120
%122 = load i8, i8* %15
%123 = zext i8 %122 to i32
%124 = add nsw i32 64, %123
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 %125
store i8 %121, i8* %126
br label %127
127: ; preds = %117
%128 = load i8, i8* %15
%129 = add i8 %128, 1
store i8 %129, i8* %15
br label %113
130: ; preds = %113
%131 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%132 = load i8*, i8** %10
%133 = call i32 @sha1(i8* %131, i32 84, i8* %132)
ret void
}

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