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

/* Variables and functions */
int /*<<< orphan*/ ERR_R_RSA_LIB;
int /*<<< orphan*/ EVP_PKEY_assign_RSA(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ RSA_F_RSA_PUB_DECODE;
int /*<<< orphan*/ RSAerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ X509_PUBKEY_get0_param(int /*<<< orphan*/ *,
                                          unsigned char const **, int *,
                                          int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ *d2i_RSAPublicKey(int /*<<< orphan*/ *,
                                     unsigned char const **, int);
int rsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) {
  const unsigned char *p;
  int pklen;
  RSA *rsa = NULL;
  if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, NULL, pubkey))
    return 0;
  if (!(rsa = d2i_RSAPublicKey(NULL, &p, pklen))) {
    RSAerr(RSA_F_RSA_PUB_DECODE, ERR_R_RSA_LIB);
    return 0;
  }
  EVP_PKEY_assign_RSA(pkey, rsa);
  return 1;
}


x86 assembly (clang, -O0):
<rsa_pub_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
mov    %rcx,%rdi
call   1050 <X509_PUBKEY_get0_param@plt>
cmp    $0x0,%eax
jne    1185 <rsa_pub_decode+0x45>
movl   $0x0,-0x4(%rbp)
jmp    11da <rsa_pub_decode+0x9a>
mov    -0x24(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1040 <d2i_RSAPublicKey@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11c6 <rsa_pub_decode+0x86>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
call   1060 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    11da <rsa_pub_decode+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <EVP_PKEY_assign_RSA@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_pub_decode>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r8
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %edi,%edi
xor    %ecx,%ecx
call   1050 <X509_PUBKEY_get0_param@plt>
test   %eax,%eax
je     11a6 <rsa_pub_decode+0x66>
mov    0xc(%rsp),%edx
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
xor    %edi,%edi
call   1040 <d2i_RSAPublicKey@plt>
test   %rax,%rax
je     118f <rsa_pub_decode+0x4f>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <EVP_PKEY_assign_RSA@plt>
mov    $0x1,%ebx
jmp    11a6 <rsa_pub_decode+0x66>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1060 <RSAerr@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RSA_F_RSA_PUB_DECODE = global i32 0
@ERR_R_RSA_LIB = global i32 0
define i32 @rsa_pub_decode(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32* null, i32** %8
%9 = load i32*, i32** %5
%10 = call i32 @X509_PUBKEY_get0_param(i32* null, i8** %6, i32* %7, i32* null, i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %25
13: ; preds = %2
%14 = load i32, i32* %7
%15 = call i32* @d2i_RSAPublicKey(i32* null, i8** %6, i32 %14)
store i32* %15, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i32, i32* @RSA_F_RSA_PUB_DECODE
%19 = load i32, i32* @ERR_R_RSA_LIB
%20 = call i32 @RSAerr(i32 %18, i32 %19)
store i32 0, i32* %3
br label %25
21: ; preds = %13
%22 = load i32*, i32** %4
%23 = load i32*, i32** %8
%24 = call i32 @EVP_PKEY_assign_RSA(i32* %22, i32* %23)
store i32 1, i32* %3
br label %25
25: ; preds = %21, %17, %12
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@RSA_F_RSA_PUB_DECODE = global i32 0
@ERR_R_RSA_LIB = global i32 0
define i32 @rsa_pub_decode(i32* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @X509_PUBKEY_get0_param(i32* null, i8** %3, i32* %4, i32* null, i32* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = call i32* @d2i_RSAPublicKey(i32* null, i8** %3, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @RSA_F_RSA_PUB_DECODE
%15 = load i32, i32* @ERR_R_RSA_LIB
%16 = call i32 @RSAerr(i32 %14, i32 %15)
br label %19
17: ; preds = %9
%18 = call i32 @EVP_PKEY_assign_RSA(i32* %0, i32* %11)
br label %19
19: ; preds = %2, %17, %13
%20 = phi i32 [ 1, %17 ], [ 0, %13 ], [ 0, %2 ]
ret i32 %20
}