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

/* Variables and functions */
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
scalar_t__ BIO_read(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ BN_set_word(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ EVP_aes_128_cbc();
int PEM_write_RSAPrivateKey(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                            int /*<<< orphan*/, int /*<<< orphan*/ *,
                            int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/ *);
int PEM_write_RSA_PUBKEY(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
scalar_t__ RSA_generate_key_ex(int /*<<< orphan*/ *, int, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ *RSA_new();
int /*<<< orphan*/ RSA_print(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int genkey(int keyLength, const char *privKey, const char *pubKey) {
  int result = 0;
  unsigned char buffer[1024];
  RSA *rsa = NULL;
  BIO *bio = NULL;
  BIGNUM *bigNum = NULL;
  FILE *privKeyFile;
  FILE *pubKeyFile;
  if ((privKeyFile = fopen(privKey, "wb")) == NULL) {
    printf("Open file error occurred\n");
    exit(1);
  }
  if ((pubKeyFile = fopen(pubKey, "wb")) == NULL) {
    printf("Open file error occurred\n");
    exit(1);
  }
  printf("Starting generating RSA key pair...\n");
  rsa = RSA_new();
  if (rsa == NULL) {
    printf("Error during generation of RSA structure!\n");
    exit(1);
  }
  bigNum = BN_new();
  BN_set_word(bigNum, 17);
  if (RSA_generate_key_ex(rsa, keyLength, bigNum, NULL) == 0) {
    printf("Error during generation of RSA key pair!\n");
    RSA_free(rsa);
    exit(1);
  }
  printf("Key pair generated successfully!\n");
  bio = BIO_new(BIO_s_mem());
  RSA_print(bio, rsa, 4);
  memset(buffer, 0, 1024);
  while (BIO_read(bio, buffer, 1024) > 0) {
    printf("%s", buffer);
    memset(buffer, 0, 1024);
  }
  printf("Writing keys to files...\n");
  result = PEM_write_RSA_PUBKEY(pubKeyFile, rsa);
  if (result == 0) {
    printf("Error occured when trying to store public key!\n");
  }
  result = PEM_write_RSAPrivateKey(privKeyFile, rsa, EVP_aes_128_cbc(), NULL, 0,
                                   0, NULL);
  if (result == 0) {
    printf("Error occured when trying to store private key!\n");
  }
  RSA_free(rsa);
  BN_free(bigNum);
  fclose(privKeyFile);
  fclose(pubKeyFile);
  return result;
}


x86 assembly (clang, -O0):
<genkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x428(%rbp)
movq   $0x0,-0x430(%rbp)
movq   $0x0,-0x438(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x440(%rbp)
cmp    $0x0,%rax
jne    1297 <genkey+0x77>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xd5e(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x448(%rbp)
cmp    $0x0,%rax
jne    12d0 <genkey+0xb0>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    $0x0,%al
call   1100 <RSA_new@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1312 <genkey+0xf2>
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    $0x0,%al
call   1060 <BN_new@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rdi
mov    $0x11,%esi
call   1050 <BN_set_word@plt>
mov    -0x428(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x438(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <RSA_generate_key_ex@plt>
cmp    $0x0,%rax
jne    1379 <genkey+0x159>
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    -0x428(%rbp),%rdi
call   10b0 <RSA_free@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    $0x0,%al
call   1140 <BIO_s_mem@plt>
mov    %eax,%edi
call   10f0 <BIO_new@plt>
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rdi
mov    -0x428(%rbp),%rsi
mov    $0x4,%edx
call   1040 <RSA_print@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10d0 <memset@plt>
mov    -0x430(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <BIO_read@plt>
cmp    $0x0,%rax
jle    1416 <genkey+0x1f6>
lea    -0x420(%rbp),%rsi
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10d0 <memset@plt>
jmp    13c7 <genkey+0x1a7>
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    -0x448(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1030 <PEM_write_RSA_PUBKEY@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1452 <genkey+0x232>
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    -0x440(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    $0x0,%al
call   1110 <EVP_aes_128_cbc@plt>
mov    -0x458(%rbp),%rdi
mov    -0x450(%rbp),%rsi
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
movq   $0x0,(%rsp)
call   1080 <PEM_write_RSAPrivateKey@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    14b7 <genkey+0x297>
lea    0xc56(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    -0x428(%rbp),%rdi
call   10b0 <RSA_free@plt>
mov    -0x438(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x440(%rbp),%rdi
call   1090 <fclose@plt>
mov    -0x448(%rbp),%rdi
call   1090 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genkey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,%rbx
mov    %rsi,%rax
mov    %edi,%r14d
lea    0xdaf(%rip),%rsi
mov    %rax,%rdi
call   1130 <fopen@plt>
test   %rax,%rax
je     1407 <genkey+0x1d7>
mov    %rax,%rbp
lea    0xd94(%rip),%rsi
mov    %rbx,%rdi
call   1130 <fopen@plt>
test   %rax,%rax
je     1407 <genkey+0x1d7>
mov    %rax,%r15
lea    0xd7f(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1110 <RSA_new@plt>
test   %rax,%rax
je     1410 <genkey+0x1e0>
mov    %rax,%r13
mov    %rbp,0x8(%rsp)
xor    %eax,%eax
call   1070 <BN_new@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x11,%esi
call   1050 <BN_set_word@plt>
mov    %r13,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1080 <RSA_generate_key_ex@plt>
test   %rax,%rax
je     1426 <genkey+0x1f6>
lea    0xd4f(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1150 <BIO_s_mem@plt>
mov    %eax,%edi
call   1100 <BIO_new@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <RSA_print@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10e0 <memset@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   10b0 <BIO_read@plt>
test   %rax,%rax
jle    1371 <genkey+0x141>
lea    0xcd2(%rip),%rbx
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10d0 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10e0 <memset@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   10b0 <BIO_read@plt>
test   %rax,%rax
jg     1340 <genkey+0x110>
lea    0xcd3(%rip),%rdi
call   1060 <puts@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <PEM_write_RSA_PUBKEY@plt>
test   %eax,%eax
jne    1398 <genkey+0x168>
lea    0xd01(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1120 <EVP_aes_128_cbc@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <PEM_write_RSAPrivateKey@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    13d3 <genkey+0x1a3>
lea    0xc96(%rip),%rdi
call   1060 <puts@plt>
mov    %r13,%rdi
call   10c0 <RSA_free@plt>
mov    %r12,%rdi
call   10f0 <BN_free@plt>
mov    %rbx,%rdi
call   10a0 <fclose@plt>
mov    %r15,%rdi
call   10a0 <fclose@plt>
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd08(%rip),%rdi
jmp    1417 <genkey+0x1e7>
lea    0xcd5(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
lea    0xc96(%rip),%rdi
call   1060 <puts@plt>
mov    %r13,%rdi
call   10c0 <RSA_free@plt>
mov    $0x1,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [26 x i8] c"Open file error occurred\0A\00"
@.str.2 = [37 x i8] c"Starting generating RSA key pair...\0A\00"
@.str.3 = [43 x i8] c"Error during generation of RSA structure!\0A\00"
@.str.4 = [42 x i8] c"Error during generation of RSA key pair!\0A\00"
@.str.5 = [34 x i8] c"Key pair generated successfully!\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [26 x i8] c"Writing keys to files...\0A\00"
@.str.8 = [48 x i8] c"Error occured when trying to store public key!\0A\00"
@.str.9 = [49 x i8] c"Error occured when trying to store private key!\0A\00"
define i32 @genkey(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
store i32* null, i32** %9
store i32* null, i32** %10
store i32* null, i32** %11
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %12
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %3
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %13
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32* (...) @RSA_new()
store i32* %29, i32** %9
%30 = load i32*, i32** %9
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
%36 = call i32* (...) @BN_new()
store i32* %36, i32** %11
%37 = load i32*, i32** %11
%38 = call i32 @BN_set_word(i32* %37, i32 17)
%39 = load i32*, i32** %9
%40 = load i32, i32* %4
%41 = load i32*, i32** %11
%42 = call i64 @RSA_generate_key_ex(i32* %39, i32 %40, i32* %41, i32* null)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %35
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32*, i32** %9
%47 = call i32 @RSA_free(i32* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %35
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 (...) @BIO_s_mem()
%52 = call i32* @BIO_new(i32 %51)
store i32* %52, i32** %10
%53 = load i32*, i32** %10
%54 = load i32*, i32** %9
%55 = call i32 @RSA_print(i32* %53, i32* %54, i32 4)
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%57 = call i32 @memset(i8* %56, i32 0, i32 1024)
br label %58
58: ; preds = %63, %49
%59 = load i32*, i32** %10
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%61 = call i64 @BIO_read(i32* %59, i8* %60, i32 1024)
%62 = icmp sgt i64 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %58
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %64)
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%67 = call i32 @memset(i8* %66, i32 0, i32 1024)
br label %58
68: ; preds = %58
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%70 = load i32*, i32** %13
%71 = load i32*, i32** %9
%72 = call i32 @PEM_write_RSA_PUBKEY(i32* %70, i32* %71)
store i32 %72, i32* %7
%73 = load i32, i32* %7
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %68
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0))
br label %77
77: ; preds = %75, %68
%78 = load i32*, i32** %12
%79 = load i32*, i32** %9
%80 = call i32 (...) @EVP_aes_128_cbc()
%81 = call i32 @PEM_write_RSAPrivateKey(i32* %78, i32* %79, i32 %80, i32* null, i32 0, i32 0, i32* null)
store i32 %81, i32* %7
%82 = load i32, i32* %7
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %77
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0))
br label %86
86: ; preds = %84, %77
%87 = load i32*, i32** %9
%88 = call i32 @RSA_free(i32* %87)
%89 = load i32*, i32** %11
%90 = call i32 @BN_free(i32* %89)
%91 = load i32*, i32** %12
%92 = call i32 @fclose(i32* %91)
%93 = load i32*, i32** %13
%94 = call i32 @fclose(i32* %93)
%95 = load i32, i32* %7
ret i32 %95
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.6 = [3 x i8] c"%s\00"
@str = [36 x i8] c"Starting generating RSA key pair...\00"
@str.10 = [33 x i8] c"Key pair generated successfully!\00"
@str.11 = [25 x i8] c"Writing keys to files...\00"
@str.12 = [48 x i8] c"Error occured when trying to store private key!\00"
@str.13 = [47 x i8] c"Error occured when trying to store public key!\00"
@str.14 = [41 x i8] c"Error during generation of RSA key pair!\00"
@str.15 = [42 x i8] c"Error during generation of RSA structure!\00"
@str.17 = [25 x i8] c"Open file error occurred\00"
define i32 @genkey(i32 %0, i8* nocapture %1, i8* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.17, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.17, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%19 = tail call i32* (...) @RSA_new()
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.15, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = tail call i32* (...) @BN_new()
%26 = tail call i32 @BN_set_word(i32* %25, i32 17)
%27 = tail call i64 @RSA_generate_key_ex(i32* %19, i32 %0, i32* %25, i32* null)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.14, i64 0, i64 0))
%31 = tail call i32 @RSA_free(i32* %19)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.10, i64 0, i64 0))
%35 = tail call i32 (...) @BIO_s_mem()
%36 = tail call i32* @BIO_new(i32 %35)
%37 = tail call i32 @RSA_print(i32* %36, i32* %19, i32 4)
%38 = call i32 @memset(i8* %5, i32 0, i32 1024)
%39 = call i64 @BIO_read(i32* %36, i8* %5, i32 1024)
%40 = icmp sgt i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %33, %41
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%43 = call i32 @memset(i8* %5, i32 0, i32 1024)
%44 = call i64 @BIO_read(i32* %36, i8* %5, i32 1024)
%45 = icmp sgt i64 %44, 0
br i1 %45, label %41, label %46
46: ; preds = %41, %33
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
%48 = call i32 @PEM_write_RSA_PUBKEY(i32* %12, i32* %19)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.13, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = call i32 (...) @EVP_aes_128_cbc()
%54 = call i32 @PEM_write_RSAPrivateKey(i32* %6, i32* %19, i32 %53, i32* null, i32 0, i32 0, i32* null)
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.12, i64 0, i64 0))
br label %58
58: ; preds = %56, %52
%59 = call i32 @RSA_free(i32* %19)
%60 = call i32 @BN_free(i32* %25)
%61 = call i32 @fclose(i32* %6)
%62 = call i32 @fclose(i32* %12)
ret i32 %54
}