#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 */
int BIO_write(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ PEM_R_BIO_WRITE_FAILURE;
int /*<<< orphan*/ PEMerror(int /*<<< orphan*/);
int /*<<< orphan*/ free(unsigned char *);
int i2b_PVK(unsigned char **, int /*<<< orphan*/ *, int, int /*<<< orphan*/ *,
            void *);
int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb,
                void *u) {
  unsigned char *tmp = NULL;
  int outlen, wrlen;
  outlen = i2b_PVK(&tmp, pk, enclevel, cb, u);
  if (outlen < 0)
    return -1;
  wrlen = BIO_write(out, tmp, outlen);
  free(tmp);
  if (wrlen == outlen) {
    PEMerror(PEM_R_BIO_WRITE_FAILURE);
    return outlen;
  }
  return -1;
}


x86 assembly (clang, -O0):
<i2b_PVK_bio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    -0x38(%rbp),%rdi
call   1050 <i2b_PVK@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1194 <i2b_PVK_bio+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <i2b_PVK_bio+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <BIO_write@plt>
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jne    11d5 <i2b_PVK_bio+0x95>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11dc <i2b_PVK_bio+0x9c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2b_PVK_bio>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <i2b_PVK@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     119a <i2b_PVK_bio+0x5a>
mov    %eax,%ebx
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1060 <BIO_write@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
cmp    %ebx,%r14d
jne    119a <i2b_PVK_bio+0x5a>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PEM_R_BIO_WRITE_FAILURE = global i32 0
define i32 @i2b_PVK_bio(i32* %0, i32* %1, i32 %2, i32* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i8* %4, i8** %11
store i8* null, i8** %12
%15 = load i32*, i32** %8
%16 = load i32, i32* %9
%17 = load i32*, i32** %10
%18 = load i8*, i8** %11
%19 = call i32 @i2b_PVK(i8** %12, i32* %15, i32 %16, i32* %17, i8* %18)
store i32 %19, i32* %13
%20 = load i32, i32* %13
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %5
store i32 -1, i32* %6
br label %38
23: ; preds = %5
%24 = load i32*, i32** %7
%25 = load i8*, i8** %12
%26 = load i32, i32* %13
%27 = call i32 @BIO_write(i32* %24, i8* %25, i32 %26)
store i32 %27, i32* %14
%28 = load i8*, i8** %12
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %14
%31 = load i32, i32* %13
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %23
%34 = load i32, i32* @PEM_R_BIO_WRITE_FAILURE
%35 = call i32 @PEMerror(i32 %34)
%36 = load i32, i32* %13
store i32 %36, i32* %6
br label %38
37: ; preds = %23
store i32 -1, i32* %6
br label %38
38: ; preds = %37, %33, %22
%39 = load i32, i32* %6
ret i32 %39
}

LLVM IR (-O2):
@PEM_R_BIO_WRITE_FAILURE = global i32 0
define i32 @i2b_PVK_bio(i32* %0, i32* %1, i32 %2, i32* %3, i8* %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%8 = call i32 @i2b_PVK(i8** %6, i32* %1, i32 %2, i32* %3, i8* %4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %5
%11 = load i8*, i8** %6
%12 = call i32 @BIO_write(i32* %0, i8* %11, i32 %8)
%13 = load i8*, i8** %6
%14 = call i32 @free(i8* %13)
%15 = icmp eq i32 %12, %8
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* @PEM_R_BIO_WRITE_FAILURE
%18 = call i32 @PEMerror(i32 %17)
br label %19
19: ; preds = %10, %5, %16
%20 = phi i32 [ %8, %16 ], [ -1, %5 ], [ -1, %10 ]
ret i32 %20
}