#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;

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
unsigned char *OPENSSL_malloc(int);
int ecdh_compute_key_point(unsigned char *, size_t, int /*<<< orphan*/ const *,
                           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stderr;
int new_ecdh_compute_key_point(unsigned char **psec, size_t *pseclen,
                               const EC_POINT *pub_key, const EC_KEY *ecdh) {
  int ret = -1;
  *psec = OPENSSL_malloc(133);
  {
    if (!(*psec)) {
      {
        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/frankmorgner/openpace/refs/"
                "heads/master/src/misc.c",
                152);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  *pseclen = 133;
  ret = ecdh_compute_key_point(*psec, *pseclen, pub_key, (EC_KEY *)ecdh, NULL);
err:
  if (ret <= 0) {
    OPENSSL_free(*psec);
    *psec = NULL;
    *pseclen = 0;
    ret = 0;
  } else {
    *pseclen = ret;
    ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<new_ecdh_compute_key_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    $0x85,%edi
call   1040 <OPENSSL_malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c5 <new_ecdh_compute_key_point+0x75>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
lea    0xe78(%rip),%rdx
mov    $0x98,%ecx
call   1030 <fprintf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1070 <ERR_print_errors_fp@plt>
jmp    11f3 <new_ecdh_compute_key_point+0xa3>
mov    -0x10(%rbp),%rax
movq   $0x85,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <ecdh_compute_key_point@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     122b <new_ecdh_compute_key_point+0xdb>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <OPENSSL_free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x24(%rbp)
jmp    123d <new_ecdh_compute_key_point+0xed>
movslq -0x24(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_ecdh_compute_key_point>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x85,%edi
call   1040 <OPENSSL_malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11a0 <new_ecdh_compute_key_point+0x50>
movq   $0x85,(%r14)
mov    $0x85,%esi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1060 <ecdh_compute_key_point@plt>
test   %eax,%eax
jle    11ca <new_ecdh_compute_key_point+0x7a>
mov    %eax,%ecx
mov    $0x1,%eax
jmp    11dd <new_ecdh_compute_key_point+0x8d>
mov    0x2e39(%rip),%r15
mov    (%r15),%edi
lea    0xe4f(%rip),%rsi
lea    0xe68(%rip),%rdx
mov    $0x98,%ecx
call   1030 <fprintf@plt>
mov    (%r15),%edi
call   1070 <ERR_print_errors_fp@plt>
mov    (%rbx),%rdi
call   1050 <OPENSSL_free@plt>
movq   $0x0,(%rbx)
xor    %ecx,%ecx
xor    %eax,%eax
mov    %rcx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"[ERROR] (%s:%d ) Out of memory\0A\00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/frankmorgner/openpace/refs/heads/master/src/misc.c\00"
define i32 @new_ecdh_compute_key_point(i8** %0, i64* %1, i32* %2, i32* %3) {
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 -1, i32* %9
%10 = call i8* @OPENSSL_malloc(i32 133)
%11 = load i8**, i8*** %5
store i8* %10, i8** %11
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 152)
%18 = load i32, i32* @stderr
%19 = call i32 @ERR_print_errors_fp(i32 %18)
br label %29
20: ; preds = %4
%21 = load i64*, i64** %6
store i64 133, i64* %21
%22 = load i8**, i8*** %5
%23 = load i8*, i8** %22
%24 = load i64*, i64** %6
%25 = load i64, i64* %24
%26 = load i32*, i32** %7
%27 = load i32*, i32** %8
%28 = call i32 @ecdh_compute_key_point(i8* %23, i64 %25, i32* %26, i32* %27, i32* null)
store i32 %28, i32* %9
br label %29
29: ; preds = %20, %15
%30 = load i32, i32* %9
%31 = icmp sle i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = call i32 @OPENSSL_free(i8* %34)
%36 = load i8**, i8*** %5
store i8* null, i8** %36
%37 = load i64*, i64** %6
store i64 0, i64* %37
store i32 0, i32* %9
br label %42
38: ; preds = %29
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = load i64*, i64** %6
store i64 %40, i64* %41
store i32 1, i32* %9
br label %42
42: ; preds = %38, %32
%43 = load i32, i32* %9
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"[ERROR] (%s:%d ) Out of memory\0A\00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/frankmorgner/openpace/refs/heads/master/src/misc.c\00"
define i32 @new_ecdh_compute_key_point(i8** nocapture %0, i64* nocapture writeonly %1, i32* %2, i32* %3) {
%5 = tail call i8* @OPENSSL_malloc(i32 133)
store i8* %5, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 152)
%10 = load i32, i32* @stderr
%11 = tail call i32 @ERR_print_errors_fp(i32 %10)
br label %15
12: ; preds = %4
store i64 133, i64* %1
%13 = tail call i32 @ecdh_compute_key_point(i8* %5, i64 133, i32* %2, i32* %3, i32* null)
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %7, %12
%16 = load i8*, i8** %0
%17 = tail call i32 @OPENSSL_free(i8* %16)
store i8* null, i8** %0
br label %20
18: ; preds = %12
%19 = zext i32 %13 to i64
br label %20
20: ; preds = %18, %15
%21 = phi i64 [ %19, %18 ], [ 0, %15 ]
%22 = phi i32 [ 1, %18 ], [ 0, %15 ]
store i64 %21, i64* %1
ret i32 %22
}