// File: /workspace/github_c_makefile_star2_O2/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 %rcx, %rbp
movq %rdx, 0x8(%rsp)
subq %rdx, %rbp
jbe 0x34b2
movq %r9, %r15
movq %r8, %r12
movq %rsi, %r14
movq %rdi, %r13
cmpq $0x1, %rbp
jne 0x332d
leaq 0x40(%r13), %rbx
leaq 0xd8f(%rip), %rsi       # 0x4050
pushq $0x40
popq %rdx
movq %rbx, %rdi
callq 0x1080
testl %eax, %eax
je 0x349e
leaq 0xfe5(%rip), %rax       # 0x42c0
movq %r14, %rbp
movq 0x8(%rsp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x8(%rsp)
callq 0x1210
movq %r13, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x28a4
leaq 0xd3d(%rip), %rsi       # 0x4050
pushq $0x40
popq %rdx
movq %rbx, %rdi
callq 0x1080
testl %eax, %eax
je 0x346a
xorl %ecx, %ecx
jmp 0x3497
movq %rcx, %rbx
movq %r13, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, 0x28(%rsp)
incq %rbp
leaq 0xe97(%rip), %rax       # 0x41e5
vmovups (%rax), %ymm0
vmovups 0x20(%rax), %ymm1
vmovups %ymm1, 0x50(%rsp)
shrq %rbp
vmovups %ymm0, 0x30(%rsp)
leaq 0x70(%rsp), %r14
vmovups %ymm1, 0x20(%r14)
movq 0x8(%rsp), %rax
addq %rax, %rbp
vmovups %ymm0, (%r14)
leaq (,%rax,4), %r15
xorl %r12d, %r12d
leaq 0xf30(%rip), %r13       # 0x42c0
movq 0x8(%rsp), %rax
addq %r12, %rax
cmpq %rbp, %rax
jae 0x33b9
leaq (%r15,%r12,4), %rax
movl (%r13,%rax), %edx
movq %r14, %rdi
movq %r14, %rsi
vzeroupper
callq 0x1305
incq %r12
jmp 0x3390
leaq (,%rbp,4), %r15
addq %r13, %r15
leaq 0x30(%rsp), %r14
movq %rbp, %r12
movq 0x18(%rsp), %r13
cmpq %rbx, %r12
jae 0x33f0
movl (%r15), %edx
movq %r14, %rdi
movq %r14, %rsi
vzeroupper
callq 0x1305
incq %r12
addq $0x4, %r15
jmp 0x33d1
leaq 0xb8(%rsp), %r14
leaq 0x70(%rsp), %rcx
movq %r14, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
vzeroupper
callq 0x28a4
leaq 0x30(%rsp), %rcx
movq %r15, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x28a4
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq 0x20(%rsp), %r14
movq %r14, %r8
movq 0x28(%rsp), %rbx
movq %rbx, %r9
callq 0x3282
movl %eax, %ecx
movb $0x1, %al
testb %cl, %cl
jne 0x34a0
movq %r15, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x3282
jmp 0x34a0
movq %r12, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
callq 0x1305
leaq 0xd17(%rip), %rsi       # 0x4198
leaq 0xb8(%rsp), %rdi
movq %r12, %rdx
callq 0x12a0
movb $0x1, %cl
testb %al, %al
je 0x349e
movb %cl, (%r15)
movb $0x1, %al
jmp 0x34a0
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf9b(%rip), %rdi       # 0x4454
leaq 0xf49(%rip), %rsi       # 0x4409
leaq 0xf9b(%rip), %rcx       # 0x4462
pushq $0x21
popq %rdx
callq 0x1050