#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*/ point_conversion_form_t;
typedef int /*<<< orphan*/ EC_POINT;
typedef int /*<<< orphan*/ EC_KEY;
typedef int /*<<< orphan*/ EC_GROUP;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ EC_KEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_get0_group(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_get0_private_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_get0_public_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_new();
size_t EC_POINT_point2oct(int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int /*<<< orphan*/,
                          unsigned char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ ec_keys(int /*<<< orphan*/ *, unsigned char const *, int,
                           int /*<<< orphan*/ *, int /*<<< orphan*/, int);
void ec_pub_key(unsigned char *pub_key, const unsigned char *priv_key,
                int priv_key_len, int curve_id, point_conversion_form_t form) {
  EC_KEY *keys = EC_KEY_new();
  ec_keys(keys, priv_key, priv_key_len, NULL, 0, curve_id);
  const EC_GROUP *group = EC_KEY_get0_group(keys);
  const EC_POINT *pk_point = EC_KEY_get0_public_key(keys);
  const BIGNUM *priv = EC_KEY_get0_private_key(keys);
  size_t len = EC_POINT_point2oct(group, pk_point, form, NULL, 0, NULL);
  EC_POINT_point2oct(group, pk_point, form, pub_key, len, NULL);
  EC_KEY_free(keys);
}


x86 assembly (clang, -O0):
<ec_pub_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    $0x0,%al
call   1080 <EC_KEY_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1090 <ec_keys@plt>
mov    -0x28(%rbp),%rdi
call   1050 <EC_KEY_get0_group@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <EC_KEY_get0_public_key@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <EC_KEY_get0_private_key@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rcx
mov    %r9,%r8
call   1060 <EC_POINT_point2oct@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x48(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1060 <EC_POINT_point2oct@plt>
mov    -0x28(%rbp),%rdi
call   1070 <EC_KEY_free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ec_pub_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,%rbp
mov    %rdi,%r14
xor    %eax,%eax
call   1080 <EC_KEY_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r12d,%r9d
call   1090 <ec_keys@plt>
mov    %rbx,%rdi
call   1050 <EC_KEY_get0_group@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <EC_KEY_get0_public_key@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <EC_KEY_get0_private_key@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <EC_POINT_point2oct@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
mov    %rax,%r8
xor    %r9d,%r9d
call   1060 <EC_POINT_point2oct@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <EC_KEY_free@plt>

LLVM IR (-O0):
define void @ec_pub_key(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%16 = call i32* (...) @EC_KEY_new()
store i32* %16, i32** %11
%17 = load i32*, i32** %11
%18 = load i8*, i8** %7
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = call i32 @ec_keys(i32* %17, i8* %18, i32 %19, i32* null, i32 0, i32 %20)
%22 = load i32*, i32** %11
%23 = call i32* @EC_KEY_get0_group(i32* %22)
store i32* %23, i32** %12
%24 = load i32*, i32** %11
%25 = call i32* @EC_KEY_get0_public_key(i32* %24)
store i32* %25, i32** %13
%26 = load i32*, i32** %11
%27 = call i32* @EC_KEY_get0_private_key(i32* %26)
store i32* %27, i32** %14
%28 = load i32*, i32** %12
%29 = load i32*, i32** %13
%30 = load i32, i32* %10
%31 = call i64 @EC_POINT_point2oct(i32* %28, i32* %29, i32 %30, i8* null, i64 0, i32* null)
store i64 %31, i64* %15
%32 = load i32*, i32** %12
%33 = load i32*, i32** %13
%34 = load i32, i32* %10
%35 = load i8*, i8** %6
%36 = load i64, i64* %15
%37 = call i64 @EC_POINT_point2oct(i32* %32, i32* %33, i32 %34, i8* %35, i64 %36, i32* null)
%38 = load i32*, i32** %11
%39 = call i32 @EC_KEY_free(i32* %38)
ret void
}

LLVM IR (-O2):
define void @ec_pub_key(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32* (...) @EC_KEY_new()
%7 = tail call i32 @ec_keys(i32* %6, i8* %1, i32 %2, i32* null, i32 0, i32 %3)
%8 = tail call i32* @EC_KEY_get0_group(i32* %6)
%9 = tail call i32* @EC_KEY_get0_public_key(i32* %6)
%10 = tail call i32* @EC_KEY_get0_private_key(i32* %6)
%11 = tail call i64 @EC_POINT_point2oct(i32* %8, i32* %9, i32 %4, i8* null, i64 0, i32* null)
%12 = tail call i64 @EC_POINT_point2oct(i32* %8, i32* %9, i32 %4, i8* %0, i64 %11, i32* null)
%13 = tail call i32 @EC_KEY_free(i32* %6)
ret void
}