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

/* Variables and functions */
int EVP_MD_size(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *EVP_get_digestbynid(int);
int NID_undef;
scalar_t__ OBJ_find_sigid_algs(int, int *, int /*<<< orphan*/ *);
int X509_get_signature_nid(int /*<<< orphan*/ *);
int ssl_ctx_security(int /*<<< orphan*/ *, int, int, int, int /*<<< orphan*/ *);
int ssl_security(int /*<<< orphan*/ *, int, int, int, int /*<<< orphan*/ *);
int ssl_security_cert_sig(SSL *s, SSL_CTX *ctx, X509 *x, int op) {
  int secbits = -1, md_nid = NID_undef, sig_nid;
  sig_nid = X509_get_signature_nid(x);
  if (sig_nid && OBJ_find_sigid_algs(sig_nid, &md_nid, NULL)) {
    const EVP_MD *md;
    if (md_nid && (md = EVP_get_digestbynid(md_nid)))
      secbits = EVP_MD_size(md) * 4;
  }
  if (s)
    return ssl_security(s, op, secbits, md_nid, x);
  else
    return ssl_ctx_security(ctx, op, secbits, md_nid, x);
}


x86 assembly (clang, -O0):
<ssl_security_cert_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <X509_get_signature_nid@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11ee <ssl_security_cert_sig+0x8e>
mov    -0x30(%rbp),%edi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <OBJ_find_sigid_algs@plt>
cmp    $0x0,%rax
je     11ee <ssl_security_cert_sig+0x8e>
cmpl   $0x0,-0x2c(%rbp)
je     11e9 <ssl_security_cert_sig+0x89>
mov    -0x2c(%rbp),%edi
call   1050 <EVP_get_digestbynid@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11e9 <ssl_security_cert_sig+0x89>
mov    -0x38(%rbp),%rdi
call   1030 <EVP_MD_size@plt>
shl    $0x2,%eax
mov    %eax,-0x28(%rbp)
jmp    11ee <ssl_security_cert_sig+0x8e>
cmpq   $0x0,-0x10(%rbp)
je     1217 <ssl_security_cert_sig+0xb7>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%r8
call   1070 <ssl_security@plt>
mov    %eax,-0x4(%rbp)
jmp    1230 <ssl_security_cert_sig+0xd0>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%r8
call   1080 <ssl_ctx_security@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_security_cert_sig>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %rdx,%rdi
call   1060 <X509_get_signature_nid@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
je     11c8 <ssl_security_cert_sig+0x68>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1040 <OBJ_find_sigid_algs@plt>
test   %rax,%rax
je     11c8 <ssl_security_cert_sig+0x68>
mov    0xc(%rsp),%edi
test   %edi,%edi
je     11c8 <ssl_security_cert_sig+0x68>
call   1050 <EVP_get_digestbynid@plt>
test   %rax,%rax
je     11c8 <ssl_security_cert_sig+0x68>
mov    %rax,%rdi
call   1030 <EVP_MD_size@plt>
mov    %eax,%ebp
shl    $0x2,%ebp
mov    0xc(%rsp),%ecx
test   %r12,%r12
je     11e3 <ssl_security_cert_sig+0x83>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %rbx,%r8
call   1070 <ssl_security@plt>
jmp    11f3 <ssl_security_cert_sig+0x93>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %rbx,%r8
call   1080 <ssl_ctx_security@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NID_undef = global i32 0
define i32 @ssl_security_cert_sig(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
%12 = alloca i32
%13 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 -1, i32* %10
%14 = load i32, i32* @NID_undef
store i32 %14, i32* %11
%15 = load i32*, i32** %8
%16 = call i32 @X509_get_signature_nid(i32* %15)
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %4
%20 = load i32, i32* %12
%21 = call i64 @OBJ_find_sigid_algs(i32 %20, i32* %11, i32* null)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load i32, i32* %11
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i32, i32* %11
%28 = call i32* @EVP_get_digestbynid(i32 %27)
store i32* %28, i32** %13
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32*, i32** %13
%32 = call i32 @EVP_MD_size(i32* %31)
%33 = mul nsw i32 %32, 4
store i32 %33, i32* %10
br label %34
34: ; preds = %30, %26, %23
br label %35
35: ; preds = %34, %19, %4
%36 = load i32*, i32** %6
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = load i32*, i32** %6
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = load i32, i32* %11
%43 = load i32*, i32** %8
%44 = call i32 @ssl_security(i32* %39, i32 %40, i32 %41, i32 %42, i32* %43)
store i32 %44, i32* %5
br label %52
45: ; preds = %35
%46 = load i32*, i32** %7
%47 = load i32, i32* %9
%48 = load i32, i32* %10
%49 = load i32, i32* %11
%50 = load i32*, i32** %8
%51 = call i32 @ssl_ctx_security(i32* %46, i32 %47, i32 %48, i32 %49, i32* %50)
store i32 %51, i32* %5
br label %52
52: ; preds = %45, %38
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
@NID_undef = global i32 0
define i32 @ssl_security_cert_sig(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* @NID_undef
store i32 %7, i32* %5
%8 = tail call i32 @X509_get_signature_nid(i32* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %4
%11 = call i64 @OBJ_find_sigid_algs(i32 %8, i32* %5, i32* null)
%12 = icmp eq i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %10
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = call i32* @EVP_get_digestbynid(i32 %14)
%18 = icmp eq i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i32 @EVP_MD_size(i32* %17)
%21 = shl nsw i32 %20, 2
br label %22
22: ; preds = %13, %16, %19, %10, %4
%23 = phi i32 [ -1, %10 ], [ -1, %4 ], [ %21, %19 ], [ -1, %16 ], [ -1, %13 ]
%24 = icmp eq i32* %0, null
%25 = load i32, i32* %5
br i1 %24, label %28, label %26
26: ; preds = %22
%27 = call i32 @ssl_security(i32* %0, i32 %3, i32 %23, i32 %25, i32* %2)
br label %30
28: ; preds = %22
%29 = call i32 @ssl_ctx_security(i32* %1, i32 %3, i32 %23, i32 %25, i32* %2)
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %27, %26 ], [ %29, %28 ]
ret i32 %31
}