#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_get_conv_form(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_POINT_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_POINT_mul(int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_POINT_new(int /*<<< orphan*/ const *);
size_t EC_POINT_point2oct(int /*<<< orphan*/ const *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/, unsigned char *, size_t,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
size_t INT_MAX;
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
unsigned char *OPENSSL_malloc(size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ memcpy(void *, unsigned char *, size_t);
int /*<<< orphan*/ stderr;
int ecdh_compute_key_point(void *out, size_t outlen, const EC_POINT *pub_key,
                           EC_KEY *ecdh,
                           void *(*KDF)(const void *in, size_t inlen, void *out,
                                        size_t *outlen)) {
  BN_CTX *ctx = NULL;
  EC_POINT *tmp = NULL;
  const BIGNUM *priv_key;
  const EC_GROUP *group;
  int ret = -1;
  size_t buflen;
  unsigned char *buf = NULL;
  {
    if (!((outlen < INT_MAX))) {
      {
        fprintf(stderr,
                "[ERROR] (%s:%d ) "
                "out of memory"
                "\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                "master/src/misc.c",
                76);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  if ((ctx = BN_CTX_new()) == NULL)
    goto err;
  BN_CTX_start(ctx);
  priv_key = EC_KEY_get0_private_key(ecdh);
  {
    if (!(priv_key)) {
      {
        fprintf(stderr,
                "[ERROR] (%s:%d ) "
                "No pivate key"
                "\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                "master/src/misc.c",
                82);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  group = EC_KEY_get0_group(ecdh);
  tmp = EC_POINT_new(group);
  {
    if (!(tmp)) {
      {
        fprintf(stderr,
                "[ERROR] (%s:%d ) "
                "Out of memory"
                "\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                "master/src/misc.c",
                86);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  {
    if (!((EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)))) {
      {
        fprintf(stderr,
                "[ERROR] (%s:%d ) "
                "Arithmetic error"
                "\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                "master/src/misc.c",
                88);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  buflen =
      EC_POINT_point2oct(group, tmp, EC_KEY_get_conv_form(ecdh), NULL, 0, ctx);
  {
    if (!((buflen != 0))) {
      {
        fprintf(stderr,
                "[ERROR] (%s:%d ) "
                "Failed to convert point to hex"
                "\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                "master/src/misc.c",
                93);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  buf = OPENSSL_malloc(buflen);
  {
    if (!(buf)) {
      {
        fprintf(stderr,
                "[ERROR] (%s:%d ) "
                "Out of memory"
                "\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                "master/src/misc.c",
                96);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  {
    if (!((buflen == EC_POINT_point2oct(group, tmp, EC_KEY_get_conv_form(ecdh),
                                        buf, buflen, ctx)))) {
      {
        fprintf(stderr,
                "[ERROR] (%s:%d ) "
                "Failed to convert point to hex"
                "\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                "master/src/misc.c",
                98);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  if (KDF != 0) {
    {
      if (!((KDF(buf, buflen, out, &outlen) != NULL))) {
        {
          fprintf(stderr,
                  "[ERROR] (%s:%d ) "
                  "Key derivation function failed"
                  "\n",
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                  "master/src/misc.c",
                  103);
          ERR_print_errors_fp(stderr);
        };
        goto err;
      }
    };
    ret = outlen;
  } else {
    if (outlen > buflen)
      outlen = buflen;
    memcpy(out, buf, outlen);
    ret = outlen;
  }
err:
  if (tmp)
    EC_POINT_free(tmp);
  if (ctx)
    BN_CTX_end(ctx);
  if (ctx)
    BN_CTX_free(ctx);
  if (buf)
    OPENSSL_free(buf);
  return (ret);
}


x86 assembly (clang, -O0):
<ecdh_compute_key_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x4c(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
jb     1286 <ecdh_compute_key_point+0x86>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
lea    0xdb7(%rip),%rdx
mov    $0x4c,%ecx
call   1080 <fprintf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
jmp    158f <ecdh_compute_key_point+0x38f>
mov    $0x0,%al
call   10a0 <BN_CTX_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12a0 <ecdh_compute_key_point+0xa0>
jmp    158f <ecdh_compute_key_point+0x38f>
mov    -0x30(%rbp),%rdi
call   1070 <BN_CTX_start@plt>
mov    -0x20(%rbp),%rdi
call   1040 <EC_KEY_get0_private_key@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12f5 <ecdh_compute_key_point+0xf5>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
lea    0xd48(%rip),%rdx
mov    $0x52,%ecx
call   1080 <fprintf@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
jmp    158f <ecdh_compute_key_point+0x38f>
mov    -0x20(%rbp),%rdi
call   10b0 <EC_KEY_get0_group@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1120 <EC_POINT_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    134e <ecdh_compute_key_point+0x14e>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
lea    0xcef(%rip),%rdx
mov    $0x56,%ecx
call   1080 <fprintf@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
jmp    158f <ecdh_compute_key_point+0x38f>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x30(%rbp),%r9
xor    %eax,%eax
mov    %eax,%edx
call   1030 <EC_POINT_mul@plt>
cmp    $0x0,%eax
jne    13a8 <ecdh_compute_key_point+0x1a8>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
lea    0xc95(%rip),%rdx
mov    $0x58,%ecx
call   1080 <fprintf@plt>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
jmp    158f <ecdh_compute_key_point+0x38f>
mov    -0x48(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   10e0 <EC_KEY_get_conv_form@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
mov    -0x30(%rbp),%r9
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   10d0 <EC_POINT_point2oct@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    141f <ecdh_compute_key_point+0x21f>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    0xd0b(%rip),%rsi
lea    0xc1e(%rip),%rdx
mov    $0x5d,%ecx
call   1080 <fprintf@plt>
mov    0x2bc5(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
jmp    158f <ecdh_compute_key_point+0x38f>
mov    -0x58(%rbp),%rdi
call   10c0 <OPENSSL_malloc@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    146b <ecdh_compute_key_point+0x26b>
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
lea    0xc7c(%rip),%rsi
lea    0xbd2(%rip),%rdx
mov    $0x60,%ecx
call   1080 <fprintf@plt>
mov    0x2b79(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
jmp    158f <ecdh_compute_key_point+0x38f>
mov    -0x58(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%rdi
call   10e0 <EC_KEY_get_conv_form@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
mov    -0x60(%rbp),%rcx
mov    -0x58(%rbp),%r8
mov    -0x30(%rbp),%r9
call   10d0 <EC_POINT_point2oct@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
cmp    %rcx,%rax
je     14f1 <ecdh_compute_key_point+0x2f1>
mov    0x2b14(%rip),%rax
mov    (%rax),%edi
lea    0xc39(%rip),%rsi
lea    0xb4c(%rip),%rdx
mov    $0x62,%ecx
call   1080 <fprintf@plt>
mov    0x2af3(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
jmp    158f <ecdh_compute_key_point+0x38f>
cmpq   $0x0,-0x28(%rbp)
je     155c <ecdh_compute_key_point+0x35c>
mov    -0x28(%rbp),%rax
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   *%rax
cmp    $0x0,%rax
jne    1550 <ecdh_compute_key_point+0x350>
mov    0x2ab5(%rip),%rax
mov    (%rax),%edi
lea    0xc0b(%rip),%rsi
lea    0xaed(%rip),%rdx
mov    $0x67,%ecx
call   1080 <fprintf@plt>
mov    0x2a94(%rip),%rax
mov    (%rax),%edi
call   1100 <ERR_print_errors_fp@plt>
jmp    158f <ecdh_compute_key_point+0x38f>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4c(%rbp)
jmp    158a <ecdh_compute_key_point+0x38a>
mov    -0x10(%rbp),%rax
cmp    -0x58(%rbp),%rax
jbe    1572 <ecdh_compute_key_point+0x372>
mov    -0x58(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1090 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4c(%rbp)
jmp    158f <ecdh_compute_key_point+0x38f>
cmpq   $0x0,-0x38(%rbp)
je     15a3 <ecdh_compute_key_point+0x3a3>
mov    -0x38(%rbp),%rdi
call   1110 <EC_POINT_free@plt>
cmpq   $0x0,-0x30(%rbp)
je     15b7 <ecdh_compute_key_point+0x3b7>
mov    -0x30(%rbp),%rdi
call   1060 <BN_CTX_end@plt>
cmpq   $0x0,-0x30(%rbp)
je     15cb <ecdh_compute_key_point+0x3cb>
mov    -0x30(%rbp),%rdi
call   1050 <BN_CTX_free@plt>
cmpq   $0x0,-0x60(%rbp)
je     15df <ecdh_compute_key_point+0x3df>
mov    -0x60(%rbp),%rdi
call   10f0 <OPENSSL_free@plt>
mov    -0x4c(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecdh_compute_key_point>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x10(%rsp)
mov    0x2dce(%rip),%rax
cmp    %rsi,(%rax)
jbe    134d <ecdh_compute_key_point+0x14d>
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %eax,%eax
call   10a0 <BN_CTX_new@plt>
test   %rax,%rax
je     1375 <ecdh_compute_key_point+0x175>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   1070 <BN_CTX_start@plt>
mov    %r14,%rdi
call   1040 <EC_KEY_get0_private_key@plt>
test   %rax,%rax
je     137f <ecdh_compute_key_point+0x17f>
mov    %rax,%r13
mov    %r12,0x20(%rsp)
mov    %rbp,0x18(%rsp)
mov    %r14,%rdi
call   10b0 <EC_KEY_get0_group@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1120 <EC_POINT_new@plt>
test   %rax,%rax
je     139d <ecdh_compute_key_point+0x19d>
mov    %r12,%rdi
mov    %rax,%rbp
mov    %rax,%rsi
xor    %edx,%edx
mov    %r15,%rcx
mov    %r13,%r8
mov    0x8(%rsp),%r13
mov    %r13,%r9
call   1030 <EC_POINT_mul@plt>
test   %eax,%eax
je     13d7 <ecdh_compute_key_point+0x1d7>
mov    %r14,%rdi
call   10e0 <EC_KEY_get_conv_form@plt>
mov    %r12,%rdi
mov    %rbp,(%rsp)
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r13,%r9
call   10d0 <EC_POINT_point2oct@plt>
test   %rax,%rax
je     140f <ecdh_compute_key_point+0x20f>
mov    %rax,%r15
mov    %rax,%rdi
call   10c0 <OPENSSL_malloc@plt>
test   %rax,%rax
je     142d <ecdh_compute_key_point+0x22d>
mov    %rax,%rbp
mov    %r14,%rdi
call   10e0 <EC_KEY_get_conv_form@plt>
mov    %r12,%rdi
mov    (%rsp),%rsi
mov    %eax,%edx
mov    %rbp,%rcx
mov    %r15,%r8
mov    %r13,%r9
call   10d0 <EC_POINT_point2oct@plt>
cmp    %rax,%r15
mov    %rbp,%r14
jne    145f <ecdh_compute_key_point+0x25f>
mov    0x20(%rsp),%rax
test   %rax,%rax
je     148e <ecdh_compute_key_point+0x28e>
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %r15,%rsi
mov    0x18(%rsp),%rdx
call   *%rax
test   %rax,%rax
je     14e2 <ecdh_compute_key_point+0x2e2>
mov    0x10(%rsp),%ebx
jmp    14ab <ecdh_compute_key_point+0x2ab>
mov    0x2c84(%rip),%rbx
mov    (%rbx),%edi
lea    0xca3(%rip),%rsi
lea    0xcbc(%rip),%rdx
mov    $0x4c,%ecx
call   1080 <fprintf@plt>
mov    (%rbx),%edi
call   1100 <ERR_print_errors_fp@plt>
mov    $0xffffffff,%ebx
jmp    14d1 <ecdh_compute_key_point+0x2d1>
mov    0x2c52(%rip),%rbx
mov    (%rbx),%edi
lea    0xd14(%rip),%rsi
lea    0xc8a(%rip),%rdx
mov    $0x52,%ecx
jmp    13b9 <ecdh_compute_key_point+0x1b9>
mov    0x2c34(%rip),%rbx
mov    (%rbx),%edi
lea    0xd16(%rip),%rsi
lea    0xc6c(%rip),%rdx
mov    $0x56,%ecx
call   1080 <fprintf@plt>
mov    (%rbx),%edi
call   1100 <ERR_print_errors_fp@plt>
mov    $0xffffffff,%ebx
xor    %r14d,%r14d
mov    0x8(%rsp),%r13
jmp    14b4 <ecdh_compute_key_point+0x2b4>
mov    0x2bfa(%rip),%rbx
mov    (%rbx),%edi
lea    0xcfc(%rip),%rsi
lea    0xc32(%rip),%rdx
mov    $0x58,%ecx
call   1080 <fprintf@plt>
mov    (%rbx),%edi
call   1100 <ERR_print_errors_fp@plt>
mov    $0xffffffff,%ebx
xor    %r14d,%r14d
mov    %rbp,%rdi
jmp    14af <ecdh_compute_key_point+0x2af>
mov    0x2bc2(%rip),%rbx
mov    (%rbx),%edi
lea    0xce7(%rip),%rsi
lea    0xbfa(%rip),%rdx
mov    $0x5d,%ecx
jmp    1449 <ecdh_compute_key_point+0x249>
mov    0x2ba4(%rip),%rbx
mov    (%rbx),%edi
lea    0xc86(%rip),%rsi
lea    0xbdc(%rip),%rdx
mov    $0x60,%ecx
call   1080 <fprintf@plt>
mov    (%rbx),%edi
call   1100 <ERR_print_errors_fp@plt>
mov    $0xffffffff,%ebx
xor    %r14d,%r14d
jmp    14ab <ecdh_compute_key_point+0x2ab>
mov    0x2b72(%rip),%rbx
mov    (%rbx),%edi
lea    0xc97(%rip),%rsi
lea    0xbaa(%rip),%rdx
mov    $0x62,%ecx
call   1080 <fprintf@plt>
mov    (%rbx),%edi
call   1100 <ERR_print_errors_fp@plt>
mov    $0xffffffff,%ebx
jmp    14ab <ecdh_compute_key_point+0x2ab>
cmp    %rbx,%r15
jae    149b <ecdh_compute_key_point+0x29b>
mov    %r15,0x10(%rsp)
mov    %r15,%rbx
mov    0x18(%rsp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1090 <memcpy@plt>
mov    (%rsp),%rdi
call   1110 <EC_POINT_free@plt>
mov    %r13,%rdi
call   1060 <BN_CTX_end@plt>
mov    %r13,%rdi
call   1050 <BN_CTX_free@plt>
test   %r14,%r14
je     14d1 <ecdh_compute_key_point+0x2d1>
mov    %r14,%rdi
call   10f0 <OPENSSL_free@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2aef(%rip),%rbx
mov    (%rbx),%edi
lea    0xc45(%rip),%rsi
lea    0xb27(%rip),%rdx
mov    $0x67,%ecx
jmp    147b <ecdh_compute_key_point+0x27b>

LLVM IR (-O0):
@INT_MAX = global i64 0
@stderr = global i32 0
@.str = [32 x i8] c"[ERROR] (%s:%d ) out of memory\0A\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/master/src/misc.c\00"
@.str.2 = [32 x i8] c"[ERROR] (%s:%d ) No pivate key\0A\00"
@.str.3 = [32 x i8] c"[ERROR] (%s:%d ) Out of memory\0A\00"
@.str.4 = [35 x i8] c"[ERROR] (%s:%d ) Arithmetic error\0A\00"
@.str.5 = [49 x i8] c"[ERROR] (%s:%d ) Failed to convert point to hex\0A\00"
@.str.6 = [49 x i8] c"[ERROR] (%s:%d ) Key derivation function failed\0A\00"
define i32 @ecdh_compute_key_point(i8* %0, i64 %1, i32* %2, i32* %3, i8* (i8*, i64, i8*, i64*)* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8* (i8*, i64, i8*, i64*)*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i64
%17 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i8* (i8*, i64, i8*, i64*)* %4, i8* (i8*, i64, i8*, i64*)** %10
store i32* null, i32** %11
store i32* null, i32** %12
store i32 -1, i32* %15
store i8* null, i8** %17
%18 = load i64, i64* %7
%19 = load i64, i64* @INT_MAX
%20 = icmp ult i64 %18, %19
br i1 %20, label %26, label %21
21: ; preds = %5
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 76)
%24 = load i32, i32* @stderr
%25 = call i32 @ERR_print_errors_fp(i32 %24)
br label %139
26: ; preds = %5
%27 = call i32* (...) @BN_CTX_new()
store i32* %27, i32** %11
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %26
br label %139
30: ; preds = %26
%31 = load i32*, i32** %11
%32 = call i32 @BN_CTX_start(i32* %31)
%33 = load i32*, i32** %9
%34 = call i32* @EC_KEY_get0_private_key(i32* %33)
store i32* %34, i32** %13
%35 = load i32*, i32** %13
%36 = icmp ne i32* %35, null
br i1 %36, label %42, label %37
37: ; preds = %30
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 82)
%40 = load i32, i32* @stderr
%41 = call i32 @ERR_print_errors_fp(i32 %40)
br label %139
42: ; preds = %30
%43 = load i32*, i32** %9
%44 = call i32* @EC_KEY_get0_group(i32* %43)
store i32* %44, i32** %14
%45 = load i32*, i32** %14
%46 = call i32* @EC_POINT_new(i32* %45)
store i32* %46, i32** %12
%47 = load i32*, i32** %12
%48 = icmp ne i32* %47, null
br i1 %48, label %54, label %49
49: ; preds = %42
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 86)
%52 = load i32, i32* @stderr
%53 = call i32 @ERR_print_errors_fp(i32 %52)
br label %139
54: ; preds = %42
%55 = load i32*, i32** %14
%56 = load i32*, i32** %12
%57 = load i32*, i32** %8
%58 = load i32*, i32** %13
%59 = load i32*, i32** %11
%60 = call i32 @EC_POINT_mul(i32* %55, i32* %56, i32* null, i32* %57, i32* %58, i32* %59)
%61 = icmp ne i32 %60, 0
br i1 %61, label %67, label %62
62: ; preds = %54
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 88)
%65 = load i32, i32* @stderr
%66 = call i32 @ERR_print_errors_fp(i32 %65)
br label %139
67: ; preds = %54
%68 = load i32*, i32** %14
%69 = load i32*, i32** %12
%70 = load i32*, i32** %9
%71 = call i32 @EC_KEY_get_conv_form(i32* %70)
%72 = load i32*, i32** %11
%73 = call i64 @EC_POINT_point2oct(i32* %68, i32* %69, i32 %71, i8* null, i64 0, i32* %72)
store i64 %73, i64* %16
%74 = load i64, i64* %16
%75 = icmp ne i64 %74, 0
br i1 %75, label %81, label %76
76: ; preds = %67
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 93)
%79 = load i32, i32* @stderr
%80 = call i32 @ERR_print_errors_fp(i32 %79)
br label %139
81: ; preds = %67
%82 = load i64, i64* %16
%83 = call i8* @OPENSSL_malloc(i64 %82)
store i8* %83, i8** %17
%84 = load i8*, i8** %17
%85 = icmp ne i8* %84, null
br i1 %85, label %91, label %86
86: ; preds = %81
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 96)
%89 = load i32, i32* @stderr
%90 = call i32 @ERR_print_errors_fp(i32 %89)
br label %139
91: ; preds = %81
%92 = load i64, i64* %16
%93 = load i32*, i32** %14
%94 = load i32*, i32** %12
%95 = load i32*, i32** %9
%96 = call i32 @EC_KEY_get_conv_form(i32* %95)
%97 = load i8*, i8** %17
%98 = load i64, i64* %16
%99 = load i32*, i32** %11
%100 = call i64 @EC_POINT_point2oct(i32* %93, i32* %94, i32 %96, i8* %97, i64 %98, i32* %99)
%101 = icmp eq i64 %92, %100
br i1 %101, label %107, label %102
102: ; preds = %91
%103 = load i32, i32* @stderr
%104 = call i32 @fprintf(i32 %103, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 98)
%105 = load i32, i32* @stderr
%106 = call i32 @ERR_print_errors_fp(i32 %105)
br label %139
107: ; preds = %91
%108 = load i8* (i8*, i64, i8*, i64*)*, i8* (i8*, i64, i8*, i64*)** %10
%109 = icmp ne i8* (i8*, i64, i8*, i64*)* %108, null
br i1 %109, label %110, label %125
110: ; preds = %107
%111 = load i8* (i8*, i64, i8*, i64*)*, i8* (i8*, i64, i8*, i64*)** %10
%112 = load i8*, i8** %17
%113 = load i64, i64* %16
%114 = load i8*, i8** %6
%115 = call i8* %111(i8* %112, i64 %113, i8* %114, i64* %7)
%116 = icmp ne i8* %115, null
br i1 %116, label %122, label %117
117: ; preds = %110
%118 = load i32, i32* @stderr
%119 = call i32 @fprintf(i32 %118, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 103)
%120 = load i32, i32* @stderr
%121 = call i32 @ERR_print_errors_fp(i32 %120)
br label %139
122: ; preds = %110
%123 = load i64, i64* %7
%124 = trunc i64 %123 to i32
store i32 %124, i32* %15
br label %138
125: ; preds = %107
%126 = load i64, i64* %7
%127 = load i64, i64* %16
%128 = icmp ugt i64 %126, %127
br i1 %128, label %129, label %131
129: ; preds = %125
%130 = load i64, i64* %16
store i64 %130, i64* %7
br label %131
131: ; preds = %129, %125
%132 = load i8*, i8** %6
%133 = load i8*, i8** %17
%134 = load i64, i64* %7
%135 = call i32 @memcpy(i8* %132, i8* %133, i64 %134)
%136 = load i64, i64* %7
%137 = trunc i64 %136 to i32
store i32 %137, i32* %15
br label %138
138: ; preds = %131, %122
br label %139
139: ; preds = %138, %117, %102, %86, %76, %62, %49, %37, %29, %21
%140 = load i32*, i32** %12
%141 = icmp ne i32* %140, null
br i1 %141, label %142, label %145
142: ; preds = %139
%143 = load i32*, i32** %12
%144 = call i32 @EC_POINT_free(i32* %143)
br label %145
145: ; preds = %142, %139
%146 = load i32*, i32** %11
%147 = icmp ne i32* %146, null
br i1 %147, label %148, label %151
148: ; preds = %145
%149 = load i32*, i32** %11
%150 = call i32 @BN_CTX_end(i32* %149)
br label %151
151: ; preds = %148, %145
%152 = load i32*, i32** %11
%153 = icmp ne i32* %152, null
br i1 %153, label %154, label %157
154: ; preds = %151
%155 = load i32*, i32** %11
%156 = call i32 @BN_CTX_free(i32* %155)
br label %157
157: ; preds = %154, %151
%158 = load i8*, i8** %17
%159 = icmp ne i8* %158, null
br i1 %159, label %160, label %163
160: ; preds = %157
%161 = load i8*, i8** %17
%162 = call i32 @OPENSSL_free(i8* %161)
br label %163
163: ; preds = %160, %157
%164 = load i32, i32* %15
ret i32 %164
}

LLVM IR (-O2):
@INT_MAX = global i64 0
@stderr = global i32 0
@.str = [32 x i8] c"[ERROR] (%s:%d ) out of memory\0A\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/master/src/misc.c\00"
@.str.2 = [32 x i8] c"[ERROR] (%s:%d ) No pivate key\0A\00"
@.str.3 = [32 x i8] c"[ERROR] (%s:%d ) Out of memory\0A\00"
@.str.4 = [35 x i8] c"[ERROR] (%s:%d ) Arithmetic error\0A\00"
@.str.5 = [49 x i8] c"[ERROR] (%s:%d ) Failed to convert point to hex\0A\00"
@.str.6 = [49 x i8] c"[ERROR] (%s:%d ) Key derivation function failed\0A\00"
define i32 @ecdh_compute_key_point(i8* %0, i64 %1, i32* %2, i32* %3, i8* (i8*, i64, i8*, i64*)* %4) {
%6 = alloca i64
store i64 %1, i64* %6
%7 = load i64, i64* @INT_MAX
%8 = icmp ugt i64 %7, %1
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 76)
%12 = load i32, i32* @stderr
%13 = tail call i32 @ERR_print_errors_fp(i32 %12)
br label %101
14: ; preds = %5
%15 = tail call i32* (...) @BN_CTX_new()
%16 = icmp eq i32* %15, null
br i1 %16, label %101, label %17
17: ; preds = %14
%18 = tail call i32 @BN_CTX_start(i32* %15)
%19 = tail call i32* @EC_KEY_get0_private_key(i32* %3)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 82)
%24 = load i32, i32* @stderr
%25 = tail call i32 @ERR_print_errors_fp(i32 %24)
br label %93
26: ; preds = %17
%27 = tail call i32* @EC_KEY_get0_group(i32* %3)
%28 = tail call i32* @EC_POINT_new(i32* %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 86)
%33 = load i32, i32* @stderr
%34 = tail call i32 @ERR_print_errors_fp(i32 %33)
br label %93
35: ; preds = %26
%36 = tail call i32 @EC_POINT_mul(i32* %27, i32* %28, i32* null, i32* %2, i32* %19, i32* %15)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 88)
%41 = load i32, i32* @stderr
%42 = tail call i32 @ERR_print_errors_fp(i32 %41)
br label %89
43: ; preds = %35
%44 = tail call i32 @EC_KEY_get_conv_form(i32* %3)
%45 = tail call i64 @EC_POINT_point2oct(i32* %27, i32* %28, i32 %44, i8* null, i64 0, i32* %15)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 93)
%50 = load i32, i32* @stderr
%51 = tail call i32 @ERR_print_errors_fp(i32 %50)
br label %89
52: ; preds = %43
%53 = tail call i8* @OPENSSL_malloc(i64 %45)
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %60
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = tail call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 96)
%58 = load i32, i32* @stderr
%59 = tail call i32 @ERR_print_errors_fp(i32 %58)
br label %89
60: ; preds = %52
%61 = tail call i32 @EC_KEY_get_conv_form(i32* %3)
%62 = tail call i64 @EC_POINT_point2oct(i32* %27, i32* %28, i32 %61, i8* %53, i64 %45, i32* %15)
%63 = icmp eq i64 %45, %62
br i1 %63, label %69, label %64
64: ; preds = %60
%65 = load i32, i32* @stderr
%66 = tail call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 98)
%67 = load i32, i32* @stderr
%68 = tail call i32 @ERR_print_errors_fp(i32 %67)
br label %89
69: ; preds = %60
%70 = icmp eq i8* (i8*, i64, i8*, i64*)* %4, null
br i1 %70, label %82, label %71
71: ; preds = %69
%72 = call i8* %4(i8* %53, i64 %45, i8* %0, i64* %6)
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %79
74: ; preds = %71
%75 = load i32, i32* @stderr
%76 = call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 103)
%77 = load i32, i32* @stderr
%78 = call i32 @ERR_print_errors_fp(i32 %77)
br label %89
79: ; preds = %71
%80 = load i64, i64* %6
%81 = trunc i64 %80 to i32
br label %89
82: ; preds = %69
%83 = icmp ult i64 %45, %1
br i1 %83, label %84, label %85
84: ; preds = %82
store i64 %45, i64* %6
br label %85
85: ; preds = %84, %82
%86 = phi i64 [ %45, %84 ], [ %1, %82 ]
%87 = tail call i32 @memcpy(i8* %0, i8* %53, i64 %86)
%88 = trunc i64 %86 to i32
br label %89
89: ; preds = %79, %74, %85, %64, %55, %47, %38
%90 = phi i32 [ -1, %38 ], [ -1, %47 ], [ -1, %55 ], [ -1, %64 ], [ %88, %85 ], [ -1, %74 ], [ %81, %79 ]
%91 = phi i8* [ null, %38 ], [ null, %47 ], [ null, %55 ], [ %53, %64 ], [ %53, %85 ], [ %53, %74 ], [ %53, %79 ]
%92 = call i32 @EC_POINT_free(i32* %28)
br label %93
93: ; preds = %21, %30, %89
%94 = phi i8* [ null, %21 ], [ null, %30 ], [ %91, %89 ]
%95 = phi i32 [ -1, %21 ], [ -1, %30 ], [ %90, %89 ]
%96 = call i32 @BN_CTX_end(i32* %15)
%97 = call i32 @BN_CTX_free(i32* %15)
%98 = icmp eq i8* %94, null
br i1 %98, label %101, label %99
99: ; preds = %93
%100 = call i32 @OPENSSL_free(i8* %94)
br label %101
101: ; preds = %9, %14, %99, %93
%102 = phi i32 [ %95, %99 ], [ %95, %93 ], [ -1, %14 ], [ -1, %9 ]
ret i32 %102
}