// File: /workspace/github_c_makefile_star2_O3/ioerror[P]csidh-reference-implementation/csidh.c
// Function: action
void action(public_key *out, public_key const *in, private_key const *priv)
{
    ui k[2];
    ui_set(&k[0], 4); /* maximal 2-power in p+1 */
    ui_set(&k[1], 4); /* maximal 2-power in p+1 */

    uint8_t e[2][NUM_PRIMES];

    for (size_t i = 0; i < NUM_PRIMES; ++i) {

        int8_t t = (int8_t) (priv->e[i / 2] << i % 2 * 4) >> 4;

        if (t > 0) {
            e[0][i] = t;
            e[1][i] = 0;
            ui_mul3_64(&k[1], &k[1], primes[i]);
        }
        else if (t < 0) {
            e[1][i] = -t;
            e[0][i] = 0;
            ui_mul3_64(&k[0], &k[0], primes[i]);
        }
        else {
            e[0][i] = 0;
            e[1][i] = 0;
            ui_mul3_64(&k[0], &k[0], primes[i]);
            ui_mul3_64(&k[1], &k[1], primes[i]);
        }
    }

    proj A = {in->A, fp_1};

    bool done[2] = {false, false};

    do {

        assert(!memcmp(&A.z, &fp_1, sizeof(fp)));

        proj P;
        fp_random(&P.x);
        P.z = fp_1;

        fp rhs;
        montgomery_rhs(&rhs, &A.x, &P.x);
        bool sign = !fp_issquare(&rhs);

        if (done[sign])
            continue;

        xMUL(&P, &A, &P, &k[sign]);

        done[sign] = true;

        for (size_t i = NUM_PRIMES - 1; i < NUM_PRIMES; --i) {

            if (e[sign][i]) {

                ui cof = ui_1;
                for (size_t j = 0; j < i; ++j)
                    if (e[sign][j])
                        ui_mul3_64(&cof, &cof, primes[j]);

                proj K;
                xMUL(&K, &A, &P, &cof);

                if (memcmp(&K.z, &fp_0, sizeof(fp))) {

                    xISOG(&A, &P, &K, primes[i]);

                    if (!--e[sign][i])
                        ui_mul3_64(&k[sign], &k[sign], primes[i]);

                }

            }

            done[sign] &= !e[sign][i];
        }

        fp_inv(&A.z);
        fp_mul2(&A.x, &A.z);
        A.z = fp_1;

    } while (!(done[0] && done[1]));

    out->A = A.x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3e8, %rsp            # imm = 0x3E8
movq %rdx, %r14
movq %rsi, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
leaq 0x360(%rsp), %rdi
movl $0x4, %esi
movq %rdi, %rbp
callq 0x1210
leaq 0x3a0(%rsp), %r12
movl $0x4, %esi
movq %r12, %rdi
callq 0x1210
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %r15, %rax
shrq %rax
movb (%r14,%rax), %al
movl %ebx, %ecx
andb $0x4, %cl
shlb %cl, %al
sarb $0x4, %al
testb %al, %al
jle 0x35dd
movb %al, 0x240(%rsp,%r15)
movb $0x0, 0x28a(%rsp,%r15)
leaq 0xcee(%rip), %rax       # 0x42c0
movl (%rbx,%rax), %edx
movq %r12, %rdi
movq %r12, %rsi
jmp 0x3638
js 0x3615
xorl %eax, %eax
movb %al, 0x240(%rsp,%r15)
movb %al, 0x28a(%rsp,%r15)
leaq 0xcc8(%rip), %rax       # 0x42c0
movl (%rbx,%rax), %r13d
movq %rbp, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1305
movq %r12, %rdi
movq %r12, %rsi
movq %r13, %rdx
jmp 0x3638
negb %al
movb %al, 0x28a(%rsp,%r15)
movb $0x0, 0x240(%rsp,%r15)
leaq 0xc91(%rip), %rax       # 0x42c0
movl (%rbx,%rax), %edx
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x1305
incq %r15
addq $0x4, %rbx
cmpq $0x4a, %r15
jne 0x35a2
movq 0x10(%rsp), %rax
vmovups (%rax), %ymm0
vmovups 0x20(%rax), %ymm1
leaq 0xc0(%rsp), %rax
vmovups %ymm1, -0x20(%rax)
vmovups %ymm0, -0x40(%rax)
leaq 0xa1b(%rip), %r15       # 0x4090
vmovups (%r15), %ymm0
vmovdqu 0x20(%r15), %ymm1
vmovups %ymm0, 0x60(%rsp)
vmovups %ymm0, (%rax)
vmovdqu %ymm1, 0x40(%rsp)
vmovdqu %ymm1, 0x20(%rax)
movw $0x0, 0xe(%rsp)
leaq 0x200(%rsp), %r12
movq $0x0, 0x10(%rsp)
vmovups (%r15), %ymm0
vmovups %ymm0, 0x120(%rsp)
vmovdqu 0x20(%r15), %ymm0
vmovdqu %ymm0, 0x100(%rsp)
leaq 0x1c0(%rsp), %r13
leaq 0x180(%rsp), %rbp
xorl %r14d, %r14d
vmovdqu 0x120(%rsp), %ymm0
vpxor 0xc0(%rsp), %ymm0, %ymm0
vmovdqu 0x100(%rsp), %ymm1
vpternlogq $0xf6, 0xe0(%rsp), %ymm1, %ymm0
vptest %ymm0, %ymm0
jne 0x3a14
movq %r13, %rdi
vzeroupper
callq 0x2463
vmovups 0x40(%rsp), %ymm0
vmovups %ymm0, 0x20(%r12)
vmovups 0x60(%rsp), %ymm0
vmovups %ymm0, (%r12)
vmovdqu 0x1c0(%rsp), %ymm0
vmovdqu 0x1e0(%rsp), %ymm1
vmovdqu %ymm0, 0x180(%rsp)
vmovdqu %ymm1, 0x1a0(%rsp)
movq %rbp, %rdi
vzeroupper
callq 0x21f2
leaq 0x2e0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
movq %r13, %rdx
callq 0x1609
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x155f
movq %rbp, %rdi
movq %r15, %rsi
callq 0x155f
movq %rbp, %rdi
movq %r13, %rsi
callq 0x21e2
movq %rbp, %rdi
callq 0x23d8
xorb $0x1, %al
movzbl %al, %edx
cmpb $0x0, 0xe(%rsp,%rdx)
jne 0x39ca
movl %edx, %eax
shll $0x6, %eax
leaq (%rsp,%rax), %rcx
addq $0x360, %rcx            # imm = 0x360
movq %rdx, 0x18(%rsp)
movq %r13, %rdi
leaq 0x80(%rsp), %rsi
movq %r13, %rdx
movq %rcx, 0x28(%rsp)
callq 0x28a4
movq 0x18(%rsp), %rcx
movb $0x1, 0xe(%rsp,%rcx)
imulq $0x4a, %rcx, %rax
leaq (%rsp,%rax), %rdx
addq $0x240, %rdx            # imm = 0x240
movq %rdx, 0x30(%rsp)
movl $0x49, %r14d
movb $0x1, %r12b
movl $0x124, %ebx            # imm = 0x124
addq %rsp, %rax
addq $0x240, %rax            # imm = 0x240
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movb (%r14,%rax), %bpl
movb $0x1, %al
testb %bpl, %bpl
je 0x394c
leaq 0x9b0(%rip), %rax       # 0x41e5
vmovdqu (%rax), %ymm0
vmovdqu 0x20(%rax), %ymm1
vmovdqu %ymm1, 0x160(%rsp)
vmovdqu %ymm0, 0x140(%rsp)
testq %r14, %r14
leaq 0x2e0(%rsp), %rdi
je 0x389e
movq 0x30(%rsp), %r13
xorl %r15d, %r15d
cmpb $0x0, (%r13)
je 0x3892
leaq 0xa4d(%rip), %rax       # 0x42c0
movl (%r15,%rax), %edx
leaq 0x140(%rsp), %rdi
movq %rdi, %rsi
vzeroupper
callq 0x1305
leaq 0x2e0(%rsp), %rdi
addq $0x4, %r15
incq %r13
cmpq %r15, %rbx
jne 0x3865
leaq 0x80(%rsp), %r13
movq %r13, %rsi
leaq 0x1c0(%rsp), %r15
movq %r15, %rdx
leaq 0x140(%rsp), %rcx
vzeroupper
callq 0x28a4
vmovdqu 0x320(%rsp), %ymm0
vmovdqu 0x340(%rsp), %ymm1
leaq 0x773(%rip), %rax       # 0x4050
vpxor (%rax), %ymm0, %ymm0
vpternlogq $0xf6, 0x20(%rax), %ymm1, %ymm0
vptest %ymm0, %ymm0
je 0x3931
movq 0x10(%rsp), %rax
addq %r14, %rax
movq %rax, 0x38(%rsp)
leaq 0x9bc(%rip), %rax       # 0x42c0
movl (%rax,%r14,4), %eax
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %r15
leaq 0x2e0(%rsp), %rdx
movq %rax, %rcx
vzeroupper
callq 0x2b1e
decb %bpl
movq 0x38(%rsp), %rax
movb %bpl, (%rax)
je 0x3935
xorl %eax, %eax
jmp 0x3947
movq 0x28(%rsp), %rdi
movq %rdi, %rsi
movq %r15, %rdx
callq 0x1305
movb $0x1, %al
movq 0x18(%rsp), %rcx
andb %al, %r12b
movb %r12b, 0xe(%rsp,%rcx)
decq %r14
addq $-0x4, %rbx
cmpq $0x4a, %r14
jb 0x381a
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
vzeroupper
callq 0x23cc
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x21e2
vmovups 0x40(%rsp), %ymm0
vmovups %ymm0, 0x20(%rbx)
vmovdqu 0x60(%rsp), %ymm0
vmovdqu %ymm0, (%rbx)
movb 0xe(%rsp), %r14b
movb 0xf(%rsp), %al
movq %rax, 0x10(%rsp)
leaq 0x6de(%rip), %r15       # 0x4090
leaq 0x200(%rsp), %r12
leaq 0x1c0(%rsp), %r13
leaq 0x180(%rsp), %rbp
testb $0x1, %r14b
je 0x36dd
testb $0x1, 0x10(%rsp)
je 0x36dd
vmovups 0x80(%rsp), %ymm0
vmovups 0xa0(%rsp), %ymm1
movq 0x20(%rsp), %rax
vmovups %ymm1, 0x20(%rax)
vmovups %ymm0, (%rax)
addq $0x3e8, %rsp            # imm = 0x3E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
leaq 0x9cd(%rip), %rdi       # 0x43e8
leaq 0x9e7(%rip), %rsi       # 0x4409
leaq 0x9e8(%rip), %rcx       # 0x4411
movl $0xaf, %edx
vzeroupper
callq 0x1050