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

/* Variables and functions */
int /*<<< orphan*/ EC_KEY_get0_group(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *EC_KEY_get0_public_key(int /*<<< orphan*/ const *);
scalar_t__ EC_POINT_cmp(int /*<<< orphan*/, int /*<<< orphan*/ const *,
                        int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_get0(int /*<<< orphan*/ *);
int pub_cmp_gost01(const EVP_PKEY *a, const EVP_PKEY *b) {
  const EC_KEY *ea = EVP_PKEY_get0((EVP_PKEY *)a);
  const EC_KEY *eb = EVP_PKEY_get0((EVP_PKEY *)b);
  const EC_POINT *ka, *kb;
  int ret = 0;
  if (!ea || !eb)
    return 0;
  ka = EC_KEY_get0_public_key(ea);
  kb = EC_KEY_get0_public_key(eb);
  if (!ka || !kb)
    return 0;
  ret = (0 == EC_POINT_cmp(EC_KEY_get0_group(ea), ka, kb, NULL));
  return ret;
}


x86 assembly (clang, -O0):
<pub_cmp_gost01>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <EVP_PKEY_get0@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <EVP_PKEY_get0@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1187 <pub_cmp_gost01+0x47>
cmpq   $0x0,-0x28(%rbp)
jne    1193 <pub_cmp_gost01+0x53>
movl   $0x0,-0x4(%rbp)
jmp    1204 <pub_cmp_gost01+0xc4>
mov    -0x20(%rbp),%rdi
call   1040 <EC_KEY_get0_public_key@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <EC_KEY_get0_public_key@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c3 <pub_cmp_gost01+0x83>
cmpq   $0x0,-0x38(%rbp)
jne    11cf <pub_cmp_gost01+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    1204 <pub_cmp_gost01+0xc4>
mov    -0x20(%rbp),%rdi
call   1060 <EC_KEY_get0_group@plt>
mov    %eax,%edi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <EC_POINT_cmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pub_cmp_gost01>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
call   1030 <EVP_PKEY_get0@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <EVP_PKEY_get0@plt>
xor    %r12d,%r12d
test   %rbx,%rbx
je     11ac <pub_cmp_gost01+0x6c>
mov    %rax,%rbp
test   %rax,%rax
je     11ac <pub_cmp_gost01+0x6c>
mov    %rbx,%rdi
call   1040 <EC_KEY_get0_public_key@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1040 <EC_KEY_get0_public_key@plt>
test   %r14,%r14
je     11ac <pub_cmp_gost01+0x6c>
mov    %rax,%r15
test   %rax,%rax
je     11ac <pub_cmp_gost01+0x6c>
mov    %rbx,%rdi
call   1060 <EC_KEY_get0_group@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
call   1050 <EC_POINT_cmp@plt>
xor    %r12d,%r12d
test   %rax,%rax
sete   %r12b
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pub_cmp_gost01(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%11 = load i32*, i32** %4
%12 = call i32* @EVP_PKEY_get0(i32* %11)
store i32* %12, i32** %6
%13 = load i32*, i32** %5
%14 = call i32* @EVP_PKEY_get0(i32* %13)
store i32* %14, i32** %7
store i32 0, i32* %10
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %17, %2
store i32 0, i32* %3
br label %41
21: ; preds = %17
%22 = load i32*, i32** %6
%23 = call i32* @EC_KEY_get0_public_key(i32* %22)
store i32* %23, i32** %8
%24 = load i32*, i32** %7
%25 = call i32* @EC_KEY_get0_public_key(i32* %24)
store i32* %25, i32** %9
%26 = load i32*, i32** %8
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i32*, i32** %9
%30 = icmp ne i32* %29, null
br i1 %30, label %32, label %31
31: ; preds = %28, %21
store i32 0, i32* %3
br label %41
32: ; preds = %28
%33 = load i32*, i32** %6
%34 = call i32 @EC_KEY_get0_group(i32* %33)
%35 = load i32*, i32** %8
%36 = load i32*, i32** %9
%37 = call i64 @EC_POINT_cmp(i32 %34, i32* %35, i32* %36, i32* null)
%38 = icmp eq i64 0, %37
%39 = zext i1 %38 to i32
store i32 %39, i32* %10
%40 = load i32, i32* %10
store i32 %40, i32* %3
br label %41
41: ; preds = %32, %31, %20
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @pub_cmp_gost01(i32* %0, i32* %1) {
%3 = tail call i32* @EVP_PKEY_get0(i32* %0)
%4 = tail call i32* @EVP_PKEY_get0(i32* %1)
%5 = icmp ne i32* %3, null
%6 = icmp ne i32* %4, null
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = tail call i32* @EC_KEY_get0_public_key(i32* %3)
%10 = tail call i32* @EC_KEY_get0_public_key(i32* %4)
%11 = icmp ne i32* %9, null
%12 = icmp ne i32* %10, null
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = tail call i32 @EC_KEY_get0_group(i32* %3)
%16 = tail call i64 @EC_POINT_cmp(i32 %15, i32* %9, i32* %10, i32* null)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %8, %2, %14
%20 = phi i32 [ %18, %14 ], [ 0, %2 ], [ 0, %8 ]
ret i32 %20
}