#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*/ create_hmac(int, unsigned char const *, int, unsigned char *,
                               unsigned int, unsigned char *, unsigned int *);
int /*<<< orphan*/ free(unsigned char *);
unsigned int get_hash_len(int);
int /*<<< orphan*/ memcpy(unsigned char *, ...);
unsigned char *safe_calloc(unsigned int, int);
unsigned int strlen(char const *);
void P_hash(int hashtype, int bytes, const unsigned char *secret,
            int secret_len, const char *label, const unsigned char *seed,
            int seed_len, unsigned char *outbuf, int *outbuf_len) {
  unsigned char *newseed, *inbuf, *tmpbuf;
  unsigned newseed_len, inbuf_len;
  unsigned int tmpbuf_len, outbuf_len_new;
  newseed = safe_calloc(strlen(label) + seed_len, 1);
  inbuf = safe_calloc(get_hash_len(hashtype) + strlen(label) + seed_len, 1);
  tmpbuf = safe_calloc(get_hash_len(hashtype) + strlen(label) + seed_len, 1);
  *outbuf_len = 0;
  newseed_len = 0;
  memcpy(newseed, label, strlen(label));
  newseed_len += strlen(label);
  memcpy(newseed + newseed_len, seed, seed_len);
  newseed_len += seed_len;
  memcpy(inbuf, newseed, newseed_len);
  inbuf_len = newseed_len;
  while (*outbuf_len < bytes) {
    create_hmac(hashtype, secret, secret_len, inbuf, inbuf_len, tmpbuf,
                &tmpbuf_len);
    memcpy(tmpbuf + tmpbuf_len, newseed, newseed_len);
    tmpbuf_len += newseed_len;
    create_hmac(hashtype, secret, secret_len, tmpbuf, tmpbuf_len,
                outbuf + *outbuf_len, &outbuf_len_new);
    *outbuf_len += outbuf_len_new;
    memcpy(inbuf, tmpbuf, tmpbuf_len);
    inbuf_len = tmpbuf_len;
  }
  free(newseed);
  free(inbuf);
  free(tmpbuf);
}


x86 assembly (clang, -O0):
<P_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    0x10(%rbp),%edi
mov    $0x1,%esi
call   1070 <safe_calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <get_hash_len@plt>
mov    %eax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%edi
add    %eax,%edi
add    0x10(%rbp),%edi
mov    $0x1,%esi
call   1070 <safe_calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <get_hash_len@plt>
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x64(%rbp),%edi
add    %eax,%edi
add    0x10(%rbp),%edi
mov    $0x1,%esi
call   1070 <safe_calloc@plt>
mov    %rax,-0x40(%rbp)
mov    0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x44(%rbp),%eax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    0x10(%rbp),%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    0x10(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x44(%rbp),%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1323 <P_hash+0x1c3>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    -0x48(%rbp),%r8d
mov    -0x40(%rbp),%r9
lea    -0x4c(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <create_hmac@plt>
mov    -0x40(%rbp),%rdi
mov    -0x4c(%rbp),%eax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x44(%rbp),%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    -0x44(%rbp),%eax
add    -0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x4c(%rbp),%r8d
mov    0x18(%rbp),%r9
mov    0x20(%rbp),%rax
movslq (%rax),%rax
add    %rax,%r9
lea    -0x50(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <create_hmac@plt>
mov    -0x50(%rbp),%ecx
mov    0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    127b <P_hash+0x11b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<P_hash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%rbp
mov    %ecx,0x20(%rsp)
mov    %rdx,%r14
mov    %esi,0xc(%rsp)
mov    %edi,%r12d
mov    0x80(%rsp),%r13
mov    0x70(%rsp),%ebx
mov    %r8,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbx,1),%edi
mov    $0x1,%esi
call   1070 <safe_calloc@plt>
mov    %rax,%r15
mov    %rax,0x18(%rsp)
mov    %r12d,%edi
call   1060 <get_hash_len@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    0x70(%rsp),%ecx
add    %ecx,%ebx
add    %eax,%ebx
mov    %ebx,%edi
mov    $0x1,%esi
call   1070 <safe_calloc@plt>
mov    %rax,0x30(%rsp)
mov    %r12d,%edi
call   1060 <get_hash_len@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    0x70(%rsp),%ecx
add    %ecx,%ebx
add    %eax,%ebx
mov    %ebx,%edi
mov    $0x1,%esi
call   1070 <safe_calloc@plt>
mov    %rax,%rbx
movl   $0x0,0x0(%r13)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    %rbp,%rdi
mov    0x30(%rsp),%rbp
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %eax,%edi
add    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x70(%rsp),%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    0x70(%rsp),%eax
add    %eax,%r15d
mov    %rbp,%rdi
mov    0x18(%rsp),%rsi
mov    %r15d,0x10(%rsp)
mov    %r15d,%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    0xc(%rsp),%eax
cmp    %eax,0x0(%r13)
jge    1337 <P_hash+0x1d7>
mov    0x10(%rsp),%r8d
mov    %r14,0x28(%rsp)
mov    0x10(%rsp),%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x8(%rsp),%rax
mov    %rax,(%rsp)
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r12d,%r14d
mov    %r13,%r12
mov    0x20(%rsp),%r13d
mov    %r13d,%edx
mov    %rbp,%rcx
mov    %rbx,%r9
call   1040 <create_hmac@plt>
mov    0x8(%rsp),%edi
add    %rbx,%rdi
mov    0x18(%rsp),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    0x8(%rsp),%r8d
add    %r15d,%r8d
mov    %r8d,0x8(%rsp)
movslq (%r12),%r9
add    0x78(%rsp),%r9
lea    0x24(%rsp),%rax
mov    %rax,(%rsp)
mov    %r14d,%edi
mov    0x28(%rsp),%rsi
mov    %r13d,%edx
mov    %r12,%r13
mov    %r14d,%r12d
mov    0x28(%rsp),%r14
mov    %rbx,%rcx
call   1040 <create_hmac@plt>
mov    0x24(%rsp),%eax
add    %eax,0x0(%r13)
mov    0x8(%rsp),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <memcpy@plt>
mov    0xc(%rsp),%eax
mov    0x8(%rsp),%r8d
cmp    %eax,0x0(%r13)
jl     1290 <P_hash+0x130>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @P_hash(i32 %0, i32 %1, i8* %2, i32 %3, i8* %4, i8* %5, i32 %6, i8* %7, i32* nocapture %8) {
%10 = alloca i32
%11 = alloca i32
%12 = bitcast i32* %10 to i8*
%13 = bitcast i32* %11 to i8*
%14 = tail call i32 @strlen(i8* %4)
%15 = add i32 %14, %6
%16 = tail call i8* @safe_calloc(i32 %15, i32 1)
%17 = tail call i32 @get_hash_len(i32 %0)
%18 = tail call i32 @strlen(i8* %4)
%19 = add i32 %17, %6
%20 = add i32 %19, %18
%21 = tail call i8* @safe_calloc(i32 %20, i32 1)
%22 = tail call i32 @get_hash_len(i32 %0)
%23 = tail call i32 @strlen(i8* %4)
%24 = add i32 %22, %6
%25 = add i32 %24, %23
%26 = tail call i8* @safe_calloc(i32 %25, i32 1)
store i32 0, i32* %8
%27 = tail call i32 @strlen(i8* %4)
%28 = tail call i32 (i8*, ...) @memcpy(i8* %16, i8* %4, i32 %27)
%29 = tail call i32 @strlen(i8* %4)
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %16, i64 %30
%32 = tail call i32 (i8*, ...) @memcpy(i8* %31, i8* %5, i32 %6)
%33 = add i32 %29, %6
%34 = tail call i32 (i8*, ...) @memcpy(i8* %21, i8* %16, i32 %33)
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, %1
br i1 %36, label %37, label %58
37: ; preds = %9, %37
%38 = phi i32 [ %55, %37 ], [ %33, %9 ]
%39 = call i32 @create_hmac(i32 %0, i8* %2, i32 %3, i8* %21, i32 %38, i8* %26, i32* %10)
%40 = load i32, i32* %10
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %26, i64 %41
%43 = call i32 (i8*, ...) @memcpy(i8* %42, i8* %16, i32 %33)
%44 = load i32, i32* %10
%45 = add i32 %44, %33
store i32 %45, i32* %10
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %7, i64 %47
%49 = call i32 @create_hmac(i32 %0, i8* %2, i32 %3, i8* %26, i32 %45, i8* %48, i32* %11)
%50 = load i32, i32* %11
%51 = load i32, i32* %8
%52 = add i32 %51, %50
store i32 %52, i32* %8
%53 = load i32, i32* %10
%54 = call i32 (i8*, ...) @memcpy(i8* %21, i8* %26, i32 %53)
%55 = load i32, i32* %10
%56 = load i32, i32* %8
%57 = icmp slt i32 %56, %1
br i1 %57, label %37, label %58
58: ; preds = %37, %9
%59 = call i32 @free(i8* %16)
%60 = call i32 @free(i8* %21)
%61 = call i32 @free(i8* %26)
ret void
}