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

/* Variables and functions */
int /*<<< orphan*/ BN_bn2binpad(int /*<<< orphan*/ const *, unsigned char *,
                                size_t);
size_t BN_num_bytes(int /*<<< orphan*/ const *);
int /*<<< orphan*/ EC_F_EC_POINT_BN2POINT;
int /*<<< orphan*/ EC_POINT_clear_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_POINT_new(int /*<<< orphan*/ const *);
int /*<<< orphan*/ EC_POINT_oct2point(int /*<<< orphan*/ const *,
                                      int /*<<< orphan*/ *, unsigned char *,
                                      size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ ECerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
unsigned char *OPENSSL_malloc(size_t);
EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, const BIGNUM *bn,
                            EC_POINT *point, BN_CTX *ctx) {
  size_t buf_len = 0;
  unsigned char *buf;
  EC_POINT *ret;
  if ((buf_len = BN_num_bytes(bn)) == 0)
    buf_len = 1;
  if ((buf = OPENSSL_malloc(buf_len)) == NULL) {
    ECerr(EC_F_EC_POINT_BN2POINT, ERR_R_MALLOC_FAILURE);
    return NULL;
  }
  if (!BN_bn2binpad(bn, buf, buf_len)) {
    OPENSSL_free(buf);
    return NULL;
  }
  if (point == NULL) {
    if ((ret = EC_POINT_new(group)) == NULL) {
      OPENSSL_free(buf);
      return NULL;
    }
  } else
    ret = point;
  if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) {
    if (ret != point)
      EC_POINT_clear_free(ret);
    OPENSSL_free(buf);
    return NULL;
  }
  OPENSSL_free(buf);
  return ret;
}


x86 assembly (clang, -O0):
<EC_POINT_bn2point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <BN_num_bytes@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11bf <EC_POINT_bn2point+0x3f>
movq   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <OPENSSL_malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11fa <EC_POINT_bn2point+0x7a>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1080 <ECerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    12cf <EC_POINT_bn2point+0x14f>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <BN_bn2binpad@plt>
cmp    $0x0,%eax
jne    122a <EC_POINT_bn2point+0xaa>
mov    -0x38(%rbp),%rdi
call   1090 <OPENSSL_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12cf <EC_POINT_bn2point+0x14f>
cmpq   $0x0,-0x20(%rbp)
jne    1267 <EC_POINT_bn2point+0xe7>
mov    -0x10(%rbp),%rdi
call   10a0 <EC_POINT_new@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1262 <EC_POINT_bn2point+0xe2>
mov    -0x38(%rbp),%rdi
call   1090 <OPENSSL_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12cf <EC_POINT_bn2point+0x14f>
jmp    126f <EC_POINT_bn2point+0xef>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1040 <EC_POINT_oct2point@plt>
cmp    $0x0,%eax
jne    12be <EC_POINT_bn2point+0x13e>
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     12a8 <EC_POINT_bn2point+0x128>
mov    -0x40(%rbp),%rdi
call   1030 <EC_POINT_clear_free@plt>
mov    -0x38(%rbp),%rdi
call   1090 <OPENSSL_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12cf <EC_POINT_bn2point+0x14f>
mov    -0x38(%rbp),%rdi
call   1090 <OPENSSL_free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EC_POINT_bn2point>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1070 <BN_num_bytes@plt>
test   %rax,%rax
mov    $0x1,%ebp
cmovne %rax,%rbp
mov    %rbp,%rdi
call   1060 <OPENSSL_malloc@plt>
test   %rax,%rax
je     120a <EC_POINT_bn2point+0x8a>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %rbp,%rdx
call   1050 <BN_bn2binpad@plt>
test   %eax,%eax
je     1230 <EC_POINT_bn2point+0xb0>
mov    %r12,%rbx
mov    %r14,%r12
test   %r14,%r14
jne    11e8 <EC_POINT_bn2point+0x68>
mov    %r13,%rdi
call   10a0 <EC_POINT_new@plt>
mov    %rax,%r12
test   %rax,%rax
je     1230 <EC_POINT_bn2point+0xb0>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %rbx,%r8
call   1040 <EC_POINT_oct2point@plt>
test   %eax,%eax
je     1223 <EC_POINT_bn2point+0xa3>
mov    %r15,%rdi
call   1090 <OPENSSL_free@plt>
jmp    123b <EC_POINT_bn2point+0xbb>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   1080 <ECerr@plt>
jmp    1238 <EC_POINT_bn2point+0xb8>
cmp    %r14,%r12
je     1230 <EC_POINT_bn2point+0xb0>
mov    %r12,%rdi
call   1030 <EC_POINT_clear_free@plt>
mov    %r15,%rdi
call   1090 <OPENSSL_free@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EC_F_EC_POINT_BN2POINT = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32* @EC_POINT_bn2point(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i64 0, i64* %10
%13 = load i32*, i32** %7
%14 = call i64 @BN_num_bytes(i32* %13)
store i64 %14, i64* %10
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i64 1, i64* %10
br label %17
17: ; preds = %16, %4
%18 = load i64, i64* %10
%19 = call i8* @OPENSSL_malloc(i64 %18)
store i8* %19, i8** %11
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* @EC_F_EC_POINT_BN2POINT
%23 = load i32, i32* @ERR_R_MALLOC_FAILURE
%24 = call i32 @ECerr(i32 %22, i32 %23)
store i32* null, i32** %5
br label %69
25: ; preds = %17
%26 = load i32*, i32** %7
%27 = load i8*, i8** %11
%28 = load i64, i64* %10
%29 = call i32 @BN_bn2binpad(i32* %26, i8* %27, i64 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = load i8*, i8** %11
%33 = call i32 @OPENSSL_free(i8* %32)
store i32* null, i32** %5
br label %69
34: ; preds = %25
%35 = load i32*, i32** %8
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load i32*, i32** %6
%39 = call i32* @EC_POINT_new(i32* %38)
store i32* %39, i32** %12
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i8*, i8** %11
%43 = call i32 @OPENSSL_free(i8* %42)
store i32* null, i32** %5
br label %69
44: ; preds = %37
br label %47
45: ; preds = %34
%46 = load i32*, i32** %8
store i32* %46, i32** %12
br label %47
47: ; preds = %45, %44
%48 = load i32*, i32** %6
%49 = load i32*, i32** %12
%50 = load i8*, i8** %11
%51 = load i64, i64* %10
%52 = load i32*, i32** %9
%53 = call i32 @EC_POINT_oct2point(i32* %48, i32* %49, i8* %50, i64 %51, i32* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %65, label %55
55: ; preds = %47
%56 = load i32*, i32** %12
%57 = load i32*, i32** %8
%58 = icmp ne i32* %56, %57
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32*, i32** %12
%61 = call i32 @EC_POINT_clear_free(i32* %60)
br label %62
62: ; preds = %59, %55
%63 = load i8*, i8** %11
%64 = call i32 @OPENSSL_free(i8* %63)
store i32* null, i32** %5
br label %69
65: ; preds = %47
%66 = load i8*, i8** %11
%67 = call i32 @OPENSSL_free(i8* %66)
%68 = load i32*, i32** %12
store i32* %68, i32** %5
br label %69
69: ; preds = %65, %62, %41, %31, %21
%70 = load i32*, i32** %5
ret i32* %70
}

LLVM IR (-O2):
@EC_F_EC_POINT_BN2POINT = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32* @EC_POINT_bn2point(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = tail call i64 @BN_num_bytes(i32* %1)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i64 1, i64 %5
%8 = tail call i8* @OPENSSL_malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = load i32, i32* @EC_F_EC_POINT_BN2POINT
%12 = load i32, i32* @ERR_R_MALLOC_FAILURE
%13 = tail call i32 @ECerr(i32 %11, i32 %12)
br label %38
14: ; preds = %4
%15 = tail call i32 @BN_bn2binpad(i32* %1, i8* %8, i64 %7)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @OPENSSL_free(i8* %8)
br label %38
19: ; preds = %14
%20 = icmp eq i32* %2, null
br i1 %20, label %21, label %26
21: ; preds = %19
%22 = tail call i32* @EC_POINT_new(i32* %0)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @OPENSSL_free(i8* %8)
br label %38
26: ; preds = %19, %21
%27 = phi i32* [ %22, %21 ], [ %2, %19 ]
%28 = tail call i32 @EC_POINT_oct2point(i32* %0, i32* %27, i8* %8, i64 %7, i32* %3)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = icmp eq i32* %27, %2
br i1 %31, label %34, label %32
32: ; preds = %30
%33 = tail call i32 @EC_POINT_clear_free(i32* %27)
br label %34
34: ; preds = %32, %30
%35 = tail call i32 @OPENSSL_free(i8* %8)
br label %38
36: ; preds = %26
%37 = tail call i32 @OPENSSL_free(i8* %8)
br label %38
38: ; preds = %36, %34, %24, %17, %10
%39 = phi i32* [ null, %10 ], [ null, %24 ], [ %27, %36 ], [ null, %34 ], [ null, %17 ]
ret i32* %39
}