// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
cmpq $0x2, %rcx
jbe 0x302a
movq %rdi, 0x10(%rsp)
testb $0x1, %cl
movq %rcx, (%rsp)
je 0x3043
movq 0x18(%rsp), %rbp
vmovups 0x40(%rbp), %ymm0
leaq 0x40(%rbp), %rbx
vmovups 0x60(%rbp), %ymm1
leaq 0x160(%rsp), %rax
vmovups %ymm1, -0x20(%rax)
vmovups %ymm0, -0x40(%rax)
vmovups (%rbp), %ymm0
vmovups 0x20(%rbp), %ymm1
vmovups %ymm1, 0x20(%rax)
vmovups %ymm0, (%rax)
movl $0x80, %edx
leaq 0x120(%rsp), %rcx
vmovups (%rbp), %ymm0
vmovups 0x20(%rbp), %ymm1
vmovups %ymm0, 0x40(%rax)
leaq (%rcx,%rdx), %rcx
movq %rcx, 0x20(%rsp)
vmovups %ymm1, 0x60(%rax)
leaq 0x1e0(%rsp), %rax
vmovups 0x40(%rbp), %ymm0
vmovups %ymm0, (%rax)
vmovups 0x60(%rbp), %ymm0
vmovups %ymm0, 0x20(%rax)
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movq %rbp, %rdx
vzeroupper
callq 0x1609
leaq 0x40(%r14), %r13
leaq 0xe0(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x1609
movq %r12, %rdi
movq %r15, %rsi
callq 0x15e6
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1609
movq %r15, %rdi
movq %r13, 0x28(%rsp)
movq %r13, %rsi
movq %rbp, %rdx
callq 0x1609
movq %r12, %rdi
movq %r15, %rsi
callq 0x15e6
vmovups (%rbp), %ymm0
vmovups 0x20(%rbp), %ymm1
vmovups 0x40(%rbp), %ymm2
vmovups 0x60(%rbp), %ymm3
leaq 0x260(%rsp), %r14
vmovups %ymm3, 0x60(%r14)
vmovups %ymm2, 0x40(%r14)
vmovups %ymm1, 0x20(%r14)
vmovups %ymm0, (%r14)
movl $0x80, %eax
leaq (%r14,%rax), %r12
vxorps %xmm0, %xmm0, %xmm0
vmovups %ymm0, 0x80(%r14)
vmovups %ymm0, 0xa0(%r14)
vmovups %ymm0, 0xc0(%r14)
vmovups %ymm0, 0xe0(%r14)
vmovups %ymm0, 0x100(%r14)
vmovups %ymm0, 0x120(%r14)
vmovups %ymm0, 0x140(%r14)
vmovups %ymm0, 0x160(%r14)
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
vzeroupper
callq 0x26c4
movq (%rsp), %r15
shrq %r15
pushq $0x1
popq %rbp
pushq $-0x1
popq %rdi
leaq 0x1e0(%rsp), %r13
xorl %r8d, %r8d
movq %r15, (%rsp)
movq %rdi, %rax
xorl %edx, %edx
pushq $0x3
popq %r9
divq %r9
movq %rax, %rcx
movq %r8, %rax
xorl %edx, %edx
divq %r9
movq %rax, %rsi
movq %rbp, %rax
xorl %edx, %edx
divq %r9
cmpq %rbp, %r15
je 0x2ee9
movq %r8, 0x38(%rsp)
movq %rdi, 0x48(%rsp)
movq %rbp, %rbx
cmpq $0x2, %rbp
jb 0x2d72
imulq $-0x180, %rcx, %rcx     # imm = 0xFE80
addq %r13, %rcx
imulq $-0x180, %rsi, %rsi     # imm = 0xFE80
addq %r14, %rsi
imulq $-0x180, %rax, %rdi     # imm = 0xFE80
addq %r12, %rdi
movq %rbp, %rax
xorl %edx, %edx
pushq $0x3
popq %r8
divq %r8
movq %rdx, %rbx
movq 0x18(%rsp), %rdx
callq 0x27b4
shlq $0x7, %rbx
movq %r13, 0x40(%rsp)
leaq (%rsp,%rbx), %r13
addq $0x260, %r13            # imm = 0x260
movq %r14, 0x58(%rsp)
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, 0x50(%rsp)
leaq 0x120(%rsp), %r12
movq %r12, %rdx
callq 0x1609
addq %rsp, %rbx
addq $0x2a0, %rbx            # imm = 0x2A0
movq %rbp, 0x30(%rsp)
leaq 0x220(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x160(%rsp), %r15
movq %r15, %rdx
callq 0x1609
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1553
movq %r15, %rdi
movq %r13, %rsi
callq 0x21e2
movq %r14, %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %r12
movq %r12, %rdx
callq 0x1609
movq %rbp, %rdi
movq %r13, %rsi
leaq 0x1e0(%rsp), %r15
movq %r15, %rdx
callq 0x1609
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1553
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e2
movq %r14, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
movq %r13, %rdx
callq 0x1609
movq %rbp, %rdi
movq 0x28(%rsp), %r12
movq %r12, %rsi
movq %rbx, %rdx
callq 0x1609
movq %r14, %rdi
movq %rbp, %rsi
callq 0x15e6
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x21e2
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1609
movq %rbp, %rdi
movq %r12, %rsi
movq 0x50(%rsp), %r12
movq %r13, %rdx
movq 0x40(%rsp), %r13
callq 0x1609
movq %r14, %rdi
movq %rbp, %rsi
movq 0x30(%rsp), %rbp
callq 0x15e6
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
movq 0x58(%rsp), %r14
callq 0x21e2
incq %rbp
movl $0x80, %eax
addq %rax, %r13
movq 0x48(%rsp), %rdi
incq %rdi
addq %rax, %r14
movq 0x38(%rsp), %r8
incq %r8
addq %rax, %r12
movq (%rsp), %r15
jmp 0x2cfd
leaq 0x120(%rsp), %r15
movq %r15, %rdi
leaq 0x160(%rsp), %rbp
movq %rbp, %rsi
callq 0x21e2
movq %r15, %rdi
movq %r15, %rsi
callq 0x155f
movq %rbp, %rdi
callq 0x21f2
movq 0x20(%rsp), %r14
movq %r14, %rdi
leaq 0x1e0(%rsp), %r13
movq %r13, %rsi
callq 0x21e2
movq %r14, %rdi
movq %r14, %rsi
callq 0x155f
movq %r13, %rdi
callq 0x21f2
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1609
leaq 0x220(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1609
movq %rbx, %rdi
movq %r14, %rsi
callq 0x15e6
movq 0x10(%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 0x60(%rsp), %rbx
movq %rbx, %rdi
callq 0x21f2
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
callq 0x21f2
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x21e2
movq 0x28(%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 0x11f4(%rip), %rdi      # 0x4225
leaq 0x11f4(%rip), %rsi      # 0x422c
leaq 0x11f4(%rip), %rcx      # 0x4233
pushq $0x6d
jmp 0x305a
leaq 0x121c(%rip), %rdi      # 0x4266
leaq 0x11db(%rip), %rsi      # 0x422c
leaq 0x11db(%rip), %rcx      # 0x4233
pushq $0x6e
popq %rdx
callq 0x1050