// File: /workspace/github_c_makefile_star2_O2/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 $0x3a8, %rsp            # imm = 0x3A8
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
leaq 0x320(%rsp), %rdi
pushq $0x4
popq %r13
movq %rdi, %r15
movq %r13, %rsi
callq 0x1210
leaq 0x360(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x1210
xorl %ebx, %ebx
xorl %ebp, %ebp
cmpq $0x4a, %rbp
je 0x35c6
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 0x355e
movb %al, 0x100(%rsp,%rbp)
movb $0x0, 0x14a(%rsp,%rbp)
leaq 0xd6d(%rip), %rax       # 0x42c0
movl (%rbx,%rax), %edx
movq %r12, %rdi
movq %r12, %rsi
jmp 0x35b5
js 0x3594
xorl %eax, %eax
movb %al, 0x100(%rsp,%rbp)
movb %al, 0x14a(%rsp,%rbp)
leaq 0xd49(%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 0x35b5
negb %al
movb %al, 0x14a(%rsp,%rbp)
movb $0x0, 0x100(%rsp,%rbp)
leaq 0xd14(%rip), %rax       # 0x42c0
movl (%rbx,%rax), %edx
movq %r15, %rdi
movq %r15, %rsi
callq 0x1305
incq %rbp
addq $0x4, %rbx
jmp 0x351b
movq 0x8(%rsp), %rax
vmovups (%rax), %ymm0
vmovups 0x20(%rax), %ymm1
leaq 0xc0(%rsp), %rax
vmovups %ymm1, -0x20(%rax)
vmovups %ymm0, -0x40(%rax)
leaq 0xaa3(%rip), %r15       # 0x4090
vmovups (%r15), %ymm0
vmovups 0x20(%r15), %ymm1
vmovups %ymm0, 0x60(%rsp)
vmovups %ymm0, (%rax)
vmovups %ymm1, 0x40(%rsp)
vmovups %ymm1, 0x20(%rax)
andw $0x0, 0x6(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x220(%rsp), %r13
leaq 0x1a0(%rsp), %rbx
xorl %r12d, %r12d
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
pushq $0x40
popq %rdx
vzeroupper
callq 0x1080
testl %eax, %eax
jne 0x392d
movq %r13, %rdi
callq 0x2463
vmovups 0x40(%rsp), %ymm0
leaq 0x260(%rsp), %rax
vmovups %ymm0, 0x20(%rax)
vmovups 0x60(%rsp), %ymm0
vmovups %ymm0, (%rax)
vmovups 0x220(%rsp), %ymm0
vmovups 0x240(%rsp), %ymm1
vmovups %ymm0, 0x1e0(%rsp)
vmovups %ymm1, 0x200(%rsp)
movq %r13, %rbp
leaq 0x1e0(%rsp), %r14
movq %r14, %rdi
vzeroupper
callq 0x21f2
leaq 0x2a0(%rsp), %r13
movq %r13, %rdi
leaq 0x80(%rsp), %rsi
movq %rbp, %rdx
callq 0x1609
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %r13
callq 0x155f
movq %r14, %rdi
movq %r15, %rsi
callq 0x155f
movq %r14, %rdi
movq %rbp, %rsi
callq 0x21e2
movq %r14, %rdi
callq 0x23d8
xorb $0x1, %al
movzbl %al, %ebp
cmpb $0x0, 0x6(%rsp,%rbp)
jne 0x38dc
movl %ebp, %eax
shll $0x6, %eax
leaq (%rsp,%rax), %rcx
addq $0x320, %rcx            # imm = 0x320
movq %r13, %rdi
leaq 0x80(%rsp), %rsi
movq %r13, %rdx
movq %rcx, 0x20(%rsp)
callq 0x28a4
movb $0x1, 0x6(%rsp,%rbp)
imulq $0x4a, %rbp, %rax
leaq (%rsp,%rax), %rcx
addq $0x100, %rcx            # imm = 0x100
movq %rcx, 0x28(%rsp)
movb $0x1, %cl
movl $0x124, %r14d           # imm = 0x124
leaq 0x100(%rsp,%rax), %rdx
pushq $0x49
popq %r12
movq %rbp, 0x30(%rsp)
movq %rdx, 0x10(%rsp)
cmpq $0x4a, %r12
jae 0x3897
movb %cl, 0x8(%rsp)
movb (%r12,%rdx), %r15b
testb %r15b, %r15b
je 0x3856
leaq 0xa61(%rip), %rax       # 0x41e5
vmovups (%rax), %ymm0
vmovups 0x20(%rax), %ymm1
leaq (%rdx,%r12), %rax
movq %rax, 0x38(%rsp)
vmovups %ymm1, 0x1c0(%rsp)
vmovups %ymm0, 0x1a0(%rsp)
movq 0x28(%rsp), %r13
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x37dd
cmpb $0x0, (%r13)
je 0x37d4
leaq 0xafe(%rip), %rax       # 0x42c0
movl (%rbp,%rax), %edx
movq %rbx, %rdi
movq %rbx, %rsi
vzeroupper
callq 0x1305
addq $0x4, %rbp
incq %r13
jmp 0x37af
leaq 0x2a0(%rsp), %rdi
leaq 0x80(%rsp), %r13
movq %r13, %rsi
leaq 0x220(%rsp), %rbp
movq %rbp, %rdx
movq %rbx, %rcx
vzeroupper
callq 0x28a4
leaq 0x2e0(%rsp), %rdi
leaq 0x83b(%rip), %rsi       # 0x4050
pushq $0x40
popq %rdx
callq 0x1080
testl %eax, %eax
je 0x385e
leaq 0xa98(%rip), %rax       # 0x42c0
movq %rbp, %rsi
movl (%rax,%r12,4), %ebp
movq %r13, %rdi
movq %rsi, %r13
leaq 0x2a0(%rsp), %rdx
movq %rbp, %rcx
callq 0x2b1e
decb %r15b
movq 0x38(%rsp), %rax
movb %r15b, (%rax)
je 0x3865
xorl %eax, %eax
jmp 0x3877
movb $0x1, %al
movb 0x8(%rsp), %cl
jmp 0x3885
xorl %eax, %eax
movq %rbp, %r13
jmp 0x3877
movq 0x20(%rsp), %rdi
movq %rdi, %rsi
movq %rbp, %rdx
callq 0x1305
movb $0x1, %al
movb 0x8(%rsp), %cl
movq 0x10(%rsp), %rdx
movq 0x30(%rsp), %rbp
andb %al, %cl
movb %cl, 0x6(%rsp,%rbp)
decq %r12
addq $-0x4, %r14
jmp 0x3762
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
callq 0x23cc
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0x21e2
vmovups 0x40(%rsp), %ymm0
vmovups %ymm0, 0x20(%r14)
vmovups 0x60(%rsp), %ymm0
vmovups %ymm0, (%r14)
movb 0x6(%rsp), %r12b
movb 0x7(%rsp), %al
movq %rax, 0x8(%rsp)
testb $0x1, %r12b
leaq 0x7a9(%rip), %r15       # 0x4090
je 0x362f
testb $0x1, 0x8(%rsp)
je 0x362f
vmovups 0x80(%rsp), %ymm0
vmovups 0xa0(%rsp), %ymm1
movq 0x18(%rsp), %rax
vmovups %ymm1, 0x20(%rax)
vmovups %ymm0, (%rax)
addq $0x3a8, %rsp            # imm = 0x3A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
leaq 0xab4(%rip), %rdi       # 0x43e8
leaq 0xace(%rip), %rsi       # 0x4409
leaq 0xacf(%rip), %rcx       # 0x4411
movl $0xaf, %edx
callq 0x1050