#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;

/* Variables and functions */
int /*<<< orphan*/ hmac_sha1_vector(unsigned char const *, size_t, int,
                                    unsigned char const **, size_t *,
                                    unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
size_t strlen(char const *);
void sha1_t_prf(const uint8_t *key, size_t key_len, const char *label,
                const uint8_t *seed, size_t seed_len, uint8_t *buf,
                size_t buf_len) {
  unsigned char counter = 0;
  size_t pos, plen;
  uint8_t hash[20];
  size_t label_len = strlen(label);
  uint8_t output_len[2];
  const unsigned char *addr[5];
  size_t len[5];
  addr[0] = hash;
  len[0] = 0;
  addr[1] = (unsigned char *)label;
  len[1] = label_len + 1;
  addr[2] = seed;
  len[2] = seed_len;
  addr[3] = output_len;
  len[3] = 2;
  addr[4] = &counter;
  len[4] = 1;
  output_len[0] = (buf_len >> 8) & 0xff;
  output_len[1] = buf_len & 0xff;
  pos = 0;
  while (pos < buf_len) {
    counter++;
    plen = buf_len - pos;
    hmac_sha1_vector(key, key_len, 5, addr, len, hash);
    if (plen >= 20) {
      memcpy(&buf[pos], hash, 20);
      pos += 20;
    } else {
      memcpy(&buf[pos], hash, plen);
      break;
    }
    len[0] = 20;
  }
}


x86 assembly (clang, -O0):
<sha1_t_prf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xa0(%rbp)
movq   $0x0,-0xd0(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc8(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    -0x6a(%rbp),%rax
mov    %rax,-0x88(%rbp)
movq   $0x2,-0xb8(%rbp)
lea    -0x31(%rbp),%rax
mov    %rax,-0x80(%rbp)
movq   $0x1,-0xb0(%rbp)
mov    0x10(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
mov    %al,-0x6a(%rbp)
mov    0x10(%rbp),%rax
and    $0xff,%rax
mov    %al,-0x69(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    0x10(%rbp),%rax
jae    129f <sha1_t_prf+0x16f>
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x31(%rbp)
mov    0x10(%rbp),%rax
sub    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0xa0(%rbp),%rcx
lea    -0xd0(%rbp),%r8
lea    -0x60(%rbp),%r9
mov    $0x5,%edx
call   1040 <hmac_sha1_vector@plt>
cmpq   $0x14,-0x48(%rbp)
jb     1275 <sha1_t_prf+0x145>
mov    -0x30(%rbp),%rdi
add    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x14,%edx
call   1050 <memcpy@plt>
mov    -0x40(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x40(%rbp)
jmp    128f <sha1_t_prf+0x15f>
mov    -0x30(%rbp),%rdi
add    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1050 <memcpy@plt>
jmp    129f <sha1_t_prf+0x16f>
movq   $0x14,-0xd0(%rbp)
jmp    11fd <sha1_t_prf+0xcd>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha1_t_prf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r9,%r14
mov    %r8,%r13
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    0x10(%rsp),%rcx
mov    %rcx,0x60(%rsp)
movq   $0x0,0x30(%rsp)
mov    %rbx,0x68(%rsp)
add    $0x1,%rax
mov    %rax,0x38(%rsp)
mov    %rbp,0x70(%rsp)
mov    %r13,0x40(%rsp)
lea    0xe(%rsp),%rax
mov    %rax,0x78(%rsp)
lea    0xd(%rsp),%rax
mov    %rax,0x80(%rsp)
mov    0xc0(%rsp),%rax
movaps 0xe54(%rip),%xmm0
movups %xmm0,0x48(%rsp)
mov    %ah,0xe(%rsp)
mov    %al,0xf(%rsp)
test   %rax,%rax
je     1267 <sha1_t_prf+0x137>
movb   $0x1,0xd(%rsp)
lea    0x60(%rsp),%rcx
lea    0x30(%rsp),%r8
lea    0x10(%rsp),%r9
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1040 <hmac_sha1_vector@plt>
mov    0xc0(%rsp),%rbx
xor    %ebp,%ebp
cmp    $0x14,%rbx
jb     1254 <sha1_t_prf+0x124>
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%rdi
mov    $0x14,%edx
mov    %r13,%rsi
call   1050 <memcpy@plt>
add    $0x14,%rbp
movq   $0x14,0x30(%rsp)
cmp    0xc0(%rsp),%rbp
jae    1267 <sha1_t_prf+0x137>
addb   $0x1,0xd(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
lea    0x60(%rsp),%rcx
lea    0x30(%rsp),%r8
mov    %r13,%r9
call   1040 <hmac_sha1_vector@plt>
add    $0xffffffffffffffec,%rbx
cmp    $0x13,%rbx
ja     1200 <sha1_t_prf+0xd0>
add    %rbp,%r14
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @sha1_t_prf(i8* %0, i64 %1, i8* %2, i8* %3, i64 %4, i8* %5, i64 %6) {
%8 = alloca i8
%9 = alloca [20 x i8]
%10 = alloca [2 x i8]
%11 = alloca [5 x i8*]
%12 = alloca [5 x i64]
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%14 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%16 = bitcast [5 x i8*]* %11 to i8*
%17 = bitcast [5 x i64]* %12 to i8*
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i64 0, i64 0
store i8* %13, i8** %18
%19 = getelementptr inbounds [5 x i64], [5 x i64]* %12, i64 0, i64 0
store i64 0, i64* %19
%20 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i64 0, i64 1
store i8* %2, i8** %20
%21 = add i64 %14, 1
%22 = getelementptr inbounds [5 x i64], [5 x i64]* %12, i64 0, i64 1
store i64 %21, i64* %22
%23 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i64 0, i64 2
store i8* %3, i8** %23
%24 = getelementptr inbounds [5 x i64], [5 x i64]* %12, i64 0, i64 2
store i64 %4, i64* %24
%25 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i64 0, i64 3
store i8* %15, i8** %25
%26 = getelementptr inbounds [5 x i64], [5 x i64]* %12, i64 0, i64 3
%27 = getelementptr inbounds [5 x i8*], [5 x i8*]* %11, i64 0, i64 4
store i8* %8, i8** %27
%28 = bitcast i64* %26 to <2 x i64>*
store <2 x i64> <i64 2, i64 1>, <2 x i64>* %28
%29 = lshr i64 %6, 8
%30 = trunc i64 %29 to i8
store i8 %30, i8* %15
%31 = trunc i64 %6 to i8
%32 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 1
store i8 %31, i8* %32
%33 = icmp eq i64 %6, 0
br i1 %33, label %54, label %34
34: ; preds = %7
store i8 1, i8* %8
%35 = call i32 @hmac_sha1_vector(i8* %0, i64 %1, i32 5, i8** %18, i64* %19, i8* %13)
%36 = icmp ugt i64 %6, 19
br i1 %36, label %37, label %49
37: ; preds = %34, %43
%38 = phi i64 [ %41, %43 ], [ 0, %34 ]
%39 = getelementptr inbounds i8, i8* %5, i64 %38
%40 = call i32 @memcpy(i8* %39, i8* %13, i64 20)
%41 = add i64 %38, 20
store i64 20, i64* %19
%42 = icmp ult i64 %41, %6
br i1 %42, label %43, label %54
43: ; preds = %37
%44 = load i8, i8* %8
%45 = add i8 %44, 1
store i8 %45, i8* %8
%46 = sub nuw i64 %6, %41
%47 = call i32 @hmac_sha1_vector(i8* %0, i64 %1, i32 5, i8** %18, i64* %19, i8* %13)
%48 = icmp ugt i64 %46, 19
br i1 %48, label %37, label %49
49: ; preds = %43, %34
%50 = phi i64 [ 0, %34 ], [ %41, %43 ]
%51 = phi i64 [ %6, %34 ], [ %46, %43 ]
%52 = getelementptr inbounds i8, i8* %5, i64 %50
%53 = call i32 @memcpy(i8* %52, i8* %13, i64 %51)
br label %54
54: ; preds = %37, %7, %49
ret void
}