#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*/ hmac_sha1(unsigned char *, int, unsigned char *, int,
                             unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
void Mrvl_PRF(unsigned char *key, int key_len, unsigned char *prefix,
              int prefix_len, unsigned char *data, int data_len,
              unsigned char *output, int len) {
  int i;
  unsigned char input[1024];
  int currentindex = 0;
  int total_len;
  memcpy(input, prefix, prefix_len);
  input[prefix_len] = 0;
  memcpy(&input[prefix_len + 1], data, data_len);
  total_len = prefix_len + 1 + data_len;
  input[total_len] = 0;
  total_len++;
  for (i = 0; i < (len + 19) / 20; i++) {
    hmac_sha1(input, total_len, key, key_len, &output[currentindex]);
    currentindex += 20;
    input[total_len - 1]++;
  }
}


x86 assembly (clang, -O0):
<Mrvl_PRF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x434(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
lea    -0x430(%rbp),%rdi
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x438(%rbp)
movslq -0x438(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x438(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x438(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    0x18(%rbp),%eax
add    $0x13,%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x43c(%rbp),%eax
cmp    %ecx,%eax
jge    124a <Mrvl_PRF+0x12a>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    0x10(%rbp),%r8
movslq -0x434(%rbp),%rax
add    %rax,%r8
call   1040 <hmac_sha1@plt>
mov    -0x434(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x434(%rbp)
mov    -0x438(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x430(%rbp,%rax,1),%cl
add    $0x1,%cl
mov    %cl,-0x430(%rbp,%rax,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c3 <Mrvl_PRF+0xa3>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mrvl_PRF>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %r9d,%r14d
mov    %r8,%r13
mov    %ecx,%ebp
mov    %esi,%r15d
mov    %rdi,%r12
mov    %rsp,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1030 <memcpy@plt>
movslq %ebp,%rbx
movb   $0x0,(%rsp,%rbx,1)
lea    (%rsp,%rbx,1),%rdi
add    $0x1,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
lea    (%rbx,%r14,1),%eax
add    $0x1,%eax
movslq %eax,%r13
mov    0x448(%rsp),%eax
movb   $0x0,(%rsp,%r13,1)
test   %eax,%eax
jle    11c2 <Mrvl_PRF+0xa2>
mov    0x440(%rsp),%rbp
add    %r14d,%ebx
add    $0x2,%ebx
add    $0x13,%eax
mov    $0xcccccccd,%r14d
imul   %rax,%r14
shr    $0x24,%r14
nop
mov    %rsp,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %rbp,%r8
call   1040 <hmac_sha1@plt>
addb   $0x1,(%rsp,%r13,1)
add    $0x14,%rbp
add    $0xffffffff,%r14d
jne    11a0 <Mrvl_PRF+0x80>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @Mrvl_PRF(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5, i8* %6, i32 %7) {
%9 = alloca [1024 x i8]
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%11 = call i32 @memcpy(i8* %10, i8* %2, i32 %3)
%12 = sext i32 %3 to i64
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %12
store i8 0, i8* %13
%14 = add nsw i32 %3, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %15
%17 = call i32 @memcpy(i8* %16, i8* %4, i32 %5)
%18 = add nsw i32 %14, %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %19
store i8 0, i8* %20
%21 = add nsw i32 %18, 1
%22 = icmp sgt i32 %7, 0
br i1 %22, label %23, label %36
23: ; preds = %8
%24 = add nuw nsw i32 %7, 19
%25 = udiv i32 %24, 20
br label %26
26: ; preds = %23, %26
%27 = phi i64 [ 0, %23 ], [ %31, %26 ]
%28 = phi i32 [ 0, %23 ], [ %34, %26 ]
%29 = getelementptr inbounds i8, i8* %6, i64 %27
%30 = call i32 @hmac_sha1(i8* %10, i32 %21, i8* %0, i32 %1, i8* %29)
%31 = add nuw nsw i64 %27, 20
%32 = load i8, i8* %20
%33 = add i8 %32, 1
store i8 %33, i8* %20
%34 = add nuw nsw i32 %28, 1
%35 = icmp eq i32 %34, %25
br i1 %35, label %36, label %26
36: ; preds = %26, %8
ret void
}