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

/* Variables and functions */
int /*<<< orphan*/ OPENSSL_free(char *);
int byteArraytoInt(char *);
int /*<<< orphan*/ *d2i_PUBKEY(int /*<<< orphan*/ *, unsigned char const **,
                               int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *processData(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *, unsigned int *,
                  char *);
int /*<<< orphan*/ stderr;
EVP_PKEY *getPublicKey(ENGINE *e) {
  char *data = NULL;
  unsigned int len;
  const unsigned char *p1 = NULL;
  int enckeylen = 0;
  EVP_PKEY *pubkey = NULL;
  ;
  data = processData(e, "--getpubkey", 0, NULL, NULL, &len, "");
  if (!data) {
    fprintf(stderr, "ERROR: Loading Key failed\n");
    return NULL;
  }
  enckeylen = byteArraytoInt(data);
  p1 = (const unsigned char *)data;
  p1++;
  p1++;
  p1++;
  p1++;
  pubkey = d2i_PUBKEY(NULL, &p1, enckeylen);
  if (!pubkey) {
    fprintf(stderr, "ERROR: Converting encoded key failed\n");
    ;
    return NULL;
  }
  OPENSSL_free(data);
  data = NULL;
  p1 = NULL;
  return pubkey;
}


x86 assembly (clang, -O0):
<getPublicKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x1c(%rbp),%r9
lea    0xe8e(%rip),%rax
mov    %r8,%rcx
mov    %rax,(%rsp)
call   1030 <processData@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d5 <getPublicKey+0x85>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127b <getPublicKey+0x12b>
mov    -0x18(%rbp),%rdi
call   1040 <byteArraytoInt@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rsi
call   1050 <d2i_PUBKEY@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    125a <getPublicKey+0x10a>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127b <getPublicKey+0x12b>
mov    -0x18(%rbp),%rdi
call   1070 <OPENSSL_free@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPublicKey>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xec8(%rip),%rax
mov    %rax,(%rsp)
lea    0xe97(%rip),%rsi
lea    0x14(%rsp),%r9
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <processData@plt>
test   %rax,%rax
je     11b6 <getPublicKey+0x66>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <byteArraytoInt@plt>
mov    %rbx,%rcx
add    $0x4,%rcx
mov    %rcx,0x8(%rsp)
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    %eax,%edx
call   1050 <d2i_PUBKEY@plt>
test   %rax,%rax
je     11c8 <getPublicKey+0x78>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <OPENSSL_free@plt>
jmp    11e0 <getPublicKey+0x90>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
jmp    11d8 <getPublicKey+0x88>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"--getpubkey\00"
@.str.1 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.2 = [27 x i8] c"ERROR: Loading Key failed\0A\00"
@.str.3 = [38 x i8] c"ERROR: Converting encoded key failed\0A\00"
define i32* @getPublicKey(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %3
store i8* null, i8** %4
store i8* null, i8** %6
store i32 0, i32* %7
store i32* null, i32** %8
%9 = load i32*, i32** %3
%10 = call i8* @processData(i32* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 0, i32* null, i32* null, i32* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32* null, i32** %2
br label %39
16: ; preds = %1
%17 = load i8*, i8** %4
%18 = call i32 @byteArraytoInt(i8* %17)
store i32 %18, i32* %7
%19 = load i8*, i8** %4
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %6
%28 = load i32, i32* %7
%29 = call i32* @d2i_PUBKEY(i32* null, i8** %6, i32 %28)
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp ne i32* %30, null
br i1 %31, label %35, label %32
32: ; preds = %16
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
store i32* null, i32** %2
br label %39
35: ; preds = %16
%36 = load i8*, i8** %4
%37 = call i32 @OPENSSL_free(i8* %36)
store i8* null, i8** %4
store i8* null, i8** %6
%38 = load i32*, i32** %8
store i32* %38, i32** %2
br label %39
39: ; preds = %35, %32, %13
%40 = load i32*, i32** %2
ret i32* %40
}

LLVM IR (-O2):
@.str = [12 x i8] c"--getpubkey\00"
@.str.1 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.2 = [27 x i8] c"ERROR: Loading Key failed\0A\00"
@.str.3 = [38 x i8] c"ERROR: Converting encoded key failed\0A\00"
define i32* @getPublicKey(i32* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = call i8* @processData(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 0, i32* null, i32* null, i32* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %21
11: ; preds = %1
%12 = call i32 @byteArraytoInt(i8* %6)
%13 = getelementptr inbounds i8, i8* %6, i64 4
store i8* %13, i8** %3
%14 = call i32* @d2i_PUBKEY(i32* null, i8** %3, i32 %12)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %21
19: ; preds = %11
%20 = call i32 @OPENSSL_free(i8* %6)
br label %21
21: ; preds = %19, %16, %8
%22 = phi i32* [ %14, %19 ], [ null, %16 ], [ null, %8 ]
ret i32* %22
}