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

/* Variables and functions */
scalar_t__ EVP_PKEY_EC;
scalar_t__ EVP_PKEY_base_id(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *PEM_read_PUBKEY(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                    int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int extract_and_print_eckey(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int load_and_print_pubkey(FILE *pemFile, int version) {
  assert(pemFile);
  EVP_PKEY *pubkey = PEM_read_PUBKEY(pemFile, NULL, NULL, NULL);
  if (!pubkey) {
    fprintf(stderr, "error: PEM_read_PUBKEY() failed.\n");
    return 1;
  }
  if (EVP_PKEY_base_id(pubkey) != EVP_PKEY_EC) {
    fprintf(stderr, "error: PEM does not contain an EC key.\n");
    EVP_PKEY_free(pubkey);
    return 1;
  }
  int result = extract_and_print_eckey(pubkey, version);
  EVP_PKEY_free(pubkey);
  return result;
}


x86 assembly (clang, -O0):
<load_and_print_pubkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1080 <PEM_read_PUBKEY@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bb <load_and_print_pubkey+0x5b>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121c <load_and_print_pubkey+0xbc>
mov    -0x20(%rbp),%rdi
call   1030 <EVP_PKEY_base_id@plt>
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
je     11fe <load_and_print_pubkey+0x9e>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
movl   $0x1,-0x4(%rbp)
jmp    121c <load_and_print_pubkey+0xbc>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <extract_and_print_eckey@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_and_print_pubkey>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1060 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <PEM_read_PUBKEY@plt>
test   %rax,%rax
je     11af <load_and_print_pubkey+0x4f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <EVP_PKEY_base_id@plt>
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%rax
jne    11c6 <load_and_print_pubkey+0x66>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <extract_and_print_eckey@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <EVP_PKEY_free@plt>
mov    %ebp,%eax
jmp    11e8 <load_and_print_pubkey+0x88>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11e3 <load_and_print_pubkey+0x83>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <EVP_PKEY_free@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"error: PEM_read_PUBKEY() failed.\0A\00"
@EVP_PKEY_EC = global i64 0
@.str.1 = [40 x i8] c"error: PEM does not contain an EC key.\0A\00"
define i32 @load_and_print_pubkey(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32*, i32** %4
%9 = call i32 @assert(i32* %8)
%10 = load i32*, i32** %4
%11 = call i32* @PEM_read_PUBKEY(i32* %10, i32* null, i32* null, i32* null)
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %34
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = call i64 @EVP_PKEY_base_id(i32* %18)
%20 = load i64, i64* @EVP_PKEY_EC
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32*, i32** %6
%26 = call i32 @EVP_PKEY_free(i32* %25)
store i32 1, i32* %3
br label %34
27: ; preds = %17
%28 = load i32*, i32** %6
%29 = load i32, i32* %5
%30 = call i32 @extract_and_print_eckey(i32* %28, i32 %29)
store i32 %30, i32* %7
%31 = load i32*, i32** %6
%32 = call i32 @EVP_PKEY_free(i32* %31)
%33 = load i32, i32* %7
store i32 %33, i32* %3
br label %34
34: ; preds = %27, %22, %14
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"error: PEM_read_PUBKEY() failed.\0A\00"
@EVP_PKEY_EC = global i64 0
@.str.1 = [40 x i8] c"error: PEM does not contain an EC key.\0A\00"
define i32 @load_and_print_pubkey(i32* %0, i32 %1) {
%3 = tail call i32 @assert(i32* %0)
%4 = tail call i32* @PEM_read_PUBKEY(i32* %0, i32* null, i32* null, i32* null)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %20
9: ; preds = %2
%10 = tail call i64 @EVP_PKEY_base_id(i32* %4)
%11 = load i64, i64* @EVP_PKEY_EC
%12 = icmp eq i64 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @EVP_PKEY_free(i32* %4)
br label %20
17: ; preds = %9
%18 = tail call i32 @extract_and_print_eckey(i32* %4, i32 %1)
%19 = tail call i32 @EVP_PKEY_free(i32* %4)
br label %20
20: ; preds = %17, %13, %6
%21 = phi i32 [ 1, %13 ], [ %18, %17 ], [ 1, %6 ]
ret i32 %21
}