#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);
int /*<<< orphan*/ 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) {
    EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
  }
  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     1187 <get_optional_pkey_id+0x57>
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>
cmpq   $0x0,-0x18(%rbp)
je     119b <get_optional_pkey_id+0x6b>
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     1172 <get_optional_pkey_id+0x42>
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>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1181 <get_optional_pkey_id+0x51>
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 %13
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i32 @EVP_PKEY_asn1_get0_info(i32* %5, i32* null, i32* null, i32* null, i32* null, i32* %11)
br label %13
13: ; preds = %10, %1
%14 = load i32*, i32** %4
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32*, i32** %4
%18 = call i32 @ENGINE_finish(i32* %17)
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* %5
ret i32 %20
}

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 %10, label %8
8: ; preds = %1
%9 = call i32 @EVP_PKEY_asn1_get0_info(i32* %3, i32* null, i32* null, i32* null, i32* null, i32* %6)
br label %10
10: ; preds = %8, %1
%11 = load i32*, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @ENGINE_finish(i32* %11)
br label %15
15: ; preds = %13, %10
%16 = load i32, i32* %3
ret i32 %16
}