// File: /workspace/github_c_makefile_star2_O3/ioerror[P]csidh-reference-implementation/csidh.c
// Function: validate_rec
static bool validate_rec(proj *P, proj const *A, size_t lower, size_t upper, ui *order, bool *is_supersingular)
{
    assert(lower < upper);

    if (upper - lower == 1) {

        /* now P is [(p+1) / l_lower] times the original random point */
        /* we only gain information if this multiple is non-zero */

        if (memcmp(&P->z, &fp_0, sizeof(fp))) {

            ui tmp;
            ui_set(&tmp, primes[lower]);
            xMUL(P, A, P, &tmp);

            if (memcmp(&P->z, &fp_0, sizeof(fp))) {
                /* order does not divide p+1. */
                *is_supersingular = false;
                return true;
            }

            ui_mul3_64(order, order, primes[lower]);

            if (ui_sub3(&tmp, &four_sqrt_p, order)) { /* returns borrow */
                /* order > 4 sqrt(p), hence definitely supersingular */
                *is_supersingular = true;
                return true;
            }
        }

        /* inconclusive */
        return false;
    }

    size_t mid = lower + (upper - lower + 1) / 2;

    ui cl = ui_1, cu = ui_1;
    for (size_t i = lower; i < mid; ++i)
        ui_mul3_64(&cu, &cu, primes[i]);
    for (size_t i = mid; i < upper; ++i)
        ui_mul3_64(&cl, &cl, primes[i]);

    proj Q;

    xMUL(&Q, A, P, &cu);
    xMUL(P, A, P, &cl);

    /* start with the right half; bigger primes help more */
    return validate_rec(&Q, A, mid, upper, order, is_supersingular)
        || validate_rec(P, A, lower, mid, order, is_supersingular);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rsi, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
movq %rcx, %rbp
subq %rdx, %rbp
jbe 0x3536
movq %r9, %r15
movq %r8, %r13
cmpq $0x1, %rbp
jne 0x33ab
leaq 0xd2c(%rip), %r12       # 0x4050
movq 0x10(%rsp), %rbp
vmovdqu 0x40(%rbp), %ymm0
vmovdqu 0x60(%rbp), %ymm1
vpxor (%r12), %ymm0, %ymm0
vpternlogq $0xf6, 0x20(%r12), %ymm1, %ymm0
vptest %ymm0, %ymm0
je 0x351f
leaq 0xf6c(%rip), %rax       # 0x42c0
movl (%rax,%rdx,4), %ebx
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
vzeroupper
callq 0x1210
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x28a4
vmovdqu 0x40(%rbp), %ymm0
vmovdqu 0x60(%rbp), %ymm1
vpxor (%r12), %ymm0, %ymm0
vpternlogq $0xf6, 0x20(%r12), %ymm1, %ymm0
vptest %ymm0, %ymm0
je 0x34ea
xorl %ecx, %ecx
jmp 0x3518
movq %rcx, %r12
movq %r13, 0x20(%rsp)
movq %r15, 0x28(%rsp)
incq %rbp
shrq %rbp
leaq (%rdx,%rbp), %rcx
leaq 0xe1c(%rip), %rax       # 0x41e5
vmovdqu (%rax), %ymm0
vmovdqu 0x20(%rax), %ymm1
vmovdqu %ymm1, 0x90(%rsp)
vmovdqu %ymm0, 0x70(%rsp)
vmovdqu %ymm1, 0x50(%rsp)
vmovdqu %ymm0, 0x30(%rsp)
leaq 0xecc(%rip), %rbx       # 0x42c0
movq %rdx, (%rsp)
movq %rcx, 0x18(%rsp)
cmpq %rdx, %rcx
jbe 0x343a
movq (%rsp), %rax
leaq (,%rax,4), %r13
xorl %r15d, %r15d
leaq 0x30(%rsp), %r14
leaq (,%r15,4), %rax
addq %r13, %rax
movl (%rbx,%rax), %edx
movq %r14, %rdi
movq %r14, %rsi
vzeroupper
callq 0x1305
incq %r15
cmpq %r15, %rbp
jne 0x3416
movq 0x18(%rsp), %rbp
cmpq %r12, %rbp
jae 0x346c
leaq (%rbx,%rbp,4), %rbx
leaq 0x70(%rsp), %r14
movq %rbp, %r15
movl (%rbx), %edx
movq %r14, %rdi
movq %r14, %rsi
vzeroupper
callq 0x1305
incq %r15
addq $0x4, %rbx
cmpq %r12, %r15
jb 0x3450
leaq 0xb8(%rsp), %r14
leaq 0x30(%rsp), %rcx
movq %r14, %rdi
movq 0x8(%rsp), %r13
movq %r13, %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
vzeroupper
callq 0x28a4
leaq 0x70(%rsp), %rcx
movq %r15, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x28a4
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r12, %rcx
movq 0x20(%rsp), %r14
movq %r14, %r8
movq 0x28(%rsp), %rbx
movq %rbx, %r9
callq 0x32e6
movl %eax, %ecx
movb $0x1, %al
testb %cl, %cl
jne 0x3521
movq %r15, %rdi
movq %r13, %rsi
movq (%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x32e6
jmp 0x3521
movq %r13, %rdi
movq %r13, %rsi
movq %rbx, %rdx
vzeroupper
callq 0x1305
leaq 0xc96(%rip), %rsi       # 0x4198
leaq 0xb8(%rsp), %rdi
movq %r13, %rdx
callq 0x12a0
movb $0x1, %cl
testb %al, %al
je 0x351f
movb %cl, (%r15)
movb $0x1, %al
jmp 0x3521
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
leaq 0xf17(%rip), %rdi       # 0x4454
leaq 0xec5(%rip), %rsi       # 0x4409
leaq 0xf17(%rip), %rcx       # 0x4462
movl $0x21, %edx
callq 0x1050