#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ X509_SIG;
struct TYPE_3__ {
  int length;
  int /*<<< orphan*/ data;
};
typedef int /*<<< orphan*/ PKCS8_PRIV_KEY_INFO;
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ EC_KEY;
typedef TYPE_1__ BUF_MEM;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_get_mem_ptr(int /*<<< orphan*/ *, TYPE_1__ **);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ *EC_KEY_dup(int /*<<< orphan*/ const *);
int /*<<< orphan*/ EC_KEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY2PKCS8(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_new();
int /*<<< orphan*/ EVP_PKEY_set1_EC_KEY(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_aes_256_cbc();
int PEM_write_bio_PKCS8(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int PEM_write_bio_PKCS8_PRIV_KEY_INFO(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ PKCS8_PRIV_KEY_INFO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *PKCS8_encrypt(int, int /*<<< orphan*/, char const *,
                                  int /*<<< orphan*/, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/, int,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_SIG_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strlen(char const *);
int vg_pkcs8_encode_privkey(char *out, int outlen, const EC_KEY *pkey,
                            const char *pass) {
  EC_KEY *pkey_copy = NULL;
  EVP_PKEY *evp_key = NULL;
  PKCS8_PRIV_KEY_INFO *pkcs8 = NULL;
  X509_SIG *pkcs8_enc = NULL;
  BUF_MEM *memptr;
  BIO *bio = NULL;
  int res = 0;
  pkey_copy = EC_KEY_dup(pkey);
  if (!pkey_copy)
    goto out;
  evp_key = EVP_PKEY_new();
  if (!evp_key || !EVP_PKEY_set1_EC_KEY(evp_key, pkey_copy))
    goto out;
  pkcs8 = EVP_PKEY2PKCS8(evp_key);
  if (!pkcs8)
    goto out;
  bio = BIO_new(BIO_s_mem());
  if (!bio)
    goto out;
  if (!pass) {
    res = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bio, pkcs8);
  } else {
    pkcs8_enc = PKCS8_encrypt(-1, EVP_aes_256_cbc(), pass, strlen(pass), NULL,
                              0, 4096, pkcs8);
    if (!pkcs8_enc)
      goto out;
    res = PEM_write_bio_PKCS8(bio, pkcs8_enc);
  }
  BIO_get_mem_ptr(bio, &memptr);
  res = memptr->length;
  if (res < outlen) {
    memcpy(out, memptr->data, res);
    out[res] = '\0';
  } else {
    memcpy(out, memptr->data, outlen - 1);
    out[outlen - 1] = '\0';
  }
out:
  if (bio)
    BIO_free(bio);
  if (pkey_copy)
    EC_KEY_free(pkey_copy);
  if (evp_key)
    EVP_PKEY_free(evp_key);
  if (pkcs8)
    PKCS8_PRIV_KEY_INFO_free(pkcs8);
  if (pkcs8_enc)
    X509_SIG_free(pkcs8_enc);
  return res;
}


x86 assembly (clang, -O0):
<vg_pkcs8_encode_privkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1140 <EC_KEY_dup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1286 <vg_pkcs8_encode_privkey+0x66>
jmp    13f0 <vg_pkcs8_encode_privkey+0x1d0>
mov    $0x0,%al
call   10c0 <EVP_PKEY_new@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12b2 <vg_pkcs8_encode_privkey+0x92>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1110 <EVP_PKEY_set1_EC_KEY@plt>
cmp    $0x0,%eax
jne    12b7 <vg_pkcs8_encode_privkey+0x97>
jmp    13f0 <vg_pkcs8_encode_privkey+0x1d0>
mov    -0x30(%rbp),%rdi
call   10f0 <EVP_PKEY2PKCS8@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12d4 <vg_pkcs8_encode_privkey+0xb4>
jmp    13f0 <vg_pkcs8_encode_privkey+0x1d0>
mov    $0x0,%al
call   1130 <BIO_s_mem@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12f6 <vg_pkcs8_encode_privkey+0xd6>
jmp    13f0 <vg_pkcs8_encode_privkey+0x1d0>
cmpq   $0x0,-0x20(%rbp)
jne    1316 <vg_pkcs8_encode_privkey+0xf6>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <PEM_write_bio_PKCS8_PRIV_KEY_INFO@plt>
mov    %eax,-0x54(%rbp)
jmp    137e <vg_pkcs8_encode_privkey+0x15e>
mov    $0x0,%al
call   1030 <EVP_aes_256_cbc@plt>
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x64(%rbp),%esi
mov    -0x60(%rbp),%rdx
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    $0xffffffff,%edi
xor    %r8d,%r8d
xor    %r9d,%r9d
movl   $0x1000,(%rsp)
mov    %rax,0x8(%rsp)
call   1120 <PKCS8_encrypt@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    136e <vg_pkcs8_encode_privkey+0x14e>
jmp    13f0 <vg_pkcs8_encode_privkey+0x1d0>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <PEM_write_bio_PKCS8@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1100 <BIO_get_mem_ptr@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13c4 <vg_pkcs8_encode_privkey+0x1a4>
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x54(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    13eb <vg_pkcs8_encode_privkey+0x1cb>
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1080 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    13f0 <vg_pkcs8_encode_privkey+0x1d0>
cmpq   $0x0,-0x50(%rbp)
je     1404 <vg_pkcs8_encode_privkey+0x1e4>
mov    -0x50(%rbp),%rdi
call   10b0 <BIO_free@plt>
cmpq   $0x0,-0x28(%rbp)
je     1418 <vg_pkcs8_encode_privkey+0x1f8>
mov    -0x28(%rbp),%rdi
call   10d0 <EC_KEY_free@plt>
cmpq   $0x0,-0x30(%rbp)
je     142c <vg_pkcs8_encode_privkey+0x20c>
mov    -0x30(%rbp),%rdi
call   1060 <EVP_PKEY_free@plt>
cmpq   $0x0,-0x38(%rbp)
je     1440 <vg_pkcs8_encode_privkey+0x220>
mov    -0x38(%rbp),%rdi
call   10e0 <PKCS8_PRIV_KEY_INFO_free@plt>
cmpq   $0x0,-0x40(%rbp)
je     1454 <vg_pkcs8_encode_privkey+0x234>
mov    -0x40(%rbp),%rdi
call   1070 <X509_SIG_free@plt>
mov    -0x54(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_pkcs8_encode_privkey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r12
mov    %esi,%ebp
mov    %rdi,%r15
mov    %rdx,%rdi
call   1140 <EC_KEY_dup@plt>
test   %rax,%rax
je     1318 <vg_pkcs8_encode_privkey+0xf8>
mov    %rax,%r13
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <EVP_PKEY_new@plt>
test   %rax,%rax
je     1347 <vg_pkcs8_encode_privkey+0x127>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r13,%rsi
call   1110 <EVP_PKEY_set1_EC_KEY@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     131f <vg_pkcs8_encode_privkey+0xff>
mov    %rbp,0x28(%rsp)
mov    %r14,%rdi
call   10f0 <EVP_PKEY2PKCS8@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     131f <vg_pkcs8_encode_privkey+0xff>
xor    %eax,%eax
call   1130 <BIO_s_mem@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,0x20(%rsp)
test   %rax,%rax
je     1354 <vg_pkcs8_encode_privkey+0x134>
test   %r12,%r12
je     135b <vg_pkcs8_encode_privkey+0x13b>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <EVP_aes_256_cbc@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    $0xffffffff,%edi
mov    %ebx,%esi
mov    %r12,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   0x8(%rsp)
push   $0x1000
call   1120 <PKCS8_encrypt@plt>
add    $0x10,%rsp
mov    $0x0,%ebx
test   %rax,%rax
mov    0x20(%rsp),%rdi
je     13bc <vg_pkcs8_encode_privkey+0x19c>
mov    %rax,%r12
mov    %r15,0x18(%rsp)
mov    %rdi,%r15
mov    %rax,%rsi
call   1040 <PEM_write_bio_PKCS8@plt>
mov    %r12,0x10(%rsp)
jmp    1379 <vg_pkcs8_encode_privkey+0x159>
xor    %ebx,%ebx
jmp    13e8 <vg_pkcs8_encode_privkey+0x1c8>
xor    %ebp,%ebp
mov    %r13,%rdi
call   10d0 <EC_KEY_free@plt>
mov    %r14,%rdi
call   1060 <EVP_PKEY_free@plt>
test   %rbp,%rbp
je     13e8 <vg_pkcs8_encode_privkey+0x1c8>
mov    %rbp,%rdi
call   10e0 <PKCS8_PRIV_KEY_INFO_free@plt>
jmp    13e8 <vg_pkcs8_encode_privkey+0x1c8>
mov    %r13,%rdi
call   10d0 <EC_KEY_free@plt>
jmp    13e8 <vg_pkcs8_encode_privkey+0x1c8>
mov    0x8(%rsp),%rbp
jmp    1321 <vg_pkcs8_encode_privkey+0x101>
mov    %r15,0x18(%rsp)
mov    0x20(%rsp),%r15
mov    %r15,%rdi
mov    0x8(%rsp),%rsi
call   1090 <PEM_write_bio_PKCS8_PRIV_KEY_INFO@plt>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
lea    0x30(%rsp),%rsi
mov    %r15,%rdi
call   1100 <BIO_get_mem_ptr@plt>
mov    0x30(%rsp),%rax
mov    (%rax),%ebx
mov    0x4(%rax),%esi
mov    0x28(%rsp),%rax
lea    -0x1(%rax),%ebp
cmp    %eax,%ebx
cmovl  %ebx,%ebp
mov    0x18(%rsp),%r12
mov    %r12,%rdi
mov    %ebp,%edx
call   1080 <memcpy@plt>
mov    %r15,%rdi
movslq %ebp,%rax
movb   $0x0,(%r12,%rax,1)
mov    0x10(%rsp),%rbp
call   10b0 <BIO_free@plt>
mov    %r13,%rdi
call   10d0 <EC_KEY_free@plt>
mov    %r14,%rdi
call   1060 <EVP_PKEY_free@plt>
mov    0x8(%rsp),%rdi
call   10e0 <PKCS8_PRIV_KEY_INFO_free@plt>
test   %rbp,%rbp
je     13e8 <vg_pkcs8_encode_privkey+0x1c8>
mov    %rbp,%rdi
call   1070 <X509_SIG_free@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
define i32 @vg_pkcs8_encode_privkey(i8* %0, i32 %1, i32* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca %struct.TYPE_3__*
%14 = alloca i32*
%15 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i8* %3, i8** %8
store i32* null, i32** %9
store i32* null, i32** %10
store i32* null, i32** %11
store i32* null, i32** %12
store i32* null, i32** %14
store i32 0, i32* %15
%16 = load i32*, i32** %7
%17 = call i32* @EC_KEY_dup(i32* %16)
store i32* %17, i32** %9
%18 = load i32*, i32** %9
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %4
br label %98
21: ; preds = %4
%22 = call i32* (...) @EVP_PKEY_new()
store i32* %22, i32** %10
%23 = load i32*, i32** %10
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32*, i32** %10
%27 = load i32*, i32** %9
%28 = call i32 @EVP_PKEY_set1_EC_KEY(i32* %26, i32* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25, %21
br label %98
31: ; preds = %25
%32 = load i32*, i32** %10
%33 = call i32* @EVP_PKEY2PKCS8(i32* %32)
store i32* %33, i32** %11
%34 = load i32*, i32** %11
%35 = icmp ne i32* %34, null
br i1 %35, label %37, label %36
36: ; preds = %31
br label %98
37: ; preds = %31
%38 = call i32 (...) @BIO_s_mem()
%39 = call i32* @BIO_new(i32 %38)
store i32* %39, i32** %14
%40 = load i32*, i32** %14
%41 = icmp ne i32* %40, null
br i1 %41, label %43, label %42
42: ; preds = %37
br label %98
43: ; preds = %37
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
br i1 %45, label %50, label %46
46: ; preds = %43
%47 = load i32*, i32** %14
%48 = load i32*, i32** %11
%49 = call i32 @PEM_write_bio_PKCS8_PRIV_KEY_INFO(i32* %47, i32* %48)
store i32 %49, i32* %15
br label %64
50: ; preds = %43
%51 = call i32 (...) @EVP_aes_256_cbc()
%52 = load i8*, i8** %8
%53 = load i8*, i8** %8
%54 = call i32 @strlen(i8* %53)
%55 = load i32*, i32** %11
%56 = call i32* @PKCS8_encrypt(i32 -1, i32 %51, i8* %52, i32 %54, i32* null, i32 0, i32 4096, i32* %55)
store i32* %56, i32** %12
%57 = load i32*, i32** %12
%58 = icmp ne i32* %57, null
br i1 %58, label %60, label %59
59: ; preds = %50
br label %98
60: ; preds = %50
%61 = load i32*, i32** %14
%62 = load i32*, i32** %12
%63 = call i32 @PEM_write_bio_PKCS8(i32* %61, i32* %62)
store i32 %63, i32* %15
br label %64
64: ; preds = %60, %46
%65 = load i32*, i32** %14
%66 = call i32 @BIO_get_mem_ptr(i32* %65, %struct.TYPE_3__** %13)
%67 = load %struct.TYPE_3__*, %struct.TYPE_3__** %13
%68 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %67, i32 0, i32 0
%69 = load i32, i32* %68
store i32 %69, i32* %15
%70 = load i32, i32* %15
%71 = load i32, i32* %6
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %84
73: ; preds = %64
%74 = load i8*, i8** %5
%75 = load %struct.TYPE_3__*, %struct.TYPE_3__** %13
%76 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %75, i32 0, i32 1
%77 = load i32, i32* %76
%78 = load i32, i32* %15
%79 = call i32 @memcpy(i8* %74, i32 %77, i32 %78)
%80 = load i8*, i8** %5
%81 = load i32, i32* %15
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 0, i8* %83
br label %97
84: ; preds = %64
%85 = load i8*, i8** %5
%86 = load %struct.TYPE_3__*, %struct.TYPE_3__** %13
%87 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %86, i32 0, i32 1
%88 = load i32, i32* %87
%89 = load i32, i32* %6
%90 = sub nsw i32 %89, 1
%91 = call i32 @memcpy(i8* %85, i32 %88, i32 %90)
%92 = load i8*, i8** %5
%93 = load i32, i32* %6
%94 = sub nsw i32 %93, 1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %92, i64 %95
store i8 0, i8* %96
br label %97
97: ; preds = %84, %73
br label %98
98: ; preds = %97, %59, %42, %36, %30, %20
%99 = load i32*, i32** %14
%100 = icmp ne i32* %99, null
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i32*, i32** %14
%103 = call i32 @BIO_free(i32* %102)
br label %104
104: ; preds = %101, %98
%105 = load i32*, i32** %9
%106 = icmp ne i32* %105, null
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = load i32*, i32** %9
%109 = call i32 @EC_KEY_free(i32* %108)
br label %110
110: ; preds = %107, %104
%111 = load i32*, i32** %10
%112 = icmp ne i32* %111, null
br i1 %112, label %113, label %116
113: ; preds = %110
%114 = load i32*, i32** %10
%115 = call i32 @EVP_PKEY_free(i32* %114)
br label %116
116: ; preds = %113, %110
%117 = load i32*, i32** %11
%118 = icmp ne i32* %117, null
br i1 %118, label %119, label %122
119: ; preds = %116
%120 = load i32*, i32** %11
%121 = call i32 @PKCS8_PRIV_KEY_INFO_free(i32* %120)
br label %122
122: ; preds = %119, %116
%123 = load i32*, i32** %12
%124 = icmp ne i32* %123, null
br i1 %124, label %125, label %128
125: ; preds = %122
%126 = load i32*, i32** %12
%127 = call i32 @X509_SIG_free(i32* %126)
br label %128
128: ; preds = %125, %122
%129 = load i32, i32* %15
ret i32 %129
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
define i32 @vg_pkcs8_encode_privkey(i8* %0, i32 %1, i32* %2, i8* %3) {
%5 = alloca %struct.TYPE_3__*
%6 = bitcast %struct.TYPE_3__** %5 to i8*
%7 = tail call i32* @EC_KEY_dup(i32* %2)
%8 = icmp eq i32* %7, null
br i1 %8, label %66, label %9
9: ; preds = %4
%10 = tail call i32* (...) @EVP_PKEY_new()
%11 = icmp eq i32* %10, null
br i1 %11, label %47, label %12
12: ; preds = %9
%13 = tail call i32 @EVP_PKEY_set1_EC_KEY(i32* %10, i32* %7)
%14 = icmp eq i32 %13, 0
br i1 %14, label %49, label %15
15: ; preds = %12
%16 = tail call i32* @EVP_PKEY2PKCS8(i32* %10)
%17 = icmp eq i32* %16, null
br i1 %17, label %49, label %18
18: ; preds = %15
%19 = tail call i32 (...) @BIO_s_mem()
%20 = tail call i32* @BIO_new(i32 %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %49, label %22
22: ; preds = %18
%23 = icmp eq i8* %3, null
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = tail call i32 @PEM_write_bio_PKCS8_PRIV_KEY_INFO(i32* %20, i32* %16)
br label %33
26: ; preds = %22
%27 = tail call i32 (...) @EVP_aes_256_cbc()
%28 = tail call i32 @strlen(i8* %3)
%29 = tail call i32* @PKCS8_encrypt(i32 -1, i32 %27, i8* %3, i32 %28, i32* null, i32 0, i32 4096, i32* %16)
%30 = icmp eq i32* %29, null
br i1 %30, label %56, label %31
31: ; preds = %26
%32 = tail call i32 @PEM_write_bio_PKCS8(i32* %20, i32* %29)
br label %33
33: ; preds = %31, %24
%34 = phi i32* [ %29, %31 ], [ null, %24 ]
%35 = call i32 @BIO_get_mem_ptr(i32* %20, %struct.TYPE_3__** %5)
%36 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %36, i64 0, i32 0
%38 = load i32, i32* %37
%39 = icmp slt i32 %38, %1
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %36, i64 0, i32 1
%41 = load i32, i32* %40
%42 = add nsw i32 %1, -1
%43 = select i1 %39, i32 %38, i32 %42
%44 = call i32 @memcpy(i8* %0, i32 %41, i32 %43)
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %0, i64 %45
store i8 0, i8* %46
br label %56
47: ; preds = %9
%48 = tail call i32 @EC_KEY_free(i32* %7)
br label %66
49: ; preds = %18, %15, %12
%50 = phi i32* [ null, %12 ], [ null, %15 ], [ %16, %18 ]
%51 = tail call i32 @EC_KEY_free(i32* %7)
%52 = tail call i32 @EVP_PKEY_free(i32* %10)
%53 = icmp eq i32* %50, null
br i1 %53, label %66, label %54
54: ; preds = %49
%55 = tail call i32 @PKCS8_PRIV_KEY_INFO_free(i32* %50)
br label %66
56: ; preds = %33, %26
%57 = phi i32* [ null, %26 ], [ %34, %33 ]
%58 = phi i32 [ 0, %26 ], [ %38, %33 ]
%59 = call i32 @BIO_free(i32* %20)
%60 = call i32 @EC_KEY_free(i32* %7)
%61 = call i32 @EVP_PKEY_free(i32* %10)
%62 = call i32 @PKCS8_PRIV_KEY_INFO_free(i32* %16)
%63 = icmp eq i32* %57, null
br i1 %63, label %66, label %64
64: ; preds = %56
%65 = call i32 @X509_SIG_free(i32* %57)
br label %66
66: ; preds = %4, %47, %49, %54, %64, %56
%67 = phi i32 [ %58, %64 ], [ %58, %56 ], [ 0, %54 ], [ 0, %49 ], [ 0, %47 ], [ 0, %4 ]
ret i32 %67
}