#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*/ RSAerror(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))) {
    RSAerror(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    11d1 <rsa_pub_decode+0x91>
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    11bd <rsa_pub_decode+0x7d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <RSAerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <rsa_pub_decode+0x91>
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     119d <rsa_pub_decode+0x5d>
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    119d <rsa_pub_decode+0x5d>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1060 <RSAerror@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@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 %24
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 %20, label %17
17: ; preds = %13
%18 = load i32, i32* @ERR_R_RSA_LIB
%19 = call i32 @RSAerror(i32 %18)
store i32 0, i32* %3
br label %24
20: ; preds = %13
%21 = load i32*, i32** %4
%22 = load i32*, i32** %8
%23 = call i32 @EVP_PKEY_assign_RSA(i32* %21, i32* %22)
store i32 1, i32* %3
br label %24
24: ; preds = %20, %17, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@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 %18, 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 %16
13: ; preds = %9
%14 = load i32, i32* @ERR_R_RSA_LIB
%15 = call i32 @RSAerror(i32 %14)
br label %18
16: ; preds = %9
%17 = call i32 @EVP_PKEY_assign_RSA(i32* %0, i32* %11)
br label %18
18: ; preds = %2, %16, %13
%19 = phi i32 [ 1, %16 ], [ 0, %13 ], [ 0, %2 ]
ret i32 %19
}