#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*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ *BN_new();
int BN_set_word(int /*<<< orphan*/ *, unsigned long);
unsigned long RSA_3;
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *RSA_generate_key(int, unsigned long, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int RSA_generate_key_ex(int /*<<< orphan*/ *, int, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ *);
int /*<<< orphan*/ *RSA_new();
int /*<<< orphan*/ RSA_print_fp(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int main() {
  RSA *r;
  int bits = 512, ret;
  unsigned long e = RSA_3;
  BIGNUM *bne;
  r = RSA_generate_key(bits, e, NULL, NULL);
  RSA_print_fp(stdout, r, 11);
  RSA_free(r);
  bne = BN_new();
  ret = BN_set_word(bne, e);
  r = RSA_new();
  ret = RSA_generate_key_ex(r, bits, bne, NULL);
  if (ret != 1) {
    printf("RSA_generate_key_ex err!\n");
    return -1;
  }
  RSA_free(r);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x200,-0x14(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   10a0 <RSA_generate_key@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0xb,%edx
call   1090 <RSA_print_fp@plt>
mov    -0x10(%rbp),%rdi
call   1060 <RSA_free@plt>
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <BN_set_word@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <RSA_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <RSA_generate_key_ex@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     123a <main+0xba>
lea    0xdd7(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <main+0xca>
mov    -0x10(%rbp),%rdi
call   1060 <RSA_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e5c(%rip),%rax
mov    (%rax),%r15
xor    %r14d,%r14d
mov    $0x200,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10a0 <RSA_generate_key@plt>
mov    %rax,%rbx
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    $0xb,%edx
call   1090 <RSA_print_fp@plt>
mov    %rbx,%rdi
call   1070 <RSA_free@plt>
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <BN_set_word@plt>
xor    %eax,%eax
call   1080 <RSA_new@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1060 <RSA_generate_key_ex@plt>
cmp    $0x1,%eax
jne    1204 <main+0x84>
mov    %r15,%rdi
call   1070 <RSA_free@plt>
jmp    1216 <main+0x96>
lea    0xdf5(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RSA_3 = global i64 0
@stdout = global i32 0
@.str = [26 x i8] c"RSA_generate_key_ex err!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32*
store i32 0, i32* %1
store i32 512, i32* %3
%7 = load i64, i64* @RSA_3
store i64 %7, i64* %5
%8 = load i32, i32* %3
%9 = load i64, i64* %5
%10 = call i32* @RSA_generate_key(i32 %8, i64 %9, i32* null, i32* null)
store i32* %10, i32** %2
%11 = load i32, i32* @stdout
%12 = load i32*, i32** %2
%13 = call i32 @RSA_print_fp(i32 %11, i32* %12, i32 11)
%14 = load i32*, i32** %2
%15 = call i32 @RSA_free(i32* %14)
%16 = call i32* (...) @BN_new()
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = load i64, i64* %5
%19 = call i32 @BN_set_word(i32* %17, i64 %18)
store i32 %19, i32* %4
%20 = call i32* (...) @RSA_new()
store i32* %20, i32** %2
%21 = load i32*, i32** %2
%22 = load i32, i32* %3
%23 = load i32*, i32** %6
%24 = call i32 @RSA_generate_key_ex(i32* %21, i32 %22, i32* %23, i32* null)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %29
27: ; preds = %0
%28 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %32
29: ; preds = %0
%30 = load i32*, i32** %2
%31 = call i32 @RSA_free(i32* %30)
store i32 0, i32* %1
br label %32
32: ; preds = %29, %27
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@RSA_3 = global i64 0
@stdout = global i32 0
@str = [25 x i8] c"RSA_generate_key_ex err!\00"
define i32 @main() {
%1 = load i64, i64* @RSA_3
%2 = tail call i32* @RSA_generate_key(i32 512, i64 %1, i32* null, i32* null)
%3 = load i32, i32* @stdout
%4 = tail call i32 @RSA_print_fp(i32 %3, i32* %2, i32 11)
%5 = tail call i32 @RSA_free(i32* %2)
%6 = tail call i32* (...) @BN_new()
%7 = tail call i32 @BN_set_word(i32* %6, i64 %1)
%8 = tail call i32* (...) @RSA_new()
%9 = tail call i32 @RSA_generate_key_ex(i32* %8, i32 512, i32* %6, i32* null)
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = tail call i32 @RSA_free(i32* %8)
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %16
}