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

/* Variables and functions */
int BIO_write(int /*<<< orphan*/ *, unsigned char *, int);
int do_i2b(unsigned char **, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ free(unsigned char *);
int do_i2b_bio(BIO *out, EVP_PKEY *pk, int ispub) {
  unsigned char *tmp = NULL;
  int outlen, wrlen;
  outlen = do_i2b(&tmp, pk, ispub);
  if (outlen < 0)
    return -1;
  wrlen = BIO_write(out, tmp, outlen);
  free(tmp);
  if (wrlen == outlen)
    return outlen;
  return -1;
}


x86 assembly (clang, -O0):
<do_i2b_bio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rdi
call   1040 <do_i2b@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1174 <do_i2b_bio+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <do_i2b_bio+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <BIO_write@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    11a7 <do_i2b_bio+0x77>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <do_i2b_bio+0x7e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_i2b_bio>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <do_i2b@plt>
test   %eax,%eax
js     117b <do_i2b_bio+0x4b>
mov    %eax,%ebx
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1050 <BIO_write@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
cmp    %ebx,%ebp
mov    $0xffffffff,%eax
cmove  %ebx,%eax
jmp    1180 <do_i2b_bio+0x50>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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