#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*/ pem_password_cb;
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
size_t BIO_read(int /*<<< orphan*/ *, unsigned char *, size_t);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ PEM_R_PVK_DATA_TOO_SHORT;
int /*<<< orphan*/ PEMerror(int /*<<< orphan*/);
int /*<<< orphan*/ *do_PVK_body(unsigned char const **, unsigned int,
                                unsigned int, int /*<<< orphan*/ *, void *);
int /*<<< orphan*/ do_PVK_header(unsigned char const **, int,
                                 int /*<<< orphan*/, unsigned int *,
                                 unsigned int *);
int /*<<< orphan*/ freezero(unsigned char *, size_t);
unsigned char *malloc(size_t);
EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u) {
  unsigned char pvk_hdr[24], *buf = NULL;
  const unsigned char *p;
  size_t buflen;
  EVP_PKEY *ret = NULL;
  unsigned int saltlen, keylen;
  if (BIO_read(in, pvk_hdr, 24) != 24) {
    PEMerror(PEM_R_PVK_DATA_TOO_SHORT);
    return NULL;
  }
  p = pvk_hdr;
  if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen))
    return 0;
  buflen = keylen + saltlen;
  buf = malloc(buflen);
  if (!buf) {
    PEMerror(ERR_R_MALLOC_FAILURE);
    return 0;
  }
  p = buf;
  if (BIO_read(in, buf, buflen) != buflen) {
    PEMerror(PEM_R_PVK_DATA_TOO_SHORT);
    goto err;
  }
  ret = do_PVK_body(&p, saltlen, keylen, cb, u);
err:
  freezero(buf, buflen);
  return ret;
}


x86 assembly (clang, -O0):
<b2i_PVK_bio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1050 <BIO_read@plt>
cmp    $0x18,%rax
je     11bb <b2i_PVK_bio+0x5b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1040 <PEMerror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1296 <b2i_PVK_bio+0x136>
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x18,%esi
xor    %edx,%edx
lea    -0x64(%rbp),%rcx
lea    -0x68(%rbp),%r8
call   1060 <do_PVK_header@plt>
cmp    $0x0,%eax
jne    11f1 <b2i_PVK_bio+0x91>
movq   $0x0,-0x8(%rbp)
jmp    1296 <b2i_PVK_bio+0x136>
mov    -0x68(%rbp),%eax
add    -0x64(%rbp),%eax
mov    %eax,%eax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1230 <b2i_PVK_bio+0xd0>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1040 <PEMerror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1296 <b2i_PVK_bio+0x136>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   1050 <BIO_read@plt>
cmp    -0x58(%rbp),%rax
je     1266 <b2i_PVK_bio+0x106>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1040 <PEMerror@plt>
jmp    1281 <b2i_PVK_bio+0x121>
mov    -0x64(%rbp),%esi
mov    -0x68(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    -0x50(%rbp),%rdi
call   1080 <do_PVK_body@plt>
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1030 <freezero@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b2i_PVK_bio>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x10(%rsp),%rbp
mov    $0x18,%edx
mov    %rbp,%rsi
call   1050 <BIO_read@plt>
cmp    $0x18,%rax
jne    1204 <b2i_PVK_bio+0xa4>
mov    %rbp,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %ebp,%ebp
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
mov    $0x18,%esi
xor    %edx,%edx
call   1060 <do_PVK_header@plt>
test   %eax,%eax
je     123a <b2i_PVK_bio+0xda>
mov    0x4(%rsp),%r12d
add    (%rsp),%r12d
mov    %r12,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1216 <b2i_PVK_bio+0xb6>
mov    %rax,%r13
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
call   1050 <BIO_read@plt>
cmp    %r12,%rax
jne    121f <b2i_PVK_bio+0xbf>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
lea    0x8(%rsp),%rdi
mov    %r15,%rcx
mov    %r14,%r8
call   1080 <do_PVK_body@plt>
mov    %rax,%rbp
jmp    122f <b2i_PVK_bio+0xcf>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1040 <PEMerror@plt>
xor    %ebp,%ebp
jmp    123a <b2i_PVK_bio+0xda>
mov    0x2dc3(%rip),%rax
jmp    120b <b2i_PVK_bio+0xab>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1040 <PEMerror@plt>
xor    %ebp,%ebp
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <freezero@plt>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PEM_R_PVK_DATA_TOO_SHORT = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32* @b2i_PVK_bio(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [24 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i8* null, i8** %9
store i32* null, i32** %12
%15 = load i32*, i32** %5
%16 = getelementptr inbounds [24 x i8], [24 x i8]* %8, i64 0, i64 0
%17 = call i64 @BIO_read(i32* %15, i8* %16, i64 24)
%18 = icmp ne i64 %17, 24
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i32, i32* @PEM_R_PVK_DATA_TOO_SHORT
%21 = call i32 @PEMerror(i32 %20)
store i32* null, i32** %4
br label %61
22: ; preds = %3
%23 = getelementptr inbounds [24 x i8], [24 x i8]* %8, i64 0, i64 0
store i8* %23, i8** %10
%24 = call i32 @do_PVK_header(i8** %10, i32 24, i32 0, i32* %13, i32* %14)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22
store i32* null, i32** %4
br label %61
27: ; preds = %22
%28 = load i32, i32* %14
%29 = load i32, i32* %13
%30 = add i32 %28, %29
%31 = zext i32 %30 to i64
store i64 %31, i64* %11
%32 = load i64, i64* %11
%33 = call i8* @malloc(i64 %32)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
%35 = icmp ne i8* %34, null
br i1 %35, label %39, label %36
36: ; preds = %27
%37 = load i32, i32* @ERR_R_MALLOC_FAILURE
%38 = call i32 @PEMerror(i32 %37)
store i32* null, i32** %4
br label %61
39: ; preds = %27
%40 = load i8*, i8** %9
store i8* %40, i8** %10
%41 = load i32*, i32** %5
%42 = load i8*, i8** %9
%43 = load i64, i64* %11
%44 = call i64 @BIO_read(i32* %41, i8* %42, i64 %43)
%45 = load i64, i64* %11
%46 = icmp ne i64 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %39
%48 = load i32, i32* @PEM_R_PVK_DATA_TOO_SHORT
%49 = call i32 @PEMerror(i32 %48)
br label %56
50: ; preds = %39
%51 = load i32, i32* %13
%52 = load i32, i32* %14
%53 = load i32*, i32** %6
%54 = load i8*, i8** %7
%55 = call i32* @do_PVK_body(i8** %10, i32 %51, i32 %52, i32* %53, i8* %54)
store i32* %55, i32** %12
br label %56
56: ; preds = %50, %47
%57 = load i8*, i8** %9
%58 = load i64, i64* %11
%59 = call i32 @freezero(i8* %57, i64 %58)
%60 = load i32*, i32** %12
store i32* %60, i32** %4
br label %61
61: ; preds = %56, %36, %26, %19
%62 = load i32*, i32** %4
ret i32* %62
}

LLVM IR (-O2):
@PEM_R_PVK_DATA_TOO_SHORT = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32* @b2i_PVK_bio(i32* %0, i32* %1, i8* %2) {
%4 = alloca [24 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [24 x i8], [24 x i8]* %4, i64 0, i64 0
%9 = bitcast i8** %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = call i64 @BIO_read(i32* %0, i8* %8, i64 24)
%13 = icmp eq i64 %12, 24
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i32, i32* @PEM_R_PVK_DATA_TOO_SHORT
%16 = call i32 @PEMerror(i32 %15)
br label %43
17: ; preds = %3
store i8* %8, i8** %5
%18 = call i32 @do_PVK_header(i8** %5, i32 24, i32 0, i32* %6, i32* %7)
%19 = icmp eq i32 %18, 0
br i1 %19, label %43, label %20
20: ; preds = %17
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = add i32 %22, %21
%24 = zext i32 %23 to i64
%25 = call i8* @malloc(i64 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i32, i32* @ERR_R_MALLOC_FAILURE
%29 = call i32 @PEMerror(i32 %28)
br label %43
30: ; preds = %20
store i8* %25, i8** %5
%31 = call i64 @BIO_read(i32* %0, i8* %25, i64 %24)
%32 = icmp eq i64 %31, %24
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* @PEM_R_PVK_DATA_TOO_SHORT
%35 = call i32 @PEMerror(i32 %34)
br label %40
36: ; preds = %30
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = call i32* @do_PVK_body(i8** %5, i32 %37, i32 %38, i32* %1, i8* %2)
br label %40
40: ; preds = %36, %33
%41 = phi i32* [ null, %33 ], [ %39, %36 ]
%42 = call i32 @freezero(i8* %25, i64 %24)
br label %43
43: ; preds = %17, %40, %27, %14
%44 = phi i32* [ null, %14 ], [ %41, %40 ], [ null, %27 ], [ null, %17 ]
ret i32* %44
}