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

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ EVP_PKEY_assign_RSA(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_new();
int /*<<< orphan*/ RSA_F4;
int /*<<< orphan*/ *RSA_generate_key(int, int /*<<< orphan*/,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
EVP_PKEY *abac_generate_key() {
  EVP_PKEY *pk = NULL;
  int keysize = 2048;
  if ((pk = EVP_PKEY_new()) == NULL) {
    ERR_print_errors_fp(stderr);
    return NULL;
  }
  RSA *rsa = RSA_generate_key(keysize, RSA_F4, NULL, NULL);
  if (!EVP_PKEY_assign_RSA(pk, rsa)) {
    ERR_print_errors_fp(stderr);
    return NULL;
  }
  rsa = NULL;
  return pk;
}


x86 assembly (clang, -O0):
<abac_generate_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x800,-0x14(%rbp)
mov    $0x0,%al
call   1040 <EVP_PKEY_new@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1187 <abac_generate_key+0x47>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1050 <ERR_print_errors_fp@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <abac_generate_key+0xa4>
mov    -0x14(%rbp),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1060 <RSA_generate_key@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <EVP_PKEY_assign_RSA@plt>
cmp    $0x0,%eax
jne    11d4 <abac_generate_key+0x94>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1050 <ERR_print_errors_fp@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <abac_generate_key+0xa4>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abac_generate_key>:
push   %rbx
xor    %eax,%eax
call   1040 <EVP_PKEY_new@plt>
test   %rax,%rax
je     1176 <abac_generate_key+0x36>
mov    %rax,%rbx
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    $0x800,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <RSA_generate_key@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <EVP_PKEY_assign_RSA@plt>
test   %eax,%eax
jne    1186 <abac_generate_key+0x46>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1050 <ERR_print_errors_fp@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@RSA_F4 = global i32 0
define i32* @abac_generate_key() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32*
store i32* null, i32** %2
store i32 2048, i32* %3
%5 = call i32* (...) @EVP_PKEY_new()
store i32* %5, 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* null, i32** %1
br label %23
10: ; preds = %0
%11 = load i32, i32* %3
%12 = load i32, i32* @RSA_F4
%13 = call i32* @RSA_generate_key(i32 %11, i32 %12, i32* null, i32* null)
store i32* %13, i32** %4
%14 = load i32*, i32** %2
%15 = load i32*, i32** %4
%16 = call i32 @EVP_PKEY_assign_RSA(i32* %14, i32* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = call i32 @ERR_print_errors_fp(i32 %19)
store i32* null, i32** %1
br label %23
21: ; preds = %10
store i32* null, i32** %4
%22 = load i32*, i32** %2
store i32* %22, i32** %1
br label %23
23: ; preds = %21, %18, %7
%24 = load i32*, i32** %1
ret i32* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@RSA_F4 = global i32 0
define i32* @abac_generate_key() {
%1 = tail call i32* (...) @EVP_PKEY_new()
%2 = icmp eq i32* %1, null
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = load i32, i32* @RSA_F4
%5 = tail call i32* @RSA_generate_key(i32 2048, i32 %4, i32* null, i32* null)
%6 = tail call i32 @EVP_PKEY_assign_RSA(i32* %1, i32* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %3, %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @ERR_print_errors_fp(i32 %9)
br label %11
11: ; preds = %8, %3
%12 = phi i32* [ %1, %3 ], [ null, %8 ]
ret i32* %12
}