#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*/ HMAC_CTX;
typedef int /*<<< orphan*/ EVP_MD;

/* Variables and functions */
int EVP_MAX_MD_SIZE;
int /*<<< orphan*/ HMAC(int /*<<< orphan*/ const *, unsigned char const *, int,
                        unsigned char *, unsigned int, unsigned char *,
                        int /*<<< orphan*/ *);
int /*<<< orphan*/ HMAC_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *HMAC_CTX_new();
int /*<<< orphan*/ HMAC_Final(int /*<<< orphan*/ *, unsigned char *,
                              unsigned int *);
int /*<<< orphan*/ HMAC_Init_ex(int /*<<< orphan*/ *, unsigned char const *,
                                int, int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ HMAC_Update(int /*<<< orphan*/ *, void const *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int tls1_P_hash(const EVP_MD *md, const unsigned char *sec, int sec_len,
                const void *seed1, int seed1_len, const void *seed2,
                int seed2_len, const void *seed3, int seed3_len,
                unsigned char *out, int olen) {
  unsigned char A1[EVP_MAX_MD_SIZE];
  HMAC_CTX *ctx = HMAC_CTX_new();
  unsigned int chunk;
  int i = 0;
  HMAC_Init_ex(ctx, sec, sec_len, md, NULL);
  do {
    if (i)
      HMAC_Update(ctx, A1, chunk);
    if (seed1)
      HMAC_Update(ctx, seed1, seed1_len);
    if (seed2)
      HMAC_Update(ctx, seed2, seed2_len);
    if (seed3)
      HMAC_Update(ctx, seed3, seed3_len);
    if (!i)
      HMAC_Final(ctx, A1, &chunk);
    else if (i * chunk <= olen) {
      HMAC_Final(ctx, out + ((i - 1) * chunk), NULL);
      HMAC(md, sec, sec_len, A1, chunk, A1, NULL);
    } else {
      HMAC_Final(ctx, A1, NULL);
      memcpy(out + ((i - 1) * chunk), A1, olen % chunk);
      break;
    }
    HMAC_Init_ex(ctx, NULL, 0, NULL, NULL);
    i++;
  } while ((i - 1) * chunk <= olen);
  HMAC_CTX_free(ctx);
  return 1;
}


x86 assembly (clang, -O0):
<tls1_P_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <HMAC_CTX_new@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <HMAC_Init_ex@plt>
cmpl   $0x0,-0x50(%rbp)
je     1211 <tls1_P_hash+0xa1>
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    -0x4c(%rbp),%edx
call   1040 <HMAC_Update@plt>
cmpq   $0x0,-0x20(%rbp)
je     122c <tls1_P_hash+0xbc>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <HMAC_Update@plt>
cmpq   $0x0,-0x30(%rbp)
je     1247 <tls1_P_hash+0xd7>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1040 <HMAC_Update@plt>
cmpq   $0x0,0x18(%rbp)
je     1262 <tls1_P_hash+0xf2>
mov    -0x48(%rbp),%rdi
mov    0x18(%rbp),%rsi
mov    0x20(%rbp),%edx
call   1040 <HMAC_Update@plt>
cmpl   $0x0,-0x50(%rbp)
jne    1282 <tls1_P_hash+0x112>
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%rdi
lea    -0x4c(%rbp),%rdx
call   1070 <HMAC_Final@plt>
jmp    1323 <tls1_P_hash+0x1b3>
mov    -0x50(%rbp),%eax
imul   -0x4c(%rbp),%eax
cmp    0x30(%rbp),%eax
ja     12e4 <tls1_P_hash+0x174>
mov    -0x48(%rbp),%rdi
mov    0x28(%rbp),%rsi
mov    -0x50(%rbp),%eax
sub    $0x1,%eax
imul   -0x4c(%rbp),%eax
mov    %eax,%eax
add    %rax,%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <HMAC_Final@plt>
mov    -0x58(%rbp),%r9
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x4c(%rbp),%r8d
xor    %eax,%eax
sub    $0x10,%rsp
mov    %r9,%rcx
movq   $0x0,(%rsp)
call   1060 <HMAC@plt>
add    $0x10,%rsp
jmp    131e <tls1_P_hash+0x1ae>
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <HMAC_Final@plt>
mov    -0x58(%rbp),%rsi
mov    0x28(%rbp),%rdi
mov    -0x50(%rbp),%eax
sub    $0x1,%eax
imul   -0x4c(%rbp),%eax
mov    %eax,%eax
add    %rax,%rdi
mov    0x30(%rbp),%eax
xor    %edx,%edx
divl   -0x4c(%rbp)
call   1050 <memcpy@plt>
jmp    1355 <tls1_P_hash+0x1e5>
jmp    1323 <tls1_P_hash+0x1b3>
mov    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
xor    %edx,%edx
mov    %r8,%rsi
mov    %r8,%rcx
call   1090 <HMAC_Init_ex@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
sub    $0x1,%eax
imul   -0x4c(%rbp),%eax
cmp    0x30(%rbp),%eax
jbe    11f7 <tls1_P_hash+0x87>
mov    -0x48(%rbp),%rdi
call   1080 <HMAC_CTX_free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    $0x1,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tls1_P_hash>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r13
mov    %r8d,-0x34(%rbp)
mov    %rcx,%r14
mov    %edx,-0x30(%rbp)
mov    %rsi,-0x48(%rbp)
mov    %rdi,-0x40(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <HMAC_CTX_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    -0x40(%rbp),%rcx
xor    %r8d,%r8d
call   1090 <HMAC_Init_ex@plt>
jmp    1216 <tls1_P_hash+0xa6>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r12,%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <HMAC_Final@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <HMAC_Init_ex@plt>
mov    -0x2c(%rbp),%edx
mov    %edx,%eax
imul   %r15d,%eax
add    $0x1,%r15d
cmp    0x30(%rbp),%eax
ja     12e3 <tls1_P_hash+0x173>
test   %r15d,%r15d
je     1226 <tls1_P_hash+0xb6>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <HMAC_Update@plt>
test   %r14,%r14
je     1239 <tls1_P_hash+0xc9>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    -0x34(%rbp),%edx
call   1040 <HMAC_Update@plt>
test   %r13,%r13
je     124c <tls1_P_hash+0xdc>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    0x10(%rbp),%edx
call   1040 <HMAC_Update@plt>
mov    0x18(%rbp),%rsi
test   %rsi,%rsi
je     1260 <tls1_P_hash+0xf0>
mov    %rbx,%rdi
mov    0x20(%rbp),%edx
call   1040 <HMAC_Update@plt>
test   %r15d,%r15d
je     11e0 <tls1_P_hash+0x70>
mov    -0x2c(%rbp),%esi
mov    %esi,%eax
imul   %r15d,%eax
cmp    0x30(%rbp),%eax
ja     12b5 <tls1_P_hash+0x145>
lea    -0x1(%r15),%eax
imul   %eax,%esi
add    0x28(%rbp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1070 <HMAC_Final@plt>
mov    -0x2c(%rbp),%r8d
sub    $0x8,%rsp
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    %r12,%rcx
mov    %r12,%r9
push   $0x0
call   1060 <HMAC@plt>
add    $0x10,%rsp
jmp    11ef <tls1_P_hash+0x7f>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1070 <HMAC_Final@plt>
add    $0xffffffff,%r15d
mov    -0x2c(%rbp),%ecx
imul   %ecx,%r15d
mov    0x28(%rbp),%rdi
add    %r15,%rdi
mov    0x30(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %r12,%rsi
call   1050 <memcpy@plt>
mov    %rbx,%rdi
call   1080 <HMAC_CTX_free@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EVP_MAX_MD_SIZE = global i32 0
define i32 @tls1_P_hash(i32* %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5, i32 %6, i8* %7, i32 %8, i8* %9, i32 %10) {
%12 = alloca i32
%13 = load i32, i32* @EVP_MAX_MD_SIZE
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
%16 = tail call i32* (...) @HMAC_CTX_new()
%17 = bitcast i32* %12 to i8*
%18 = tail call i32 @HMAC_Init_ex(i32* %16, i8* %1, i32 %2, i32* %0, i32* null)
%19 = icmp eq i8* %3, null
%20 = icmp eq i8* %5, null
%21 = icmp eq i8* %7, null
br label %22
22: ; preds = %61, %11
%23 = phi i32 [ undef, %11 ], [ %64, %61 ]
%24 = phi i32 [ 0, %11 ], [ %63, %61 ]
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 @HMAC_Update(i32* %16, i8* %15, i32 %23)
br label %28
28: ; preds = %26, %22
br i1 %19, label %31, label %29
29: ; preds = %28
%30 = call i32 @HMAC_Update(i32* %16, i8* %3, i32 %4)
br label %31
31: ; preds = %29, %28
br i1 %20, label %34, label %32
32: ; preds = %31
%33 = call i32 @HMAC_Update(i32* %16, i8* %5, i32 %6)
br label %34
34: ; preds = %32, %31
br i1 %21, label %37, label %35
35: ; preds = %34
%36 = call i32 @HMAC_Update(i32* %16, i8* %7, i32 %8)
br label %37
37: ; preds = %35, %34
br i1 %25, label %38, label %40
38: ; preds = %37
%39 = call i32 @HMAC_Final(i32* %16, i8* %15, i32* %12)
br label %61
40: ; preds = %37
%41 = load i32, i32* %12
%42 = mul i32 %41, %24
%43 = icmp ugt i32 %42, %10
br i1 %43, label %52, label %44
44: ; preds = %40
%45 = add nsw i32 %24, -1
%46 = mul i32 %41, %45
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %9, i64 %47
%49 = call i32 @HMAC_Final(i32* %16, i8* %48, i32* null)
%50 = load i32, i32* %12
%51 = call i32 @HMAC(i32* %0, i8* %1, i32 %2, i8* %15, i32 %50, i8* %15, i32* null)
br label %61
52: ; preds = %40
%53 = call i32 @HMAC_Final(i32* %16, i8* %15, i32* null)
%54 = add nsw i32 %24, -1
%55 = load i32, i32* %12
%56 = mul i32 %55, %54
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %9, i64 %57
%59 = urem i32 %10, %55
%60 = call i32 @memcpy(i8* %58, i8* %15, i32 %59)
br label %67
61: ; preds = %44, %38
%62 = call i32 @HMAC_Init_ex(i32* %16, i8* null, i32 0, i32* null, i32* null)
%63 = add nuw nsw i32 %24, 1
%64 = load i32, i32* %12
%65 = mul i32 %64, %24
%66 = icmp ugt i32 %65, %10
br i1 %66, label %67, label %22
67: ; preds = %61, %52
%68 = call i32 @HMAC_CTX_free(i32* %16)
ret i32 1
}