// File: /workspace/github_c_makefile_star2_O3/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
movq $-0x1, %rax
cmpq $0x2, %rcx
jae 0xb237
movq 0x10(%rdi), %rcx
movq %rax, (%rcx,%rsi,8)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rdi), %r11
movq 0x10(%rdx,%r8), %r8
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ebx, %ebx
movq %r8, %r14
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movq (%r14), %r15
movq %r15, %r12
shrq %r12
cmpq %r11, %r12
jne 0xb28d
leal -0x1(%rbx), %ebp
cmpl $-0x1, %r9d
cmovnel %r9d, %ebp
cmpl $-0x1, %edx
cmovnel %ebp, %r9d
cmovel %ebx, %edx
andl $0x1, %r15d
cmpl $-0x1, %r10d
je 0xb28a
cmpl %r10d, %r15d
je 0xb28d
jmp 0xb224
movl %r15d, %r10d
incq %rbx
addq $0x20, %r14
cmpq %rbx, %rcx
jne 0xb256
cmpl $-0x1, %edx
je 0xb224
cmpl $-0x1, %r9d
je 0xb224
cmpl $-0x1, %r10d
je 0xb224
testl %edx, %edx
jne 0xb2d1
leal -0x2(%rcx), %r11d
cmpl %r11d, %r9d
jb 0xb2d1
shlq $0x21, %rdx
movl %r9d, %eax
leaq (%rdx,%rax,2), %rcx
movl %r10d, %eax
orq %rcx, %rax
jmp 0xb224
movl %r9d, %r11d
subl %edx, %r11d
movl %r11d, %ebx
subl %edx, %ebx
jb 0xb224
incl %ebx
xorl %r14d, %r14d
cmpl %r11d, %ebx
cmoval %r14d, %ebx
shlq $0x5, %rcx
xorl %r15d, %r15d
movq (%r8,%r15), %r12
leal (%rbx,%rdx), %r13d
shlq $0x5, %r13
cmpq (%r8,%r13), %r12
jne 0xb224
incl %ebx
cmpl %r11d, %ebx
cmoval %r14d, %ebx
addq $0x20, %r15
cmpq %r15, %rcx
jne 0xb2f5
jmp 0xb2bb