// File: /workspace/github_cpp_makefile_star2_O1/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 $0x128, %rsp            # imm = 0x128
movq %r9, %r15
movl %r8d, %r12d
movq %rcx, %rbp
movq %rdx, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
movsbq (%r9), %rbx
leaq 0x60(%rsp), %rdi
testq %rbx, %rbx
jle 0x1c81
leaq (,%rbx,8), %rdx
movq %r14, %rsi
callq 0x1070
leaq 0xa0(%rsp), %r13
movq %r14, 0x28(%rsp)
leaq (%r14,%rbx,8), %r14
testb %bl, %bl
jle 0x1ca9
leaq (,%rbx,8), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x1070
testq %rbp, %rbp
je 0x1ccc
testb %bl, %bl
jle 0x1d24
leaq (,%rbx,8), %rdx
leaq 0xc0(%rsp), %rdi
movq %rbp, %rsi
callq 0x1070
jmp 0x1cf3
testb %bl, %bl
jle 0x1ce7
leaq (,%rbx,8), %rdx
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0x1050
movq $0x1, 0xc0(%rsp)
testb %bl, %bl
jle 0x1d24
leaq (,%rbx,8), %rbp
leaq 0x40(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq %rbp, %rdx
callq 0x10f0
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x10f0
movq %r14, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
leaq 0xc0(%rsp), %rbp
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x3b5b
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq *0xa8(%r15)
leaq 0x40(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x3b5b
addl $-0x2, %r12d
testw %r12w, %r12w
movq 0x8(%rsp), %rdi
jle 0x1e16
movzwl %r12w, %r12d
movl %r12d, %eax
shrl $0x6, %eax
movl $0x1, %edx
movl %r12d, %ecx
shlq %cl, %rdx
xorl %ecx, %ecx
xorl %esi, %esi
testq %rdx, (%rdi,%rax,8)
sete %cl
setne %sil
shll $0x5, %esi
leaq (%rsp,%rsi), %r13
addq $0x40, %r13
leaq (%rsp,%rsi), %rbp
addq $0x80, %rbp
shll $0x5, %ecx
leaq (%rsp,%rcx), %rbx
addq $0x40, %rbx
leaq 0x80(%rsp,%rcx), %r14
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x549a
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0x3970
movq 0x8(%rsp), %rdi
leal -0x1(%r12), %eax
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x1d8e
movl (%rdi), %eax
andl $0x1, %eax
movl %eax, %ecx
xorl $0x1, %ecx
shll $0x5, %eax
leaq (%rsp,%rax), %rdi
addq $0x40, %rdi
movq %rdi, 0x18(%rsp)
leaq (%rsp,%rax), %r12
addq $0x80, %r12
shll $0x5, %ecx
leaq (%rsp,%rcx), %rdx
addq $0x40, %rdx
movq %rdx, 0x8(%rsp)
leaq 0x80(%rsp,%rcx), %rcx
movq %rcx, 0x20(%rsp)
movq %r12, %rsi
movq %r15, %r8
callq 0x549a
leaq 0x8(%r15), %rbp
leaq 0x100(%rsp), %r13
leaq 0x40(%rsp), %rdx
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
movq %rbp, %rcx
movq 0x38(%rsp), %r14
movl %r14d, %r8d
callq 0x38f2
movsbl (%r15), %ecx
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x5802
movq %r13, %rdi
movq %rbx, %rsi
callq *0xc0(%r15)
movsbl (%r15), %ecx
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq 0x28(%rsp), %rdx
callq 0x5802
movq %r13, %rdi
movq %rbx, %rsi
callq *0xc0(%r15)
movq %r13, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movl %r14d, %ecx
callq 0x316a
movsbl (%r15), %ecx
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
callq 0x5802
movq %r13, %rdi
movq %rbx, %rsi
callq *0xc0(%r15)
movsbl (%r15), %ecx
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rbp
movq %rbp, %rdx
callq 0x5802
movq %r13, %rdi
movq %rbx, %rsi
callq *0xc0(%r15)
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbp, %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x3970
leaq 0x80(%rsp), %rsi
leaq 0x40(%rsp), %rdi
movq %r13, %rdx
movq %r15, %rcx
callq 0x3b5b
testb %r14b, %r14b
jle 0x1fa9
leaq (,%r14,8), %rdx
leaq 0x40(%rsp), %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x1070
leaq (%rbx,%r14,8), %rdi
movzbl %r14b, %edx
shll $0x3, %edx
leaq 0x80(%rsp), %rsi
callq 0x1070
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq