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

/* Variables and functions */
int /*<<< orphan*/ *EVP_PKEY2PKCS8(int /*<<< orphan*/ *);
int /*<<< orphan*/ PKCS8_PRIV_KEY_INFO_free(int /*<<< orphan*/ *);
int i2d_PKCS8_PRIV_KEY_INFO_bio(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) {
  PKCS8_PRIV_KEY_INFO *p8inf;
  int ret;
  p8inf = EVP_PKEY2PKCS8(key);
  if (!p8inf)
    return 0;
  ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
  PKCS8_PRIV_KEY_INFO_free(p8inf);
  return ret;
}


x86 assembly (clang, -O0):
<i2d_PKCS8PrivateKeyInfo_bio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <EVP_PKEY2PKCS8@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1164 <i2d_PKCS8PrivateKeyInfo_bio+0x34>
movl   $0x0,-0x4(%rbp)
jmp    1183 <i2d_PKCS8PrivateKeyInfo_bio+0x53>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <i2d_PKCS8_PRIV_KEY_INFO_bio@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <PKCS8_PRIV_KEY_INFO_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2d_PKCS8PrivateKeyInfo_bio>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <EVP_PKEY2PKCS8@plt>
test   %rax,%rax
je     1160 <i2d_PKCS8PrivateKeyInfo_bio+0x30>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <i2d_PKCS8_PRIV_KEY_INFO_bio@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <PKCS8_PRIV_KEY_INFO_free@plt>
mov    %ebp,%eax
jmp    1162 <i2d_PKCS8PrivateKeyInfo_bio+0x32>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @i2d_PKCS8PrivateKeyInfo_bio(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
%9 = call i32* @EVP_PKEY2PKCS8(i32* %8)
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %20
13: ; preds = %2
%14 = load i32*, i32** %4
%15 = load i32*, i32** %6
%16 = call i32 @i2d_PKCS8_PRIV_KEY_INFO_bio(i32* %14, i32* %15)
store i32 %16, i32* %7
%17 = load i32*, i32** %6
%18 = call i32 @PKCS8_PRIV_KEY_INFO_free(i32* %17)
%19 = load i32, i32* %7
store i32 %19, i32* %3
br label %20
20: ; preds = %13, %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
define i32 @i2d_PKCS8PrivateKeyInfo_bio(i32* %0, i32* %1) {
%3 = tail call i32* @EVP_PKEY2PKCS8(i32* %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @i2d_PKCS8_PRIV_KEY_INFO_bio(i32* %0, i32* %3)
%7 = tail call i32 @PKCS8_PRIV_KEY_INFO_free(i32* %3)
br label %8
8: ; preds = %2, %5
%9 = phi i32 [ %6, %5 ], [ 0, %2 ]
ret i32 %9
}