// File: /workspace/github_cpp_makefile_star2_O2/simap[P]ecctools/lib/uECC.c
// Function: EccPoint_mult(unsigned long*, unsigned long const*, unsigned long const*, unsigned long const*, short, uECC_Curve_t const*)
static void EccPoint_mult(uECC_word_t * result,
                          const uECC_word_t * point,
                          const uECC_word_t * scalar,
                          const uECC_word_t * initial_Z,
                          bitcount_t num_bits,
                          uECC_Curve curve) {
    /* R0 and R1 */
    uECC_word_t Rx[2][uECC_MAX_WORDS];
    uECC_word_t Ry[2][uECC_MAX_WORDS];
    uECC_word_t z[uECC_MAX_WORDS];
    bitcount_t i;
    uECC_word_t nb;
    wordcount_t num_words = curve->num_words;

    uECC_vli_set(Rx[1], point, num_words);
    uECC_vli_set(Ry[1], point + num_words, num_words);

    XYcZ_initial_double(Rx[1], Ry[1], Rx[0], Ry[0], initial_Z, curve);

    for (i = num_bits - 2; i > 0; --i) {
        nb = !uECC_vli_testBit(scalar, i);
        XYcZ_addC(Rx[1 - nb], Ry[1 - nb], Rx[nb], Ry[nb], curve);
        XYcZ_add(Rx[nb], Ry[nb], Rx[1 - nb], Ry[1 - nb], curve);
    }

    nb = !uECC_vli_testBit(scalar, 0);
    XYcZ_addC(Rx[1 - nb], Ry[1 - nb], Rx[nb], Ry[nb], curve);

    /* Find final 1/Z value. */
    uECC_vli_modSub(z, Rx[1], Rx[0], curve->p, num_words); /* X1 - X0 */
    uECC_vli_modMult_fast(z, z, Ry[1 - nb], curve);               /* Yb * (X1 - X0) */
    uECC_vli_modMult_fast(z, z, point, curve);                    /* xP * Yb * (X1 - X0) */
    uECC_vli_modInv(z, z, curve->p, num_words);            /* 1 / (xP * Yb * (X1 - X0)) */
    /* yP / (xP * Yb * (X1 - X0)) */
    uECC_vli_modMult_fast(z, z, point + num_words, curve);
    uECC_vli_modMult_fast(z, z, Rx[1 - nb], curve); /* Xb * yP / (xP * Yb * (X1 - X0)) */
    /* End 1/Z calculation */

    XYcZ_add(Rx[nb], Ry[nb], Rx[1 - nb], Ry[1 - nb], curve);
    apply_z(Rx[0], Ry[0], z, curve);

    uECC_vli_set(result, Rx[0], num_words);
    uECC_vli_set(result + num_words, Ry[0], num_words);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, %r15
movl %r8d, %r12d
movq %rcx, %rbp
movq %rdx, (%rsp)
movq %rsi, %r14
movq %rdi, 0x20(%rsp)
movsbq (%r9), %rbx
leaq 0x50(%rsp), %rdi
movl %ebx, %edx
callq 0x3017
leaq 0xb0(%rsp), %r13
movq %r14, 0x10(%rsp)
leaq (%r14,%rbx,8), %rsi
movq %r13, %rdi
movq %rsi, 0x18(%rsp)
movl %ebx, %edx
callq 0x3017
testq %rbp, %rbp
je 0x1b24
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0x3017
jmp 0x1b3b
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movl %ebx, %esi
callq 0x3272
movq $0x1, (%rbp)
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %r14
movq %r14, %rsi
movl %ebx, %edx
callq 0x3017
leaq 0x90(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %rbx, 0x28(%rsp)
movl %ebx, %edx
callq 0x3017
movq %r13, %rbx
leaq 0x70(%rsp), %r13
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x31b8
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq *0xa8(%r15)
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x31b8
addl $-0x2, %r12d
movzwl %r12w, %ebp
testw %bp, %bp
jle 0x1c2a
movl %ebp, %eax
shrl $0x6, %eax
pushq $0x1
popq %rdx
movl %ebp, %ecx
shlq %cl, %rdx
xorl %ecx, %ecx
xorl %esi, %esi
movq (%rsp), %rdi
testq %rdx, (%rdi,%rax,8)
sete %cl
setne %sil
shll $0x5, %esi
leaq (%rsp,%rsi), %r12
addq $0x30, %r12
leaq (%rsp,%rsi), %r13
addq $0x90, %r13
shll $0x5, %ecx
leaq (%rsp,%rcx), %rbx
addq $0x30, %rbx
leaq 0x90(%rsp,%rcx), %r14
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x441e
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x3069
decl %ebp
jmp 0x1bb0
movq (%rsp), %rax
movl (%rax), %eax
andl $0x1, %eax
movl %eax, %ecx
xorl $0x1, %ecx
shll $0x5, %eax
leaq (%rsp,%rax), %r14
addq $0x30, %r14
leaq (%rsp,%rax), %r12
addq $0x90, %r12
shll $0x5, %ecx
leaq (%rsp,%rcx), %rdx
addq $0x30, %rdx
movq %rdx, (%rsp)
leaq 0x90(%rsp,%rcx), %rcx
movq %rcx, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %r8
callq 0x441e
leaq 0x8(%r15), %rbx
leaq 0x70(%rsp), %r13
leaq 0x30(%rsp), %rdx
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
movq %rbx, %rcx
movq 0x28(%rsp), %rbp
movl %ebp, %r8d
callq 0x3034
movq %r13, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x328d
movq %r13, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x328d
movq %r13, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
callq 0x2bfb
movq %r13, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
callq 0x328d
movq %r13, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x328d
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x3069
leaq 0x90(%rsp), %rbx
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x31b8
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x3017
leaq (%r14,%rbp,8), %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x3017
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq