// File: /workspace/github_c_makefile_star2_O3/ioerror[P]csidh-reference-implementation/mont.c
// Function: xISOG
void xISOG(proj *A, proj *P, proj const *K, uint64_t k)
{
    assert (k >= 3);
    assert (k % 2 == 1);

    fp tmp0, tmp1;
    fp T[4] = {K->z, K->x, K->x, K->z};
    proj Q;

    fp_mul3(&Q.x,  &P->x, &K->x);
    fp_mul3(&tmp0, &P->z, &K->z);
    fp_sub2(&Q.x,  &tmp0);

    fp_mul3(&Q.z,  &P->x, &K->z);
    fp_mul3(&tmp0, &P->z, &K->x);
    fp_sub2(&Q.z,  &tmp0);

    proj M[3] = {*K};
    xDBL(&M[1], A, K);

    for (uint64_t i = 1; i < k / 2; ++i) {

        if (i >= 2)
            xADD(&M[i % 3], &M[(i - 1) % 3], K, &M[(i - 2) % 3]);

        fp_mul3(&tmp0, &M[i % 3].x, &T[0]);
        fp_mul3(&tmp1, &M[i % 3].z, &T[1]);
        fp_add3(&T[0], &tmp0, &tmp1);

        fp_mul2(&T[1], &M[i % 3].x);

        fp_mul3(&tmp0, &M[i % 3].z, &T[2]);
        fp_mul3(&tmp1, &M[i % 3].x, &T[3]);
        fp_add3(&T[2], &tmp0, &tmp1);

        fp_mul2(&T[3], &M[i % 3].z);


        fp_mul3(&tmp0, &P->x, &M[i % 3].x);
        fp_mul3(&tmp1, &P->z, &M[i % 3].z);
        fp_sub2(&tmp0, &tmp1);
        fp_mul2(&Q.x,  &tmp0);

        fp_mul3(&tmp0, &P->x, &M[i % 3].z);
        fp_mul3(&tmp1, &P->z, &M[i % 3].x);
        fp_sub2(&tmp0, &tmp1);
        fp_mul2(&Q.z,  &tmp0);
    }

    fp_mul2(&T[0], &T[1]);
    fp_add2(&T[0], &T[0]); /* multiplication by 2 */

    fp_sq1(&T[1]);

    fp_mul2(&T[2], &T[3]);
    fp_add2(&T[2], &T[2]); /* multiplication by 2 */

    fp_sq1(&T[3]);

    /* Ax := T[1] * T[3] * Ax - 3 * Az * (T[1] * T[2] - T[0] * T[3]) */
    fp_mul3(&tmp0, &T[1], &T[2]);
    fp_mul3(&tmp1, &T[0], &T[3]);
    fp_sub2(&tmp0, &tmp1);
    fp_mul2(&tmp0, &A->z);
    fp_add3(&tmp1, &tmp0, &tmp0); fp_add2(&tmp0, &tmp1); /* multiplication by 3 */

    fp_mul3(&tmp1, &T[1], &T[3]);
    fp_mul2(&tmp1, &A->x);

    fp_sub3(&A->x, &tmp1, &tmp0);

    /* Az := Az * T[3]^2 */
    fp_sq1(&T[3]);
    fp_mul2(&A->z, &T[3]);

    /* X := X * Xim^2, Z := Z * Zim^2 */
    fp_sq1(&Q.x);
    fp_sq1(&Q.z);
    fp_mul2(&P->x, &Q.x);
    fp_mul2(&P->z, &Q.z);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3e8, %rsp            # imm = 0x3E8
movq %rdx, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
cmpq $0x2, %rcx
jbe 0x3070
movq %rdi, 0x18(%rsp)
testb $0x1, %cl
movq %rcx, 0x8(%rsp)
je 0x308f
movq 0x20(%rsp), %r13
vmovups 0x40(%r13), %ymm0
leaq 0x40(%r13), %rbx
vmovups 0x60(%r13), %ymm1
leaq 0x1a0(%rsp), %rax
vmovups %ymm1, -0x20(%rax)
vmovups %ymm0, -0x40(%rax)
vmovups (%r13), %ymm0
vmovups 0x20(%r13), %ymm1
vmovups %ymm1, 0x20(%rax)
vmovups %ymm0, (%rax)
movl $0x80, %edx
leaq 0x160(%rsp), %rcx
vmovups (%r13), %ymm0
vmovups 0x20(%r13), %ymm1
vmovups %ymm0, 0x40(%rax)
addq %rdx, %rcx
movq %rcx, 0x28(%rsp)
vmovups %ymm1, 0x60(%rax)
leaq 0x220(%rsp), %rax
vmovups 0x40(%r13), %ymm0
vmovups %ymm0, (%rax)
vmovups 0x60(%r13), %ymm0
vmovups %ymm0, 0x20(%rax)
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %r12
movq %r12, %rsi
movq %r13, %rdx
vzeroupper
callq 0x1609
leaq 0x40(%r12), %rbp
leaq 0x120(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x1609
movq %r14, %rdi
movq %r15, %rsi
callq 0x15e6
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x1609
movq %r15, %rdi
movq %rbp, 0x30(%rsp)
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1609
movq %r14, %rdi
movq %r15, %rsi
callq 0x15e6
vmovups (%r13), %ymm0
vmovups 0x20(%r13), %ymm1
vmovups 0x40(%r13), %ymm2
vmovups 0x60(%r13), %ymm3
leaq 0x260(%rsp), %rbx
vmovups %ymm3, 0x60(%rbx)
vmovups %ymm2, 0x40(%rbx)
vmovups %ymm1, 0x20(%rbx)
vmovups %ymm0, (%rbx)
movl $0x80, %eax
leaq (%rbx,%rax), %rdi
vxorps %xmm0, %xmm0, %xmm0
vmovups %ymm0, 0x80(%rbx)
vmovups %ymm0, 0xa0(%rbx)
vmovups %ymm0, 0xc0(%rbx)
vmovups %ymm0, 0xe0(%rbx)
vmovups %ymm0, 0x100(%rbx)
vmovups %ymm0, 0x120(%rbx)
vmovups %ymm0, 0x140(%rbx)
vmovups %ymm0, 0x160(%rbx)
movq 0x18(%rsp), %rsi
movq %r13, %rdx
vzeroupper
callq 0x26c4
movq 0x8(%rsp), %rax
cmpq $0x3, %rax
je 0x2f2f
shrq %rax
leaq 0x2e0(%rsp), %r14
movl $0x1, %r13d
movq $-0x1, %rdi
leaq 0x1e0(%rsp), %rbp
xorl %ecx, %ecx
movq %rax, 0x8(%rsp)
movq %r13, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
mulxq %rax, %rsi, %rsi
movq %rcx, 0x38(%rsp)
movq %rcx, %rdx
mulxq %rax, %rcx, %rcx
movq %rdi, 0x48(%rsp)
movq %rdi, %rdx
mulxq %rax, %rax, %rax
movq %r13, %r15
cmpq $0x2, %r13
jb 0x2dac
shlq $0x6, %rsi
andq $-0x80, %rsi
leaq (%rsi,%rsi,2), %rdx
movq %r14, %rdi
subq %rdx, %rdi
shlq $0x6, %rcx
andq $-0x80, %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rbx, %rsi
subq %rcx, %rsi
shlq $0x6, %rax
andq $-0x80, %rax
leaq (%rax,%rax,2), %rax
movq %rbp, %rcx
subq %rax, %rcx
movq %r13, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
mulxq %rax, %rax, %rax
shrq %rax
leaq (%rax,%rax,2), %rax
movq %r13, %r15
subq %rax, %r15
movq 0x20(%rsp), %rdx
callq 0x27b4
shlq $0x7, %r15
movq %r14, 0x50(%rsp)
leaq (%rsp,%r15), %r14
addq $0x260, %r14            # imm = 0x260
leaq 0x120(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
leaq 0x160(%rsp), %rdx
callq 0x1609
addq %rsp, %r15
addq $0x2a0, %r15            # imm = 0x2A0
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
movq %rbx, 0x58(%rsp)
leaq 0x1a0(%rsp), %rdx
callq 0x1609
leaq 0x160(%rsp), %rdi
movq %r12, %rsi
leaq 0x60(%rsp), %rbx
movq %rbx, %rdx
callq 0x1553
leaq 0x1a0(%rsp), %rdi
movq %r14, %rsi
callq 0x21e2
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, 0x40(%rsp)
movq 0x28(%rsp), %rbp
movq %rbp, %rdx
callq 0x1609
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x220(%rsp), %rbx
movq %rbx, %rdx
callq 0x1609
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x60(%rsp), %rbp
movq %rbp, %rdx
callq 0x1553
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21e2
movq %r12, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1609
movq %rbp, %rdi
movq 0x30(%rsp), %rbp
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1609
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
callq 0x15e6
leaq 0xa0(%rsp), %rdi
movq %r12, %rsi
callq 0x21e2
movq %r12, %rdi
movq %rbx, %rsi
movq 0x58(%rsp), %rbx
movq %r15, %rdx
callq 0x1609
leaq 0x60(%rsp), %rdi
movq %rbp, %rsi
movq 0x40(%rsp), %rbp
movq %r14, %rdx
movq 0x50(%rsp), %r14
callq 0x1609
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
callq 0x15e6
leaq 0xe0(%rsp), %rdi
movq %r12, %rsi
callq 0x21e2
incq %r13
movl $0x80, %eax
addq %rax, %r14
addq %rax, %rbx
movq 0x38(%rsp), %rcx
incq %rcx
addq %rax, %rbp
movq 0x48(%rsp), %rdi
incq %rdi
movq 0x8(%rsp), %rax
cmpq %r13, %rax
jne 0x2d18
leaq 0x160(%rsp), %r15
movq %r15, %rdi
leaq 0x1a0(%rsp), %rbp
movq %rbp, %rsi
callq 0x21e2
movq %r15, %rdi
movq %r15, %rsi
callq 0x155f
movq %rbp, %rdi
callq 0x21f2
movq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0x220(%rsp), %r13
movq %r13, %rsi
callq 0x21e2
movq %r14, %rdi
movq %r14, %rsi
callq 0x155f
movq %r13, %rdi
callq 0x21f2
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1609
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1609
movq %rbx, %rdi
movq %r14, %rsi
callq 0x15e6
movq 0x18(%rsp), %r12
leaq 0x40(%r12), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21e2
movq %r14, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x1553
movq %rbx, %rdi
movq %r14, %rsi
callq 0x155f
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1609
movq %r14, %rdi
movq %r12, %rsi
callq 0x21e2
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1567
movq %r13, %rdi
callq 0x21f2
movq %r15, %rdi
movq %r13, %rsi
callq 0x21e2
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
callq 0x21f2
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
callq 0x21f2
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x21e2
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x21e2
addq $0x3e8, %rsp            # imm = 0x3E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11ae(%rip), %rdi      # 0x4225
leaq 0x11ae(%rip), %rsi      # 0x422c
leaq 0x11ae(%rip), %rcx      # 0x4233
movl $0x6d, %edx
callq 0x1050
leaq 0x11d0(%rip), %rdi      # 0x4266
leaq 0x118f(%rip), %rsi      # 0x422c
leaq 0x118f(%rip), %rcx      # 0x4233
movl $0x6e, %edx
callq 0x1050
nop