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

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_end(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
int /*<<< orphan*/ BN_CTX_start(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_get0_group(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_get0_private_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_KEY_set_public_key(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_POINT_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ 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*/ ERR_GOST_error(int, int, char *, int);
int ERR_R_EC_LIB;
int ERR_R_MALLOC_FAILURE;
int gost2001_compute_public(EC_KEY *ec) {
  const EC_GROUP *group = EC_KEY_get0_group(ec);
  EC_POINT *pub_key = NULL;
  const BIGNUM *priv_key = NULL;
  BN_CTX *ctx = NULL;
  int ok = 0;
  if (!group) {
    ERR_GOST_error(
        (104), (114),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/"
        "dependencies/openssl/engines/ccgost/gost2001.c",
        390);
    return 0;
  }
  ctx = BN_CTX_new();
  if (!ctx) {
    ERR_GOST_error(
        (104), (ERR_R_MALLOC_FAILURE),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/"
        "dependencies/openssl/engines/ccgost/gost2001.c",
        396);
    goto err;
  }
  BN_CTX_start(ctx);
  if (!(priv_key = EC_KEY_get0_private_key(ec))) {
    ERR_GOST_error(
        (104), (ERR_R_EC_LIB),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/"
        "dependencies/openssl/engines/ccgost/gost2001.c",
        401);
    goto err;
  }
  pub_key = EC_POINT_new(group);
  if (!pub_key) {
    ERR_GOST_error(
        (104), (ERR_R_MALLOC_FAILURE),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/"
        "dependencies/openssl/engines/ccgost/gost2001.c",
        407);
    goto err;
  }
  if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx)) {
    ERR_GOST_error(
        (104), (ERR_R_EC_LIB),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/"
        "dependencies/openssl/engines/ccgost/gost2001.c",
        411);
    goto err;
  }
  if (!EC_KEY_set_public_key(ec, pub_key)) {
    ERR_GOST_error(
        (104), (ERR_R_EC_LIB),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/"
        "dependencies/openssl/engines/ccgost/gost2001.c",
        415);
    goto err;
  }
  ok = 256;
err:
  if (pub_key)
    EC_POINT_free(pub_key);
  if (ctx) {
    BN_CTX_end(ctx);
    BN_CTX_free(ctx);
  }
  return ok;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <EC_KEY_get0_group@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121a <gost2001_compute_public+0x6a>
mov    $0x68,%edi
mov    $0x72,%esi
lea    0xdfc(%rip),%rdx
mov    $0x186,%ecx
call   10b0 <ERR_GOST_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1396 <gost2001_compute_public+0x1e6>
mov    $0x0,%al
call   1090 <BN_CTX_new@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1254 <gost2001_compute_public+0xa4>
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    $0x68,%edi
lea    0xdbb(%rip),%rdx
mov    $0x18c,%ecx
call   10b0 <ERR_GOST_error@plt>
jmp    135f <gost2001_compute_public+0x1af>
mov    -0x30(%rbp),%rdi
call   1080 <BN_CTX_start@plt>
mov    -0x10(%rbp),%rdi
call   1050 <EC_KEY_get0_private_key@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1298 <gost2001_compute_public+0xe8>
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    $0x68,%edi
lea    0xd77(%rip),%rdx
mov    $0x191,%ecx
call   10b0 <ERR_GOST_error@plt>
jmp    135f <gost2001_compute_public+0x1af>
mov    -0x18(%rbp),%rdi
call   10d0 <EC_POINT_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12d4 <gost2001_compute_public+0x124>
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
mov    $0x68,%edi
lea    0xd3b(%rip),%rdx
mov    $0x197,%ecx
call   10b0 <ERR_GOST_error@plt>
jmp    135f <gost2001_compute_public+0x1af>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%r9
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1040 <EC_POINT_mul@plt>
cmp    $0x0,%eax
jne    131e <gost2001_compute_public+0x16e>
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
mov    $0x68,%edi
lea    0xcf1(%rip),%rdx
mov    $0x19b,%ecx
call   10b0 <ERR_GOST_error@plt>
jmp    135f <gost2001_compute_public+0x1af>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <EC_KEY_set_public_key@plt>
cmp    $0x0,%eax
jne    1358 <gost2001_compute_public+0x1a8>
mov    0x2ca5(%rip),%rax
mov    (%rax),%esi
mov    $0x68,%edi
lea    0xcb7(%rip),%rdx
mov    $0x19f,%ecx
call   10b0 <ERR_GOST_error@plt>
jmp    135f <gost2001_compute_public+0x1af>
movl   $0x100,-0x34(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1373 <gost2001_compute_public+0x1c3>
mov    -0x20(%rbp),%rdi
call   10c0 <EC_POINT_free@plt>
cmpq   $0x0,-0x30(%rbp)
je     1390 <gost2001_compute_public+0x1e0>
mov    -0x30(%rbp),%rdi
call   1070 <BN_CTX_end@plt>
mov    -0x30(%rbp),%rdi
call   1060 <BN_CTX_free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   10a0 <EC_KEY_get0_group@plt>
test   %rax,%rax
je     1251 <gost2001_compute_public+0xa1>
mov    %rax,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1090 <BN_CTX_new@plt>
test   %rax,%rax
je     1273 <gost2001_compute_public+0xc3>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <BN_CTX_start@plt>
mov    %r12,%rdi
call   1050 <EC_KEY_get0_private_key@plt>
test   %rax,%rax
je     1294 <gost2001_compute_public+0xe4>
mov    %rax,%rbp
mov    %rbx,%rdi
call   10d0 <EC_POINT_new@plt>
test   %rax,%rax
je     12b0 <gost2001_compute_public+0x100>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %rbp,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1040 <EC_POINT_mul@plt>
test   %eax,%eax
je     12d3 <gost2001_compute_public+0x123>
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <EC_KEY_set_public_key@plt>
mov    $0x100,%ebp
test   %eax,%eax
jne    12f4 <gost2001_compute_public+0x144>
mov    $0x19f,%ecx
jmp    12d8 <gost2001_compute_public+0x128>
lea    0xda8(%rip),%rdx
mov    $0x68,%edi
mov    $0x72,%esi
mov    $0x186,%ecx
call   10b0 <ERR_GOST_error@plt>
xor    %ebp,%ebp
jmp    130c <gost2001_compute_public+0x15c>
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
lea    0xd7d(%rip),%rdx
mov    $0x68,%edi
mov    $0x18c,%ecx
call   10b0 <ERR_GOST_error@plt>
jmp    130c <gost2001_compute_public+0x15c>
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
lea    0xd5c(%rip),%rdx
mov    $0x68,%edi
mov    $0x191,%ecx
jmp    12ca <gost2001_compute_public+0x11a>
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
lea    0xd40(%rip),%rdx
mov    $0x68,%edi
mov    $0x197,%ecx
call   10b0 <ERR_GOST_error@plt>
xor    %ebp,%ebp
jmp    12fc <gost2001_compute_public+0x14c>
mov    $0x19b,%ecx
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
lea    0xd18(%rip),%rdx
mov    $0x68,%edi
call   10b0 <ERR_GOST_error@plt>
xor    %ebp,%ebp
mov    %r15,%rdi
call   10c0 <EC_POINT_free@plt>
mov    %r14,%rdi
call   1070 <BN_CTX_end@plt>
mov    %r14,%rdi
call   1060 <BN_CTX_free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [181 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/dependencies/openssl/engines/ccgost/gost2001.c\00"
@ERR_R_MALLOC_FAILURE = global i32 0
@ERR_R_EC_LIB = global i32 0
define i32 @gost2001_compute_public(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %3
%9 = load i32*, i32** %3
%10 = call i32* @EC_KEY_get0_group(i32* %9)
store i32* %10, i32** %4
store i32* null, i32** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32 0, i32* %8
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i32 @ERR_GOST_error(i32 104, i32 114, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 390)
store i32 0, i32* %2
br label %74
15: ; preds = %1
%16 = call i32* (...) @BN_CTX_new()
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp ne i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32, i32* @ERR_R_MALLOC_FAILURE
%21 = call i32 @ERR_GOST_error(i32 104, i32 %20, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 396)
br label %58
22: ; preds = %15
%23 = load i32*, i32** %7
%24 = call i32 @BN_CTX_start(i32* %23)
%25 = load i32*, i32** %3
%26 = call i32* @EC_KEY_get0_private_key(i32* %25)
store i32* %26, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %22
%29 = load i32, i32* @ERR_R_EC_LIB
%30 = call i32 @ERR_GOST_error(i32 104, i32 %29, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 401)
br label %58
31: ; preds = %22
%32 = load i32*, i32** %4
%33 = call i32* @EC_POINT_new(i32* %32)
store i32* %33, i32** %5
%34 = load i32*, i32** %5
%35 = icmp ne i32* %34, null
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = load i32, i32* @ERR_R_MALLOC_FAILURE
%38 = call i32 @ERR_GOST_error(i32 104, i32 %37, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 407)
br label %58
39: ; preds = %31
%40 = load i32*, i32** %4
%41 = load i32*, i32** %5
%42 = load i32*, i32** %6
%43 = load i32*, i32** %7
%44 = call i32 @EC_POINT_mul(i32* %40, i32* %41, i32* %42, i32* null, i32* null, i32* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %39
%47 = load i32, i32* @ERR_R_EC_LIB
%48 = call i32 @ERR_GOST_error(i32 104, i32 %47, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 411)
br label %58
49: ; preds = %39
%50 = load i32*, i32** %3
%51 = load i32*, i32** %5
%52 = call i32 @EC_KEY_set_public_key(i32* %50, i32* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %49
%55 = load i32, i32* @ERR_R_EC_LIB
%56 = call i32 @ERR_GOST_error(i32 104, i32 %55, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 415)
br label %58
57: ; preds = %49
store i32 256, i32* %8
br label %58
58: ; preds = %57, %54, %46, %36, %28, %19
%59 = load i32*, i32** %5
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32*, i32** %5
%63 = call i32 @EC_POINT_free(i32* %62)
br label %64
64: ; preds = %61, %58
%65 = load i32*, i32** %7
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i32*, i32** %7
%69 = call i32 @BN_CTX_end(i32* %68)
%70 = load i32*, i32** %7
%71 = call i32 @BN_CTX_free(i32* %70)
br label %72
72: ; preds = %67, %64
%73 = load i32, i32* %8
store i32 %73, i32* %2
br label %74
74: ; preds = %72, %13
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
@.str = [181 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Orav/kbengine/refs/heads/master/kbe/src/lib/dependencies/openssl/engines/ccgost/gost2001.c\00"
@ERR_R_MALLOC_FAILURE = global i32 0
@ERR_R_EC_LIB = global i32 0
define i32 @gost2001_compute_public(i32* %0) {
%2 = tail call i32* @EC_KEY_get0_group(i32* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @ERR_GOST_error(i32 104, i32 114, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 390)
br label %42
6: ; preds = %1
%7 = tail call i32* (...) @BN_CTX_new()
%8 = icmp eq i32* %7, null
br i1 %8, label %35, label %9
9: ; preds = %6
%10 = tail call i32 @BN_CTX_start(i32* %7)
%11 = tail call i32* @EC_KEY_get0_private_key(i32* %0)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @ERR_R_EC_LIB
%15 = tail call i32 @ERR_GOST_error(i32 104, i32 %14, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 401)
br label %38
16: ; preds = %9
%17 = tail call i32* @EC_POINT_new(i32* %2)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @ERR_R_MALLOC_FAILURE
%21 = tail call i32 @ERR_GOST_error(i32 104, i32 %20, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 407)
br label %38
22: ; preds = %16
%23 = tail call i32 @EC_POINT_mul(i32* %2, i32* %17, i32* %11, i32* null, i32* null, i32* %7)
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = tail call i32 @EC_KEY_set_public_key(i32* %0, i32* %17)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25, %22
%29 = phi i32 [ 411, %22 ], [ 415, %25 ]
%30 = load i32, i32* @ERR_R_EC_LIB
%31 = tail call i32 @ERR_GOST_error(i32 104, i32 %30, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %32
32: ; preds = %28, %25
%33 = phi i32 [ 256, %25 ], [ 0, %28 ]
%34 = tail call i32 @EC_POINT_free(i32* %17)
br label %38
35: ; preds = %6
%36 = load i32, i32* @ERR_R_MALLOC_FAILURE
%37 = tail call i32 @ERR_GOST_error(i32 104, i32 %36, i8* getelementptr inbounds ([181 x i8], [181 x i8]* @.str, i64 0, i64 0), i32 396)
br label %42
38: ; preds = %13, %19, %32
%39 = phi i32 [ %33, %32 ], [ 0, %19 ], [ 0, %13 ]
%40 = tail call i32 @BN_CTX_end(i32* %7)
%41 = tail call i32 @BN_CTX_free(i32* %7)
br label %42
42: ; preds = %35, %38, %4
%43 = phi i32 [ 0, %4 ], [ %39, %38 ], [ 0, %35 ]
ret i32 %43
}