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

/* Variables and functions */
scalar_t__ BN_is_bit_set(int /*<<< orphan*/ const *, int);
int BN_num_bits(int /*<<< orphan*/ const *);
int /*<<< orphan*/ EC_POINT_add(int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_POINT_dbl(int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ const *,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ const *EC_POINT_new(int /*<<< orphan*/ const *);
EC_POINT *EC_POINT_mult_BN(const EC_GROUP *group, EC_POINT *P,
                           const EC_POINT *a, const BIGNUM *b, BN_CTX *ctx) {
  EC_POINT *O = EC_POINT_new(group);
  if (P == NULL)
    P = EC_POINT_new(group);
  for (int i = BN_num_bits(b); i >= 0; i--) {
    EC_POINT_dbl(group, P, P, ctx);
    if (BN_is_bit_set(b, i))
      EC_POINT_add(group, P, P, a, ctx);
    else
      EC_POINT_add(group, P, P, O, ctx);
  }
  return P;
}


x86 assembly (clang, -O0):
<EC_POINT_mult_BN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <EC_POINT_new@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1191 <EC_POINT_mult_BN+0x41>
mov    -0x8(%rbp),%rdi
call   1070 <EC_POINT_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <BN_num_bits@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     121c <EC_POINT_mult_BN+0xcc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <EC_POINT_dbl@plt>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <BN_is_bit_set@plt>
cmp    $0x0,%rax
je     11f0 <EC_POINT_mult_BN+0xa0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1060 <EC_POINT_add@plt>
jmp    1209 <EC_POINT_mult_BN+0xb9>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1060 <EC_POINT_add@plt>
jmp    120e <EC_POINT_mult_BN+0xbe>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    119d <EC_POINT_mult_BN+0x4d>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EC_POINT_mult_BN>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r12
mov    %rcx,%rbp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r13
call   1070 <EC_POINT_new@plt>
mov    %rax,0x8(%rsp)
test   %rbx,%rbx
jne    1187 <EC_POINT_mult_BN+0x37>
mov    %r13,%rdi
call   1070 <EC_POINT_new@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <BN_num_bits@plt>
mov    %rbp,0x10(%rsp)
test   %eax,%eax
mov    0x8(%rsp),%rbp
js     11e5 <EC_POINT_mult_BN+0x95>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1040 <EC_POINT_dbl@plt>
mov    0x10(%rsp),%rdi
mov    %r15d,%esi
call   1050 <BN_is_bit_set@plt>
test   %rax,%rax
mov    %r14,%rcx
cmove  %rbp,%rcx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
mov    %r12,%r8
call   1060 <EC_POINT_add@plt>
lea    -0x1(%r15),%eax
test   %r15d,%r15d
mov    %eax,%r15d
jg     11a0 <EC_POINT_mult_BN+0x50>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @EC_POINT_mult_BN(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%13 = load i32*, i32** %6
%14 = call i32* @EC_POINT_new(i32* %13)
store i32* %14, i32** %11
%15 = load i32*, i32** %7
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %5
%18 = load i32*, i32** %6
%19 = call i32* @EC_POINT_new(i32* %18)
store i32* %19, i32** %7
br label %20
20: ; preds = %17, %5
%21 = load i32*, i32** %9
%22 = call i32 @BN_num_bits(i32* %21)
store i32 %22, i32* %12
br label %23
23: ; preds = %51, %20
%24 = load i32, i32* %12
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %54
26: ; preds = %23
%27 = load i32*, i32** %6
%28 = load i32*, i32** %7
%29 = load i32*, i32** %7
%30 = load i32*, i32** %10
%31 = call i32 @EC_POINT_dbl(i32* %27, i32* %28, i32* %29, i32* %30)
%32 = load i32*, i32** %9
%33 = load i32, i32* %12
%34 = call i64 @BN_is_bit_set(i32* %32, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %26
%37 = load i32*, i32** %6
%38 = load i32*, i32** %7
%39 = load i32*, i32** %7
%40 = load i32*, i32** %8
%41 = load i32*, i32** %10
%42 = call i32 @EC_POINT_add(i32* %37, i32* %38, i32* %39, i32* %40, i32* %41)
br label %50
43: ; preds = %26
%44 = load i32*, i32** %6
%45 = load i32*, i32** %7
%46 = load i32*, i32** %7
%47 = load i32*, i32** %11
%48 = load i32*, i32** %10
%49 = call i32 @EC_POINT_add(i32* %44, i32* %45, i32* %46, i32* %47, i32* %48)
br label %50
50: ; preds = %43, %36
br label %51
51: ; preds = %50
%52 = load i32, i32* %12
%53 = add nsw i32 %52, -1
store i32 %53, i32* %12
br label %23
54: ; preds = %23
%55 = load i32*, i32** %7
ret i32* %55
}

LLVM IR (-O2):
define i32* @EC_POINT_mult_BN(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = tail call i32* @EC_POINT_new(i32* %0)
%7 = icmp eq i32* %1, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32* @EC_POINT_new(i32* %0)
br label %10
10: ; preds = %8, %5
%11 = phi i32* [ %9, %8 ], [ %1, %5 ]
%12 = tail call i32 @BN_num_bits(i32* %3)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %15, label %14
14: ; preds = %15, %10
ret i32* %11
15: ; preds = %10, %15
%16 = phi i32 [ %22, %15 ], [ %12, %10 ]
%17 = tail call i32 @EC_POINT_dbl(i32* %0, i32* %11, i32* %11, i32* %4)
%18 = tail call i64 @BN_is_bit_set(i32* %3, i32 %16)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32* %6, i32* %2
%21 = tail call i32 @EC_POINT_add(i32* %0, i32* %11, i32* %11, i32* %20, i32* %4)
%22 = add nsw i32 %16, -1
%23 = icmp sgt i32 %16, 0
br i1 %23, label %15, label %14
}