#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*/ salt;
typedef int /*<<< orphan*/ hash;

/* Variables and functions */
int /*<<< orphan*/ PKCS5_PBKDF2_HMAC_SHA1(char *, size_t, unsigned char const *,
                                          int, int, size_t const,
                                          unsigned char *);
size_t SHA_DIGEST_LENGTH;
int a_to_b16(unsigned char *, size_t const, unsigned char *, size_t);
int /*<<< orphan*/ bzero(unsigned char *, int);
int password_to_key(char *pass, size_t pass_len, unsigned char *key,
                    size_t max_keylen) {
  const size_t md_size = SHA_DIGEST_LENGTH;
  unsigned char hash[md_size];
  int ret;
  static const unsigned char salt[] = "eP9VfEvqP7vMC3T3rXC6zOvzVOA=";
  if (max_keylen < md_size * 2 + 1)
    return -1;
  PKCS5_PBKDF2_HMAC_SHA1(pass, pass_len, salt, sizeof(salt), (1 << 17), md_size,
                         hash);
  ret = a_to_b16(hash, md_size, key, max_keylen);
  bzero(hash, sizeof(hash));
  return ret;
}


x86 assembly (clang, -O0):
<password_to_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x1,%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jae    11ad <password_to_key+0x7d>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    1216 <password_to_key+0xe6>
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%r9
lea    0xe3c(%rip),%rdx
mov    $0x1d,%ecx
mov    $0x20000,%r8d
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1030 <PKCS5_PBKDF2_HMAC_SHA1@plt>
mov    -0x50(%rbp),%rdi
add    $0x10,%rsp
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <a_to_b16@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,-0x44(%rbp)
mov    %eax,%esi
call   1040 <bzero@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<password_to_key>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ea3(%rip),%rax
mov    (%rax),%r12
mov    %rsp,%rbx
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    (%r12,%r12,1),%rax
add    $0x1,%rax
mov    $0xffffffff,%r13d
cmp    %rcx,%rax
ja     11b5 <password_to_key+0x85>
mov    %rcx,%r14
mov    %rdx,%r15
sub    $0x8,%rsp
lea    0xe82(%rip),%rdx
mov    $0x1d,%ecx
mov    $0x20000,%r8d
mov    %r12,%r9
push   %rbx
call   1030 <PKCS5_PBKDF2_HMAC_SHA1@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <a_to_b16@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    %r12d,%esi
call   1040 <bzero@plt>
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA_DIGEST_LENGTH = global i64 0
@password_to_key.salt = internal constant [29 x i8] c"eP9VfEvqP7vMC3T3rXC6zOvzVOA=\00"
define i32 @password_to_key(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%15 = load i64, i64* @SHA_DIGEST_LENGTH
store i64 %15, i64* %10
%16 = load i64, i64* %10
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %11
%18 = alloca i8, i64 %16
store i64 %16, i64* %12
%19 = load i64, i64* %9
%20 = load i64, i64* %10
%21 = mul i64 %20, 2
%22 = add i64 %21, 1
%23 = icmp ult i64 %19, %22
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 -1, i32* %5
store i32 1, i32* %14
br label %37
25: ; preds = %4
%26 = load i8*, i8** %6
%27 = load i64, i64* %7
%28 = load i64, i64* %10
%29 = call i32 @PKCS5_PBKDF2_HMAC_SHA1(i8* %26, i64 %27, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @password_to_key.salt, i64 0, i64 0), i32 29, i32 131072, i64 %28, i8* %18)
%30 = load i64, i64* %10
%31 = load i8*, i8** %8
%32 = load i64, i64* %9
%33 = call i32 @a_to_b16(i8* %18, i64 %30, i8* %31, i64 %32)
store i32 %33, i32* %13
%34 = trunc i64 %16 to i32
%35 = call i32 @bzero(i8* %18, i32 %34)
%36 = load i32, i32* %13
store i32 %36, i32* %5
store i32 1, i32* %14
br label %37
37: ; preds = %25, %24
%38 = load i8*, i8** %11
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@SHA_DIGEST_LENGTH = global i64 0
@password_to_key.salt = internal constant [29 x i8] c"eP9VfEvqP7vMC3T3rXC6zOvzVOA=\00"
define i32 @password_to_key(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = load i64, i64* @SHA_DIGEST_LENGTH
%6 = alloca i8, i64 %5
%7 = shl i64 %5, 1
%8 = or i64 %7, 1
%9 = icmp ugt i64 %8, %3
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = call i32 @PKCS5_PBKDF2_HMAC_SHA1(i8* %0, i64 %1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @password_to_key.salt, i64 0, i64 0), i32 29, i32 131072, i64 %5, i8* %6)
%12 = call i32 @a_to_b16(i8* %6, i64 %5, i8* %2, i64 %3)
%13 = trunc i64 %5 to i32
%14 = call i32 @bzero(i8* %6, i32 %13)
br label %15
15: ; preds = %4, %10
%16 = phi i32 [ %12, %10 ], [ -1, %4 ]
ret i32 %16
}