#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*/ EVP_PKEY_ASN1_METHOD;
typedef int /*<<< orphan*/ ENGINE;

/* Variables and functions */
int /*<<< orphan*/ ENGINE_finish(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_asn1_find_str(int /*<<< orphan*/ **, char const *,
                                           int);
scalar_t__ EVP_PKEY_asn1_get0_info(int *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ const *);
int get_optional_pkey_id(const char *pkey_name) {
  const EVP_PKEY_ASN1_METHOD *ameth;
  ENGINE *tmpeng = NULL;
  int pkey_id = 0;
  ameth = EVP_PKEY_asn1_find_str(&tmpeng, pkey_name, -1);
  if (ameth) {
    if (EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth) <= 0)
      pkey_id = 0;
  }
  if (tmpeng)
    ENGINE_finish(tmpeng);
  return pkey_id;
}


x86 assembly (clang, -O0):
<get_optional_pkey_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdi
mov    $0xffffffff,%edx
call   1030 <EVP_PKEY_asn1_find_str@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119d <get_optional_pkey_id+0x6d>
mov    -0x10(%rbp),%r9
lea    -0x1c(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rsi
mov    %r8,%rdx
mov    %r8,%rcx
call   1040 <EVP_PKEY_asn1_get0_info@plt>
cmp    $0x0,%rax
jg     1198 <get_optional_pkey_id+0x68>
movl   $0x0,-0x1c(%rbp)
jmp    119d <get_optional_pkey_id+0x6d>
cmpq   $0x0,-0x18(%rbp)
je     11b1 <get_optional_pkey_id+0x81>
mov    -0x18(%rbp),%rdi
call   1050 <ENGINE_finish@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_optional_pkey_id>:
sub    $0x18,%rsp
mov    %rdi,%rsi
movq   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rdi
mov    $0xffffffff,%edx
call   1030 <EVP_PKEY_asn1_find_str@plt>
test   %rax,%rax
je     117f <get_optional_pkey_id+0x4f>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rax,%r9
call   1040 <EVP_PKEY_asn1_get0_info@plt>
test   %rax,%rax
jg     117f <get_optional_pkey_id+0x4f>
movl   $0x0,0xc(%rsp)
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     118e <get_optional_pkey_id+0x5e>
call   1050 <ENGINE_finish@plt>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @get_optional_pkey_id(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %2
store i32* null, i32** %4
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i32* @EVP_PKEY_asn1_find_str(i32** %4, i8* %6, i32 -1)
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i64 @EVP_PKEY_asn1_get0_info(i32* %5, i32* null, i32* null, i32* null, i32* null, i32* %11)
%13 = icmp sle i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 0, i32* %5
br label %15
15: ; preds = %14, %10
br label %16
16: ; preds = %15, %1
%17 = load i32*, i32** %4
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32*, i32** %4
%21 = call i32 @ENGINE_finish(i32* %20)
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %5
ret i32 %23
}

LLVM IR (-O2):
define i32 @get_optional_pkey_id(i8* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = bitcast i32** %2 to i8*
store i32* null, i32** %2
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = call i32* @EVP_PKEY_asn1_find_str(i32** %2, i8* %0, i32 -1)
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = call i64 @EVP_PKEY_asn1_get0_info(i32* %3, i32* null, i32* null, i32* null, i32* null, i32* %6)
%10 = icmp slt i64 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 0, i32* %3
br label %12
12: ; preds = %8, %11, %1
%13 = load i32*, i32** %2
%14 = icmp eq i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @ENGINE_finish(i32* %13)
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* %3
ret i32 %18
}