// File: /workspace/github_c_makefile_star2_O1/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 $0x3f8, %rsp            # imm = 0x3F8
movq %rdx, 0x20(%rsp)
movq %rsi, 0x8(%rsp)
cmpq $0x2, %rcx
jbe 0x3064
movq %rdi, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
testb $0x1, %cl
je 0x3083
movq 0x20(%rsp), %r14
vmovups 0x40(%r14), %ymm0
leaq 0x40(%r14), %r13
vmovups 0x60(%r14), %ymm1
leaq 0x170(%rsp), %rax
vmovups %ymm1, -0x20(%rax)
vmovups %ymm0, -0x40(%rax)
vmovups (%r14), %ymm0
vmovups 0x20(%r14), %ymm1
vmovups %ymm1, 0x20(%rax)
vmovups %ymm0, (%rax)
movl $0x80, %edx
leaq 0x130(%rsp), %rcx
vmovups (%r14), %ymm0
vmovups 0x20(%r14), %ymm1
vmovups %ymm0, 0x40(%rax)
addq %rdx, %rcx
movq %rcx, 0x28(%rsp)
vmovups %ymm1, 0x60(%rax)
leaq 0x1f0(%rsp), %rax
vmovups 0x40(%r14), %ymm0
vmovups %ymm0, (%rax)
vmovups 0x60(%r14), %ymm0
vmovups %ymm0, 0x20(%rax)
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
vzeroupper
callq 0x1609
leaq 0x40(%rbx), %rbp
leaq 0xf0(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1609
movq %r15, %rdi
movq %r12, %rsi
callq 0x15e6
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x1609
movq %r12, %rdi
movq %rbp, 0x30(%rsp)
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1609
movq %r15, %rdi
movq %r12, %rsi
callq 0x15e6
vmovups (%r14), %ymm0
vmovups 0x20(%r14), %ymm1
vmovups 0x40(%r14), %ymm2
vmovups 0x60(%r14), %ymm3
leaq 0x270(%rsp), %r15
vmovups %ymm3, 0x60(%r15)
vmovups %ymm2, 0x40(%r15)
vmovups %ymm1, 0x20(%r15)
vmovups %ymm0, (%r15)
movl $0x80, %eax
leaq (%r15,%rax), %rdi
vxorps %xmm0, %xmm0, %xmm0
vmovups %ymm0, 0x80(%r15)
vmovups %ymm0, 0xa0(%r15)
vmovups %ymm0, 0xc0(%r15)
vmovups %ymm0, 0xe0(%r15)
vmovups %ymm0, 0x100(%r15)
vmovups %ymm0, 0x120(%r15)
vmovups %ymm0, 0x140(%r15)
vmovups %ymm0, 0x160(%r15)
movq 0x18(%rsp), %rsi
movq %r14, %rdx
vzeroupper
callq 0x26c4
movq 0x10(%rsp), %rcx
cmpq $0x3, %rcx
je 0x2f23
shrq %rcx
cmpq $0x3, %rcx
movl $0x2, %eax
cmovaeq %rcx, %rax
movq %rax, 0x40(%rsp)
leaq 0x330(%rsp), %r13
leaq 0x2f0(%rsp), %r14
movl $0x1, %r8d
movq $-0x1, %rsi
leaq 0x1f0(%rsp), %rax
movq %rax, 0x38(%rsp)
xorl %ecx, %ecx
movq %r8, %rdx
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
mulxq %rdi, %rax, %rax
shlq $0x6, %rax
andq $-0x80, %rax
leaq (%rax,%rax,2), %rbx
movq %r14, 0x60(%rsp)
subq %rbx, %r14
movq %rcx, 0x50(%rsp)
movq %rcx, %rdx
mulxq %rdi, %rcx, %rcx
movq %rsi, 0x58(%rsp)
movq %rsi, %rdx
mulxq %rdi, %rax, %rax
movq %r8, 0x48(%rsp)
cmpq $0x2, %r8
jb 0x2dc0
shlq $0x6, %rcx
andq $-0x80, %rcx
leaq (%rcx,%rcx,2), %rcx
movq %r15, %rsi
subq %rcx, %rsi
shlq $0x6, %rax
andq $-0x80, %rax
leaq (%rax,%rax,2), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
movq %r14, %rdi
movq 0x20(%rsp), %rdx
callq 0x27b4
movq %r15, 0x10(%rsp)
movq %r13, %r15
subq %rbx, %r15
leaq 0xf0(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
leaq 0x130(%rsp), %rdx
callq 0x1609
leaq 0x230(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
leaq 0x170(%rsp), %rbx
movq %rbx, %rdx
callq 0x1609
leaq 0x130(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x1553
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21e2
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, 0x68(%rsp)
movq 0x28(%rsp), %r13
movq %r13, %rdx
callq 0x1609
movq %r12, %rdi
movq %r14, %rsi
leaq 0x1f0(%rsp), %rbx
movq %rbx, %rdx
callq 0x1609
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x1553
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21e2
movq %rbp, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1609
movq %r12, %rdi
movq 0x30(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
callq 0x1609
movq %rbp, %rdi
movq %r12, %rsi
callq 0x15e6
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x21e2
movq %rbp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq 0x10(%rsp), %r15
callq 0x1609
movq %r12, %rdi
movq %r13, %rsi
movq 0x68(%rsp), %r13
movq %r14, %rdx
callq 0x1609
movq %rbp, %rdi
movq %r12, %rsi
callq 0x15e6
leaq 0xb0(%rsp), %rdi
movq %rbp, %rsi
callq 0x21e2
movq 0x48(%rsp), %r8
incq %r8
movl $0x80, %eax
addq %rax, %r13
movq 0x60(%rsp), %r14
addq %rax, %r14
addq %rax, %r15
movq 0x50(%rsp), %rcx
incq %rcx
addq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rsi
incq %rsi
cmpq %r8, 0x40(%rsp)
jne 0x2d42
leaq 0x130(%rsp), %r15
movq %r15, %rdi
leaq 0x170(%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 0x1f0(%rsp), %r13
movq %r13, %rsi
callq 0x21e2
movq %r14, %rdi
movq %r14, %rsi
callq 0x155f
movq %r13, %rdi
callq 0x21f2
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1609
leaq 0x230(%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 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x21f2
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
callq 0x21f2
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x21e2
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x21e2
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11ba(%rip), %rdi      # 0x4225
leaq 0x11ba(%rip), %rsi      # 0x422c
leaq 0x11ba(%rip), %rcx      # 0x4233
movl $0x6d, %edx
callq 0x1050
leaq 0x11dc(%rip), %rdi      # 0x4266
leaq 0x119b(%rip), %rsi      # 0x422c
leaq 0x119b(%rip), %rcx      # 0x4233
movl $0x6e, %edx
callq 0x1050
nop