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

/* Variables and functions */
int /*<<< orphan*/ EC_KEY_check_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_get0_group(int /*<<< orphan*/ *);
scalar_t__ EC_KEY_set_private_key(int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ const *);
scalar_t__ EC_KEY_set_public_key(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_POINT_free(int /*<<< orphan*/ *);
scalar_t__ EC_POINT_mul(int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_POINT_new(int /*<<< orphan*/ const *);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int vg_set_privkey(const BIGNUM *bnpriv, EC_KEY *pkey) {
  const EC_GROUP *pgroup;
  EC_POINT *ppnt;
  int res;
  pgroup = EC_KEY_get0_group(pkey);
  ppnt = EC_POINT_new(pgroup);
  res = (ppnt && EC_KEY_set_private_key(pkey, bnpriv) &&
         EC_POINT_mul(pgroup, ppnt, bnpriv, NULL, NULL, NULL) &&
         EC_KEY_set_public_key(pkey, ppnt));
  if (ppnt)
    EC_POINT_free(ppnt);
  if (!res)
    return 0;
  assert(EC_KEY_check_key(pkey));
  return 1;
}


x86 assembly (clang, -O0):
<vg_set_privkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <EC_KEY_get0_group@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <EC_POINT_new@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x2d(%rbp)
je     121e <vg_set_privkey+0x9e>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <EC_KEY_set_private_key@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2d(%rbp)
je     121e <vg_set_privkey+0x9e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rcx
mov    %r9,%r8
call   1050 <EC_POINT_mul@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2d(%rbp)
je     121e <vg_set_privkey+0x9e>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <EC_KEY_set_public_key@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123d <vg_set_privkey+0xbd>
mov    -0x28(%rbp),%rdi
call   1090 <EC_POINT_free@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    1253 <vg_set_privkey+0xd3>
movl   $0x0,-0x4(%rbp)
jmp    126a <vg_set_privkey+0xea>
mov    -0x18(%rbp),%rdi
call   1040 <EC_KEY_check_key@plt>
mov    %eax,%edi
call   1070 <assert@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_set_privkey>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1080 <EC_KEY_get0_group@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <EC_POINT_new@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1217 <vg_set_privkey+0x97>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <EC_KEY_set_private_key@plt>
test   %rax,%rax
je     120f <vg_set_privkey+0x8f>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <EC_POINT_mul@plt>
test   %rax,%rax
je     120f <vg_set_privkey+0x8f>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <EC_KEY_set_public_key@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1090 <EC_POINT_free@plt>
mov    $0x0,%r14d
test   %rbx,%rbx
je     1217 <vg_set_privkey+0x97>
mov    %r12,%rdi
call   1040 <EC_KEY_check_key@plt>
mov    %eax,%edi
call   1070 <assert@plt>
mov    $0x1,%r14d
jmp    1217 <vg_set_privkey+0x97>
mov    %rbp,%rdi
call   1090 <EC_POINT_free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @vg_set_privkey(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = load i32*, i32** %5
%10 = call i32* @EC_KEY_get0_group(i32* %9)
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = call i32* @EC_POINT_new(i32* %11)
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %31
15: ; preds = %2
%16 = load i32*, i32** %5
%17 = load i32*, i32** %4
%18 = call i64 @EC_KEY_set_private_key(i32* %16, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i32*, i32** %6
%22 = load i32*, i32** %7
%23 = load i32*, i32** %4
%24 = call i64 @EC_POINT_mul(i32* %21, i32* %22, i32* %23, i32* null, i32* null, i32* null)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32*, i32** %5
%28 = load i32*, i32** %7
%29 = call i64 @EC_KEY_set_public_key(i32* %27, i32* %28)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %26, %20, %15, %2
%32 = phi i1 [ false, %20 ], [ false, %15 ], [ false, %2 ], [ %30, %26 ]
%33 = zext i1 %32 to i32
store i32 %33, i32* %8
%34 = load i32*, i32** %7
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32*, i32** %7
%38 = call i32 @EC_POINT_free(i32* %37)
br label %39
39: ; preds = %36, %31
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %39
store i32 0, i32* %3
br label %47
43: ; preds = %39
%44 = load i32*, i32** %5
%45 = call i32 @EC_KEY_check_key(i32* %44)
%46 = call i32 @assert(i32 %45)
store i32 1, i32* %3
br label %47
47: ; preds = %43, %42
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @vg_set_privkey(i32* %0, i32* %1) {
%3 = tail call i32* @EC_KEY_get0_group(i32* %1)
%4 = tail call i32* @EC_POINT_new(i32* %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = tail call i64 @EC_KEY_set_private_key(i32* %1, i32* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i64 @EC_POINT_mul(i32* %3, i32* %4, i32* %0, i32* null, i32* null, i32* null)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6, %9
%13 = tail call i32 @EC_POINT_free(i32* %4)
br label %21
14: ; preds = %9
%15 = tail call i64 @EC_KEY_set_public_key(i32* %1, i32* %4)
%16 = icmp eq i64 %15, 0
%17 = tail call i32 @EC_POINT_free(i32* %4)
br i1 %16, label %21, label %18
18: ; preds = %14
%19 = tail call i32 @EC_KEY_check_key(i32* %1)
%20 = tail call i32 @assert(i32 %19)
br label %21
21: ; preds = %2, %12, %14, %18
%22 = phi i32 [ 1, %18 ], [ 0, %14 ], [ 0, %12 ], [ 0, %2 ]
ret i32 %22
}