#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*/ SSL;
typedef int /*<<< orphan*/ RSA;
typedef int /*<<< orphan*/ EVP_PKEY;

/* Variables and functions */
int /*<<< orphan*/ ERR_LIB_SSL;
int /*<<< orphan*/ ERR_R_EVP_LIB;
int /*<<< orphan*/ ERR_R_PASSED_NULL_PARAMETER;
int /*<<< orphan*/ ERR_raise(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ EVP_PKEY_assign_RSA(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_new();
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ RSA_up_ref(int /*<<< orphan*/ *);
int SSL_use_PrivateKey(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa) {
  EVP_PKEY *pkey;
  int ret;
  if (rsa == NULL) {
    ERR_raise(ERR_LIB_SSL, ERR_R_PASSED_NULL_PARAMETER);
    return 0;
  }
  if ((pkey = EVP_PKEY_new()) == NULL) {
    ERR_raise(ERR_LIB_SSL, ERR_R_EVP_LIB);
    return 0;
  }
  RSA_up_ref(rsa);
  if (EVP_PKEY_assign_RSA(pkey, rsa) <= 0) {
    RSA_free(rsa);
    EVP_PKEY_free(pkey);
    return 0;
  }
  ret = SSL_use_PrivateKey(ssl, pkey);
  EVP_PKEY_free(pkey);
  return ret;
}


x86 assembly (clang, -O0):
<SSL_use_RSAPrivateKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ae <SSL_use_RSAPrivateKey+0x3e>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
call   1070 <ERR_raise@plt>
movl   $0x0,-0x4(%rbp)
jmp    1243 <SSL_use_RSAPrivateKey+0xd3>
mov    $0x0,%al
call   1060 <EVP_PKEY_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e6 <SSL_use_RSAPrivateKey+0x76>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
call   1070 <ERR_raise@plt>
movl   $0x0,-0x4(%rbp)
jmp    1243 <SSL_use_RSAPrivateKey+0xd3>
mov    -0x18(%rbp),%rdi
call   1090 <RSA_up_ref@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <EVP_PKEY_assign_RSA@plt>
cmp    $0x0,%rax
jg     1224 <SSL_use_RSAPrivateKey+0xb4>
mov    -0x18(%rbp),%rdi
call   1040 <RSA_free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1243 <SSL_use_RSAPrivateKey+0xd3>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <SSL_use_PrivateKey@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SSL_use_RSAPrivateKey>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     11c0 <SSL_use_RSAPrivateKey+0x50>
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <EVP_PKEY_new@plt>
test   %rax,%rax
je     11d2 <SSL_use_RSAPrivateKey+0x62>
mov    %rax,%r14
mov    %rbx,%rdi
call   1090 <RSA_up_ref@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <EVP_PKEY_assign_RSA@plt>
test   %rax,%rax
jle    11eb <SSL_use_RSAPrivateKey+0x7b>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <SSL_use_PrivateKey@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <EVP_PKEY_free@plt>
mov    %ebx,%eax
jmp    11fd <SSL_use_RSAPrivateKey+0x8d>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
jmp    11e2 <SSL_use_RSAPrivateKey+0x72>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
call   1070 <ERR_raise@plt>
jmp    11fb <SSL_use_RSAPrivateKey+0x8b>
mov    %rbx,%rdi
call   1040 <RSA_free@plt>
mov    %r14,%rdi
call   1050 <EVP_PKEY_free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ERR_LIB_SSL = global i32 0
@ERR_R_PASSED_NULL_PARAMETER = global i32 0
@ERR_R_EVP_LIB = global i32 0
define i32 @SSL_use_RSAPrivateKey(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @ERR_LIB_SSL
%12 = load i32, i32* @ERR_R_PASSED_NULL_PARAMETER
%13 = call i32 @ERR_raise(i32 %11, i32 %12)
store i32 0, i32* %3
br label %40
14: ; preds = %2
%15 = call i32* (...) @EVP_PKEY_new()
store i32* %15, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @ERR_LIB_SSL
%19 = load i32, i32* @ERR_R_EVP_LIB
%20 = call i32 @ERR_raise(i32 %18, i32 %19)
store i32 0, i32* %3
br label %40
21: ; preds = %14
%22 = load i32*, i32** %5
%23 = call i32 @RSA_up_ref(i32* %22)
%24 = load i32*, i32** %6
%25 = load i32*, i32** %5
%26 = call i64 @EVP_PKEY_assign_RSA(i32* %24, i32* %25)
%27 = icmp sle i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %21
%29 = load i32*, i32** %5
%30 = call i32 @RSA_free(i32* %29)
%31 = load i32*, i32** %6
%32 = call i32 @EVP_PKEY_free(i32* %31)
store i32 0, i32* %3
br label %40
33: ; preds = %21
%34 = load i32*, i32** %4
%35 = load i32*, i32** %6
%36 = call i32 @SSL_use_PrivateKey(i32* %34, i32* %35)
store i32 %36, i32* %7
%37 = load i32*, i32** %6
%38 = call i32 @EVP_PKEY_free(i32* %37)
%39 = load i32, i32* %7
store i32 %39, i32* %3
br label %40
40: ; preds = %33, %28, %17, %10
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@ERR_LIB_SSL = global i32 0
@ERR_R_PASSED_NULL_PARAMETER = global i32 0
@ERR_R_EVP_LIB = global i32 0
define i32 @SSL_use_RSAPrivateKey(i32* %0, i32* %1) {
%3 = icmp eq i32* %1, null
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @ERR_LIB_SSL
%6 = load i32, i32* @ERR_R_PASSED_NULL_PARAMETER
%7 = tail call i32 @ERR_raise(i32 %5, i32 %6)
br label %25
8: ; preds = %2
%9 = tail call i32* (...) @EVP_PKEY_new()
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @ERR_LIB_SSL
%13 = load i32, i32* @ERR_R_EVP_LIB
%14 = tail call i32 @ERR_raise(i32 %12, i32 %13)
br label %25
15: ; preds = %8
%16 = tail call i32 @RSA_up_ref(i32* %1)
%17 = tail call i64 @EVP_PKEY_assign_RSA(i32* %9, i32* %1)
%18 = icmp slt i64 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = tail call i32 @RSA_free(i32* %1)
%21 = tail call i32 @EVP_PKEY_free(i32* %9)
br label %25
22: ; preds = %15
%23 = tail call i32 @SSL_use_PrivateKey(i32* %0, i32* %9)
%24 = tail call i32 @EVP_PKEY_free(i32* %9)
br label %25
25: ; preds = %22, %19, %11, %4
%26 = phi i32 [ 0, %4 ], [ 0, %11 ], [ 0, %19 ], [ %23, %22 ]
ret i32 %26
}