// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/path_finder.c
// Function: minicircle_analysis_thread
static void minicircle_analysis_thread(void *_data, long i, int tid) // kt_for() callback
{
    uint32_t j, k, beg, end, rev, nfrg;
    uint64_t sid, uid;
    scg_ra_t *ra;
    ra_frg_t *frgs;
    
    ra = &(((mc_shared_t *)_data)->ra->a[i]);
    sid = ((mc_shared_t *)_data)->sid;
    nfrg = ra->n;
    frgs = ra->a;

    if (nfrg < 2) {
        ((mc_shared_t *)_data)->mcs[i] = UINT64_MAX;
        return;
    }

    // find begin and end position
    beg = end = rev = UINT32_MAX;
    for (j = 0; j < nfrg; ++j) {
        uid = frgs[j].uid;
        if (uid>>1 != sid)
            continue;
        if (beg == UINT32_MAX)
            beg = j;
        else if (end == UINT32_MAX)
            end = j - 1;
        if (rev == UINT32_MAX) {
            rev = uid & 1;
        } else if (rev != (uid & 1)) {
            // inconsistent alignment orientation found
            rev = UINT32_MAX;
            break;
        }
    }

    if (beg == UINT32_MAX || end == UINT32_MAX || rev == UINT32_MAX) {
        // either no repeat unit or inconsistent orientation
        ((mc_shared_t *)_data)->mcs[i] = UINT64_MAX;
        return;
    }
    
    // check repeat unit consistency across the entire alignment path
    int valid = 1;
    if (beg > 0 || end < nfrg - 2) {
        uint32_t r = end - beg;
        if (beg > r) {
            valid = 0;
        } else {
            k = r - beg;
            if (++k > r) k = 0;
            for (j = 0; j < nfrg; ++j) {
                if (frgs[j].uid != frgs[beg+k].uid) {
                    valid = 0;
                    break;
                }
                if (++k > r) k = 0;
            }
        }
    }

    ((mc_shared_t *)_data)->mcs[i] = valid? ((uint64_t) beg<<33 | (uint64_t) end<<1 | rev) : UINT64_MAX;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdi), %rax
movq 0x10(%rax), %rdx
movq %rsi, %r8
shlq $0x5, %r8
movl 0x8(%rdx,%r8), %ecx
movabsq $-0x1, %rax
cmpq $0x2, %rcx
jb 0x915c
movq 0x8(%rdi), %r11
movq 0x10(%rdx,%r8), %rdx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movq %rdx, %r15
movl %ebx, %r9d
movl %ebx, %r10d
movl %ebx, %r8d
cmpq %r14, %rcx
je 0x911b
movq (%r15), %r12
movq %r12, %r13
shrq %r13
cmpq %r11, %r13
jne 0x9101
leal -0x1(%r14), %ebp
cmpl $-0x1, %r10d
cmovnel %r10d, %ebp
cmpl $-0x1, %r8d
cmovel %r10d, %ebp
cmovel %r14d, %r8d
andl $0x1, %r12d
cmpl $-0x1, %r9d
je 0x9106
cmpl %r9d, %r12d
je 0x9109
jmp 0x9115
movl %r10d, %ebp
jmp 0x9109
movl %r12d, %r9d
incq %r14
addq $0x20, %r15
movl %ebp, %r10d
jmp 0x90c5
movl %ebx, %r9d
movl %ebp, %r10d
cmpl $-0x1, %r8d
je 0x915c
cmpl $-0x1, %r10d
je 0x915c
cmpl $-0x1, %r9d
je 0x915c
testl %r8d, %r8d
jne 0x914e
leal -0x2(%rcx), %r11d
cmpl %r11d, %r10d
jb 0x914e
shlq $0x21, %r8
movl %r10d, %eax
leaq (%r8,%rax,2), %rcx
movl %r9d, %eax
orq %rcx, %rax
jmp 0x915c
movl %r10d, %r11d
subl %r8d, %r11d
movl %r11d, %ebx
subl %r8d, %ebx
jae 0x916f
movq 0x10(%rdi), %rcx
movq %rax, (%rcx,%rsi,8)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl %ebx
xorl %r14d, %r14d
cmpl %r11d, %ebx
cmoval %r14d, %ebx
shlq $0x5, %rcx
xorl %r15d, %r15d
cmpq %r15, %rcx
je 0x913b
movq (%rdx,%r15), %r12
leal (%rbx,%r8), %r13d
shlq $0x5, %r13
cmpq (%rdx,%r13), %r12
jne 0x915c
incl %ebx
cmpl %r11d, %ebx
cmoval %r14d, %ebx
addq $0x20, %r15
jmp 0x9182