// File: /workspace/github_c_makefile_star2_O1/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, 0x18(%rsp)
leaq 0x360(%rsp), %r15
movl $0x4, %esi
movq %r15, %rdi
callq 0x1210
leaq 0x3a0(%rsp), %r12
movl $0x4, %esi
movq %r12, %rdi
callq 0x1210
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %rbp, %rax
shrq %rax
movb (%r14,%rax), %al
movl %ebx, %ecx
andb $0x4, %cl
shlb %cl, %al
sarb $0x4, %al
testb %al, %al
jle 0x35e2
movb %al, 0x1c0(%rsp,%rbp)
movb $0x0, 0x20a(%rsp,%rbp)
leaq 0xce9(%rip), %rax       # 0x42c0
movl (%rbx,%rax), %edx
movq %r12, %rdi
movq %r12, %rsi
jmp 0x3639
js 0x3618
xorl %eax, %eax
movb %al, 0x1c0(%rsp,%rbp)
movb %al, 0x20a(%rsp,%rbp)
leaq 0xcc5(%rip), %rax       # 0x42c0
movl (%rbx,%rax), %r13d
movq %r15, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1305
movq %r12, %rdi
movq %r12, %rsi
movq %r13, %rdx
jmp 0x3639
negb %al
movb %al, 0x20a(%rsp,%rbp)
movb $0x0, 0x1c0(%rsp,%rbp)
leaq 0xc90(%rip), %rax       # 0x42c0
movl (%rbx,%rax), %edx
movq %r15, %rdi
movq %r15, %rsi
callq 0x1305
incq %rbp
addq $0x4, %rbx
cmpq $0x4a, %rbp
jne 0x35a9
movq 0x10(%rsp), %rax
vmovups (%rax), %ymm0
vmovups 0x20(%rax), %ymm1
leaq 0xc0(%rsp), %rax
vmovups %ymm1, -0x20(%rax)
vmovups %ymm0, -0x40(%rax)
leaq 0xa1a(%rip), %rbx       # 0x4090
vmovups (%rbx), %ymm0
vmovdqu 0x20(%rbx), %ymm1
vmovups %ymm0, 0x60(%rsp)
vmovups %ymm0, (%rax)
vmovdqu %ymm1, 0x40(%rsp)
vmovdqu %ymm1, 0x20(%rax)
movw $0x0, 0xe(%rsp)
leaq 0x180(%rsp), %r14
vmovups (%rbx), %ymm0
vmovups %ymm0, 0x120(%rsp)
vmovdqu 0x20(%rbx), %ymm0
vmovdqu %ymm0, 0x100(%rsp)
leaq 0x260(%rsp), %r15
vmovdqu 0x120(%rsp), %ymm0
vpxor 0xc0(%rsp), %ymm0, %ymm0
vmovdqu 0x100(%rsp), %ymm1
vpternlogq $0xf6, 0xe0(%rsp), %ymm1, %ymm0
vptest %ymm0, %ymm0
jne 0x39d4
leaq 0x140(%rsp), %r12
movq %r12, %rdi
vzeroupper
callq 0x2463
vmovups 0x40(%rsp), %ymm0
vmovups %ymm0, 0x20(%r14)
vmovups 0x60(%rsp), %ymm0
vmovups %ymm0, (%r14)
vmovdqu 0x140(%rsp), %ymm0
vmovdqu 0x160(%rsp), %ymm1
vmovdqu %ymm0, 0x2a0(%rsp)
vmovdqu %ymm1, 0x2c0(%rsp)
leaq 0x2a0(%rsp), %r13
movq %r13, %rdi
vzeroupper
callq 0x21f2
leaq 0x2e0(%rsp), %rbp
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
movq %r12, %rdx
callq 0x1609
movq %r13, %rdi
movq %rbp, %rsi
callq 0x155f
movq %r13, %rdi
movq %rbx, %rsi
callq 0x155f
movq %r13, %rdi
movq %r12, %rsi
callq 0x21e2
movq %r13, %rdi
callq 0x23d8
xorb $0x1, %al
movzbl %al, %r13d
cmpb $0x0, 0xe(%rsp,%r13)
jne 0x3989
movl %r13d, %eax
shll $0x6, %eax
leaq (%rsp,%rax), %rcx
addq $0x360, %rcx            # imm = 0x360
leaq 0x140(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movq %rdi, %rdx
movq %rcx, 0x20(%rsp)
callq 0x28a4
movb $0x1, 0xe(%rsp,%r13)
imulq $0x4a, %r13, %rax
leaq (%rsp,%rax), %rcx
addq $0x1c0, %rcx            # imm = 0x1C0
movq %rcx, 0x28(%rsp)
movl $0x49, %r14d
movl $0x124, %r12d           # imm = 0x124
addq %rsp, %rax
addq $0x1c0, %rax            # imm = 0x1C0
movq %rax, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq 0x38(%rsp), %rax
leaq (%rax,%r14), %rbp
movb (%r14,%rax), %bl
testb %bl, %bl
je 0x3925
movq %rbp, 0x10(%rsp)
leaq 0x9b1(%rip), %rax       # 0x41e5
vmovdqu (%rax), %ymm0
vmovdqu 0x20(%rax), %ymm1
vmovdqu %ymm1, 0x280(%rsp)
vmovdqu %ymm0, 0x260(%rsp)
testq %r14, %r14
je 0x3887
movq 0x28(%rsp), %r13
xorl %ebp, %ebp
cmpb $0x0, (%r13)
je 0x387b
leaq 0xa57(%rip), %rax       # 0x42c0
movl (%rbp,%rax), %edx
movq %r15, %rdi
movq %r15, %rsi
vzeroupper
callq 0x1305
addq $0x4, %rbp
incq %r13
cmpq %rbp, %r12
jne 0x385b
leaq 0x2e0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x140(%rsp), %rdx
movq %r15, %rcx
vzeroupper
callq 0x28a4
vmovdqu 0x320(%rsp), %ymm0
vmovdqu 0x340(%rsp), %ymm1
leaq 0x78d(%rip), %rax       # 0x4050
vpxor (%rax), %ymm0, %ymm0
vpternlogq $0xf6, 0x20(%rax), %ymm1, %ymm0
vptest %ymm0, %ymm0
movq 0x10(%rsp), %rbp
je 0x3920
leaq 0x9de(%rip), %rax       # 0x42c0
movl (%rax,%r14,4), %r13d
leaq 0x80(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0x2e0(%rsp), %rdx
movq %r13, %rcx
vzeroupper
callq 0x2b29
decb %bl
movb %bl, (%rbp)
jne 0x3920
movq 0x20(%rsp), %rdi
movq %rdi, %rsi
movq %r13, %rdx
callq 0x1305
movq 0x30(%rsp), %r13
cmpb $0x0, (%rbp)
sete %al
andb %al, 0xe(%rsp,%r13)
decq %r14
addq $-0x4, %r12
cmpq $0x4a, %r14
jb 0x3813
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)
leaq 0x70f(%rip), %rbx       # 0x4090
leaq 0x180(%rsp), %r14
cmpb $0x1, 0xe(%rsp)
jne 0x36c6
testb $0x1, 0xf(%rsp)
je 0x36c6
vmovups 0x80(%rsp), %ymm0
vmovups 0xa0(%rsp), %ymm1
movq 0x18(%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 0xa0d(%rip), %rdi       # 0x43e8
leaq 0xa27(%rip), %rsi       # 0x4409
leaq 0xa28(%rip), %rcx       # 0x4411
movl $0xaf, %edx
vzeroupper
callq 0x1050