#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;

/* Variables and functions */
int /*<<< orphan*/ ERR_free_strings();
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *RSA_generate_key(int, int, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ RSA_print_fp(int /*<<< orphan*/, int /*<<< orphan*/ *,
                                int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(void) {
  RSA *rsa;
  ERR_load_crypto_strings();
  rsa = RSA_generate_key(2048, 17, NULL, NULL);
  if (rsa == NULL) {
    ERR_print_errors_fp(stderr);
    return 1;
  }
  if (!RSA_print_fp(stdout, rsa, 0))
    fprintf(stderr, "Couldn't print key!\n");
  RSA_free(rsa);
  ERR_free_strings();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <ERR_load_crypto_strings@plt>
mov    $0x800,%edi
mov    $0x11,%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1090 <RSA_generate_key@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c5 <main+0x55>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1080 <ERR_print_errors_fp@plt>
movl   $0x1,-0x4(%rbp)
jmp    120e <main+0x9e>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1060 <RSA_print_fp@plt>
cmp    $0x0,%eax
jne    11f7 <main+0x87>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <RSA_free@plt>
mov    $0x0,%al
call   1050 <ERR_free_strings@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <ERR_load_crypto_strings@plt>
mov    $0x800,%edi
mov    $0x11,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <RSA_generate_key@plt>
test   %rax,%rax
je     11d4 <main+0x64>
mov    %rax,%rbx
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <RSA_print_fp@plt>
test   %eax,%eax
jne    11c3 <main+0x53>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <RSA_free@plt>
xor    %eax,%eax
call   1050 <ERR_free_strings@plt>
jmp    11e7 <main+0x77>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1080 <ERR_print_errors_fp@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@stdout = global i32 0
@.str = [21 x i8] c"Couldn't print key!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32 (...) @ERR_load_crypto_strings()
%4 = call i32* @RSA_generate_key(i32 2048, i32 17, i32* null, i32* null)
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @ERR_print_errors_fp(i32 %8)
store i32 1, i32* %1
br label %22
10: ; preds = %0
%11 = load i32, i32* @stdout
%12 = load i32*, i32** %2
%13 = call i32 @RSA_print_fp(i32 %11, i32* %12, i32 0)
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %10
%19 = load i32*, i32** %2
%20 = call i32 @RSA_free(i32* %19)
%21 = call i32 (...) @ERR_free_strings()
store i32 0, i32* %1
br label %22
22: ; preds = %18, %7
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@stdout = global i32 0
@.str = [21 x i8] c"Couldn't print key!\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @ERR_load_crypto_strings()
%2 = tail call i32* @RSA_generate_key(i32 2048, i32 17, i32* null, i32* null)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @ERR_print_errors_fp(i32 %5)
br label %17
7: ; preds = %0
%8 = load i32, i32* @stdout
%9 = tail call i32 @RSA_print_fp(i32 %8, i32* %2, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %7
%15 = tail call i32 @RSA_free(i32* %2)
%16 = tail call i32 (...) @ERR_free_strings()
br label %17
17: ; preds = %14, %4
%18 = phi i32 [ 1, %4 ], [ 0, %14 ]
ret i32 %18
}