// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rcx, %rbp
movq %rdi, 0x20(%rsp)
movsbq (%r9), %rbx
leaq 0x60(%rsp), %r13
testq %rbx, %rbx
movq %rsi, 0x30(%rsp)
movq %rdx, 0x8(%rsp)
movl %r8d, 0x10(%rsp)
jle 0x1cb3
leaq (,%rbx,8), %r12
movq %r13, %rdi
movq %rsi, %r13
movq %r12, %rdx
callq 0x1070
leaq 0xa0(%rsp), %r14
leaq (,%rbx,8), %rsi
addq %r13, %rsi
movq %r14, %rdi
movq %rsi, 0x18(%rsp)
movq %r12, %rdx
callq 0x1070
testq %rbp, %rbp
je 0x1cd7
leaq 0xc0(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x1070
jmp 0x1cf4
leaq 0xa0(%rsp), %r14
leaq (%rsi,%rbx,8), %rax
movq %rax, 0x18(%rsp)
testq %rbp, %rbp
jne 0x1d21
movq $0x1, 0xc0(%rsp)
jmp 0x1d21
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1050
movq $0x1, (%rbp)
leaq 0x40(%rsp), %rdi
leaq 0x60(%rsp), %r13
movq %r13, %rsi
movq %r12, %rdx
callq 0x10f0
leaq 0xa0(%rsp), %rsi
leaq 0x80(%rsp), %rdi
movq %r12, %rdx
callq 0x10f0
movq %rbx, 0x38(%rsp)
leaq 0xc0(%rsp), %r12
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x3a02
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq *0xa8(%r15)
leaq 0x40(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x3a02
movl 0x10(%rsp), %eax
addl $-0x2, %eax
testw %ax, %ax
movq 0x8(%rsp), %rdi
jle 0x1e0a
movzwl %ax, %r14d
movl %r14d, %eax
shrl $0x6, %eax
movl $0x1, %edx
movl %r14d, %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), %r12
addq $0x40, %r12
leaq (%rsp,%rsi), %r13
addq $0x80, %r13
shll $0x5, %ecx
leaq (%rsp,%rcx), %rbp
addq $0x40, %rbp
leaq 0x80(%rsp,%rcx), %rbx
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x52cc
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x3817
movq 0x8(%rsp), %rdi
leal -0x1(%r14), %eax
cmpl $0x1, %r14d
movl %eax, %r14d
ja 0x1d83
movl (%rdi), %eax
andl $0x1, %eax
movl %eax, %ecx
xorl $0x1, %ecx
shll $0x5, %eax
leaq (%rsp,%rax), %rdi
addq $0x40, %rdi
movq %rdi, 0x28(%rsp)
leaq (%rsp,%rax), %r13
addq $0x80, %r13
shll $0x5, %ecx
leaq (%rsp,%rcx), %rdx
addq $0x40, %rdx
movq %rdx, 0x8(%rsp)
leaq 0x80(%rsp,%rcx), %rcx
movq %rcx, 0x10(%rsp)
movq %r13, %rsi
movq %r15, %r8
callq 0x52cc
leaq 0x8(%r15), %r12
leaq 0x100(%rsp), %r14
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movq %r12, %rcx
movq 0x38(%rsp), %rbx
movl %ebx, %r8d
callq 0x37ab
movsbl (%r15), %ecx
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x561c
movq %r14, %rdi
movq %rbp, %rsi
callq *0xc0(%r15)
movsbl (%r15), %ecx
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
callq 0x561c
movq %r14, %rdi
movq %rbp, %rsi
callq *0xc0(%r15)
movq %r14, %rdi
movq %r14, %rsi
movq %r12, %rdx
movl %ebx, %ecx
callq 0x30c7
movsbl (%r15), %ecx
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
callq 0x561c
movq %r14, %rdi
movq %r12, %rsi
callq *0xc0(%r15)
movsbl (%r15), %ecx
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq 0x28(%rsp), %rbp
movq %rbp, %rdx
callq 0x561c
movq %r14, %rdi
movq %r12, %rsi
callq *0xc0(%r15)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x3817
leaq 0x80(%rsp), %rsi
leaq 0x40(%rsp), %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x3a02
testb %bl, %bl
jle 0x1f99
movq %rbx, %r15
shlq $0x3, %rbx
leaq 0x40(%rsp), %rsi
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
callq 0x1070
leaq (%r14,%r15,8), %rdi
leaq 0x80(%rsp), %rsi
movq %rbx, %rdx
callq 0x1070
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq