#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*/ EVP_MD;

/* Variables and functions */
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ OPENSSL_asc2uni(char const *, int, unsigned char **, int *);
int PKCS12_key_gen_uni(unsigned char *, int, unsigned char *, int, int, int,
                       int, unsigned char *, int /*<<< orphan*/ const *);
int /*<<< orphan*/ PKCS12error(int /*<<< orphan*/);
int /*<<< orphan*/ freezero(unsigned char *, int);
int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
                       int saltlen, int id, int iter, int n, unsigned char *out,
                       const EVP_MD *md_type) {
  int ret;
  unsigned char *unipass;
  int uniplen;
  if (!pass) {
    unipass = NULL;
    uniplen = 0;
  } else if (!OPENSSL_asc2uni(pass, passlen, &unipass, &uniplen)) {
    PKCS12error(ERR_R_MALLOC_FAILURE);
    return 0;
  }
  ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen, id, iter, n, out,
                           md_type);
  if (ret <= 0)
    return 0;
  freezero(unipass, uniplen);
  return ret;
}


x86 assembly (clang, -O0):
<PKCS12_key_gen_asc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1188 <PKCS12_key_gen_asc+0x48>
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
jmp    11c4 <PKCS12_key_gen_asc+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
call   1040 <OPENSSL_asc2uni@plt>
cmp    $0x0,%eax
jne    11bf <PKCS12_key_gen_asc+0x7f>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1050 <PKCS12error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1224 <PKCS12_key_gen_asc+0xe4>
jmp    11c4 <PKCS12_key_gen_asc+0x84>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    0x10(%rbp),%r11d
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%rax
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <PKCS12_key_gen_uni@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jg     1212 <PKCS12_key_gen_asc+0xd2>
movl   $0x0,-0x4(%rbp)
jmp    1224 <PKCS12_key_gen_asc+0xe4>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
call   1030 <freezero@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS12_key_gen_asc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %rdx,%rbp
test   %rdi,%rdi
je     1178 <PKCS12_key_gen_asc+0x38>
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1040 <OPENSSL_asc2uni@plt>
test   %eax,%eax
je     11c8 <PKCS12_key_gen_asc+0x88>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
jmp    118d <PKCS12_key_gen_asc+0x4d>
movq   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
xor    %esi,%esi
xor    %edi,%edi
mov    0x40(%rsp),%eax
sub    $0x8,%rsp
mov    %rbp,%rdx
mov    %ebx,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
push   0x58(%rsp)
push   0x58(%rsp)
push   %rax
call   1060 <PKCS12_key_gen_uni@plt>
add    $0x20,%rsp
test   %eax,%eax
jle    11d6 <PKCS12_key_gen_asc+0x96>
mov    %eax,%ebx
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   1030 <freezero@plt>
jmp    11d8 <PKCS12_key_gen_asc+0x98>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1050 <PKCS12error@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @PKCS12_key_gen_asc(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i8* %7, i32* %8) {
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32*
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i32
store i8* %0, i8** %11
store i32 %1, i32* %12
store i8* %2, i8** %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i8* %7, i8** %18
store i32* %8, i32** %19
%23 = load i8*, i8** %11
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %9
store i8* null, i8** %21
store i32 0, i32* %22
br label %35
26: ; preds = %9
%27 = load i8*, i8** %11
%28 = load i32, i32* %12
%29 = call i32 @OPENSSL_asc2uni(i8* %27, i32 %28, i8** %21, i32* %22)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = load i32, i32* @ERR_R_MALLOC_FAILURE
%33 = call i32 @PKCS12error(i32 %32)
store i32 0, i32* %10
br label %54
34: ; preds = %26
br label %35
35: ; preds = %34, %25
%36 = load i8*, i8** %21
%37 = load i32, i32* %22
%38 = load i8*, i8** %13
%39 = load i32, i32* %14
%40 = load i32, i32* %15
%41 = load i32, i32* %16
%42 = load i32, i32* %17
%43 = load i8*, i8** %18
%44 = load i32*, i32** %19
%45 = call i32 @PKCS12_key_gen_uni(i8* %36, i32 %37, i8* %38, i32 %39, i32 %40, i32 %41, i32 %42, i8* %43, i32* %44)
store i32 %45, i32* %20
%46 = load i32, i32* %20
%47 = icmp sle i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %35
store i32 0, i32* %10
br label %54
49: ; preds = %35
%50 = load i8*, i8** %21
%51 = load i32, i32* %22
%52 = call i32 @freezero(i8* %50, i32 %51)
%53 = load i32, i32* %20
store i32 %53, i32* %10
br label %54
54: ; preds = %49, %48, %31
%55 = load i32, i32* %10
ret i32 %55
}

LLVM IR (-O2):
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @PKCS12_key_gen_asc(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i8* %7, i32* %8) {
%10 = alloca i8*
%11 = alloca i32
%12 = bitcast i8** %10 to i8*
%13 = bitcast i32* %11 to i8*
%14 = icmp eq i8* %0, null
br i1 %14, label %15, label %16
15: ; preds = %9
store i8* null, i8** %10
store i32 0, i32* %11
br label %25
16: ; preds = %9
%17 = call i32 @OPENSSL_asc2uni(i8* %0, i32 %1, i8** %10, i32* %11)
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8*, i8** %10
%21 = load i32, i32* %11
br label %25
22: ; preds = %16
%23 = load i32, i32* @ERR_R_MALLOC_FAILURE
%24 = call i32 @PKCS12error(i32 %23)
br label %34
25: ; preds = %19, %15
%26 = phi i32 [ %21, %19 ], [ 0, %15 ]
%27 = phi i8* [ %20, %19 ], [ null, %15 ]
%28 = call i32 @PKCS12_key_gen_uni(i8* %27, i32 %26, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i8* %7, i32* %8)
%29 = icmp slt i32 %28, 1
br i1 %29, label %34, label %30
30: ; preds = %25
%31 = load i8*, i8** %10
%32 = load i32, i32* %11
%33 = call i32 @freezero(i8* %31, i32 %32)
br label %34
34: ; preds = %25, %30, %22
%35 = phi i32 [ %28, %30 ], [ 0, %22 ], [ 0, %25 ]
ret i32 %35
}