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

/* Variables and functions */
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int EVP_PKEY_security_bits(int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_get_pubkey(int /*<<< orphan*/ *);
int ssl_ctx_security(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/,
                     int /*<<< orphan*/ *);
int ssl_security(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/,
                 int /*<<< orphan*/ *);
int ssl_security_cert_key(SSL *s, SSL_CTX *ctx, X509 *x, int op) {
  int secbits;
  EVP_PKEY *pkey = X509_get_pubkey(x);
  if (pkey) {
    secbits = EVP_PKEY_security_bits(pkey);
    EVP_PKEY_free(pkey);
  } else
    secbits = -1;
  if (s)
    return ssl_security(s, op, secbits, 0, x);
  else
    return ssl_ctx_security(ctx, op, secbits, 0, x);
}


x86 assembly (clang, -O0):
<ssl_security_cert_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <X509_get_pubkey@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1199 <ssl_security_cert_key+0x49>
mov    -0x30(%rbp),%rdi
call   1030 <EVP_PKEY_security_bits@plt>
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <EVP_PKEY_free@plt>
jmp    11a0 <ssl_security_cert_key+0x50>
movl   $0xffffffff,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c8 <ssl_security_cert_key+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%r8
xor    %ecx,%ecx
call   1060 <ssl_security@plt>
mov    %eax,-0x4(%rbp)
jmp    11e0 <ssl_security_cert_key+0x90>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%r8
xor    %ecx,%ecx
call   1070 <ssl_ctx_security@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_security_cert_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1050 <X509_get_pubkey@plt>
test   %rax,%rax
je     11b0 <ssl_security_cert_key+0x60>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <EVP_PKEY_security_bits@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1040 <EVP_PKEY_free@plt>
test   %rbp,%rbp
je     11bb <ssl_security_cert_key+0x6b>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
xor    %ecx,%ecx
mov    %r13,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <ssl_security@plt>
mov    $0xffffffff,%r12d
test   %rbp,%rbp
jne    118f <ssl_security_cert_key+0x3f>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
xor    %ecx,%ecx
mov    %r13,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <ssl_ctx_security@plt>

LLVM IR (-O0):
define i32 @ssl_security_cert_key(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%12 = load i32*, i32** %8
%13 = call i32* @X509_get_pubkey(i32* %12)
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = load i32*, i32** %11
%18 = call i32 @EVP_PKEY_security_bits(i32* %17)
store i32 %18, i32* %10
%19 = load i32*, i32** %11
%20 = call i32 @EVP_PKEY_free(i32* %19)
br label %22
21: ; preds = %4
store i32 -1, i32* %10
br label %22
22: ; preds = %21, %16
%23 = load i32*, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32*, i32** %6
%27 = load i32, i32* %9
%28 = load i32, i32* %10
%29 = load i32*, i32** %8
%30 = call i32 @ssl_security(i32* %26, i32 %27, i32 %28, i32 0, i32* %29)
store i32 %30, i32* %5
br label %37
31: ; preds = %22
%32 = load i32*, i32** %7
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = load i32*, i32** %8
%36 = call i32 @ssl_ctx_security(i32* %32, i32 %33, i32 %34, i32 0, i32* %35)
store i32 %36, i32* %5
br label %37
37: ; preds = %31, %25
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
define i32 @ssl_security_cert_key(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = tail call i32* @X509_get_pubkey(i32* %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @EVP_PKEY_security_bits(i32* %5)
%9 = tail call i32 @EVP_PKEY_free(i32* %5)
br label %10
10: ; preds = %4, %7
%11 = phi i32 [ %8, %7 ], [ -1, %4 ]
%12 = icmp eq i32* %0, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @ssl_security(i32* %0, i32 %3, i32 %11, i32 0, i32* %2)
br label %17
15: ; preds = %10
%16 = tail call i32 @ssl_ctx_security(i32* %1, i32 %3, i32 %11, i32 0, i32* %2)
br label %17
17: ; preds = %15, %13
%18 = phi i32 [ %14, %13 ], [ %16, %15 ]
ret i32 %18
}