// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x378, %rsp            # imm = 0x378
movq %rdi, 0x370(%rsp)
movq %rsi, 0x368(%rsp)
movq %rdx, 0x360(%rsp)
leaq 0x2e0(%rsp), %rdi
movl $0x4, %esi
callq 0x1274
leaq 0x2e0(%rsp), %rdi
addq $0x40, %rdi
movl $0x4, %esi
callq 0x1274
movq $0x0, 0x238(%rsp)
cmpq $0x4a, 0x238(%rsp)
jae 0x3ced
movq 0x360(%rsp), %rax
movq 0x238(%rsp), %rcx
shrq %rcx
movsbl (%rax,%rcx), %eax
movq 0x238(%rsp), %rcx
andq $0x1, %rcx
shlq $0x2, %rcx
shll %cl, %eax
movsbl %al, %eax
sarl $0x4, %eax
movb %al, 0x237(%rsp)
movsbl 0x237(%rsp), %eax
cmpl $0x0, %eax
jle 0x3bf1
movb 0x237(%rsp), %cl
movq 0x238(%rsp), %rax
movb %cl, 0x240(%rsp,%rax)
movq 0x238(%rsp), %rax
movb $0x0, 0x28a(%rsp,%rax)
leaq 0x2e0(%rsp), %rdi
addq $0x40, %rdi
leaq 0x2e0(%rsp), %rsi
addq $0x40, %rsi
movq 0x238(%rsp), %rcx
leaq 0x16de(%rip), %rax      # 0x52c0
movl (%rax,%rcx,4), %eax
movl %eax, %edx
callq 0x1369
jmp 0x3cd2
movsbl 0x237(%rsp), %eax
cmpl $0x0, %eax
jge 0x3c56
movsbl 0x237(%rsp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movb %al, %cl
movq 0x238(%rsp), %rax
movb %cl, 0x28a(%rsp,%rax)
movq 0x238(%rsp), %rax
movb $0x0, 0x240(%rsp,%rax)
leaq 0x2e0(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
movq 0x238(%rsp), %rcx
leaq 0x1676(%rip), %rax      # 0x52c0
movl (%rax,%rcx,4), %eax
movl %eax, %edx
callq 0x1369
jmp 0x3cd0
movq 0x238(%rsp), %rax
movb $0x0, 0x240(%rsp,%rax)
movq 0x238(%rsp), %rax
movb $0x0, 0x28a(%rsp,%rax)
leaq 0x2e0(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
movq 0x238(%rsp), %rcx
leaq 0x162b(%rip), %rax      # 0x52c0
movl (%rax,%rcx,4), %eax
movl %eax, %edx
callq 0x1369
leaq 0x2e0(%rsp), %rdi
addq $0x40, %rdi
leaq 0x2e0(%rsp), %rsi
addq $0x40, %rsi
movq 0x238(%rsp), %rcx
leaq 0x15fa(%rip), %rax      # 0x52c0
movl (%rax,%rcx,4), %eax
movl %eax, %edx
callq 0x1369
jmp 0x3cd2
jmp 0x3cd4
movq 0x238(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x238(%rsp)
jmp 0x3b43
leaq 0x1b0(%rsp), %rdi
movq 0x368(%rsp), %rsi
movl $0x40, %edx
callq 0x1090
leaq 0x1b0(%rsp), %rdi
addq $0x40, %rdi
leaq 0x1376(%rip), %rsi      # 0x5090
movl $0x40, %edx
callq 0x1090
leaq 0x1ae(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1060
leaq 0x1b0(%rsp), %rdi
addq $0x40, %rdi
leaq 0x1345(%rip), %rsi      # 0x5090
movl $0x40, %edx
callq 0x1080
cmpl $0x0, %eax
jne 0x3d5c
jmp 0x3d7b
leaq 0x1685(%rip), %rdi      # 0x53e8
leaq 0x169f(%rip), %rsi      # 0x5409
movl $0xaf, %edx
leaq 0x169b(%rip), %rcx      # 0x5411
callq 0x1050
leaq 0x128(%rsp), %rdi
callq 0x24c7
leaq 0x128(%rsp), %rdi
addq $0x40, %rdi
leaq 0x12f5(%rip), %rsi      # 0x5090
movl $0x40, %edx
callq 0x1090
leaq 0x1b0(%rsp), %rsi
leaq 0x128(%rsp), %rdx
leaq 0xe8(%rsp), %rdi
callq 0x4130
leaq 0xe8(%rsp), %rdi
callq 0x243c
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0xe7(%rsp)
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
testb $0x1, 0x1ae(%rsp,%rax)
je 0x3df5
jmp 0x40d7
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
leaq 0x2e0(%rsp), %rcx
shlq $0x6, %rax
addq %rax, %rcx
leaq 0x128(%rsp), %rdx
leaq 0x1b0(%rsp), %rsi
movq %rdx, %rdi
callq 0x2af0
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movb $0x1, 0x1ae(%rsp,%rax)
movq $0x49, 0xd8(%rsp)
cmpq $0x4a, 0xd8(%rsp)
jae 0x4090
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %ecx
leaq 0x240(%rsp), %rax
imulq $0x4a, %rcx, %rcx
addq %rcx, %rax
movq 0xd8(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x4019
leaq 0x98(%rsp), %rdi
leaq 0x1350(%rip), %rsi      # 0x51e5
movl $0x40, %edx
callq 0x1090
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jae 0x3f24
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %ecx
leaq 0x240(%rsp), %rax
imulq $0x4a, %rcx, %rcx
addq %rcx, %rax
movq 0x90(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3f0c
movq 0x90(%rsp), %rcx
leaq 0x13c9(%rip), %rax      # 0x52c0
movl (%rax,%rcx,4), %eax
movl %eax, %edx
leaq 0x98(%rsp), %rsi
movq %rsi, %rdi
callq 0x1369
jmp 0x3f0e
movq 0x90(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x90(%rsp)
jmp 0x3eab
leaq 0x10(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
leaq 0x128(%rsp), %rdx
leaq 0x98(%rsp), %rcx
callq 0x2af0
leaq 0x10(%rsp), %rdi
addq $0x40, %rdi
leaq 0x10fa(%rip), %rsi      # 0x5050
movl $0x40, %edx
callq 0x1080
cmpl $0x0, %eax
je 0x4017
movq 0xd8(%rsp), %rcx
leaq 0x1348(%rip), %rax      # 0x52c0
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
leaq 0x1b0(%rsp), %rdi
leaq 0x128(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x2d00
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
leaq 0x240(%rsp), %rcx
imulq $0x4a, %rax, %rax
addq %rax, %rcx
movq 0xd8(%rsp), %rdx
movb (%rcx,%rdx), %al
addb $-0x1, %al
movb %al, (%rcx,%rdx)
cmpb $0x0, %al
jne 0x4015
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
leaq 0x2e0(%rsp), %rdi
shlq $0x6, %rax
addq %rax, %rdi
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
leaq 0x2e0(%rsp), %rsi
shlq $0x6, %rax
addq %rax, %rsi
movq 0xd8(%rsp), %rcx
leaq 0x12b5(%rip), %rax      # 0x52c0
movl (%rax,%rcx,4), %eax
movl %eax, %edx
callq 0x1369
jmp 0x4017
jmp 0x4019
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %ecx
leaq 0x240(%rsp), %rax
imulq $0x4a, %rcx, %rcx
addq %rcx, %rax
movq 0xd8(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edx
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movb 0x1ae(%rsp,%rax), %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %edx, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, 0x1ae(%rsp,%rax)
movq 0xd8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xd8(%rsp)
jmp 0x3e48
leaq 0x1b0(%rsp), %rdi
addq $0x40, %rdi
callq 0x2430
leaq 0x1b0(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
addq $0x40, %rsi
callq 0x2246
leaq 0x1b0(%rsp), %rdi
addq $0x40, %rdi
leaq 0xfc3(%rip), %rsi       # 0x5090
movl $0x40, %edx
callq 0x1090
xorl %eax, %eax
testb $0x1, 0x1ae(%rsp)
movb %al, 0xf(%rsp)
je 0x40f2
movb 0x1af(%rsp), %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3d38
movq 0x370(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
movl $0x40, %edx
callq 0x1090
addq $0x378, %rsp            # imm = 0x378
retq
nopw %cs:(%rax,%rax)