// File: /workspace/github_c_makefile_star2_O1/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), %rcx
movq %rsi, %rdx
shlq $0x5, %rdx
movl 0x8(%rcx,%rdx), %r10d
movq $-0x1, %rax
cmpq $0x2, %r10
jb 0xacb3
movq 0x8(%rdi), %r11
movq 0x10(%rcx,%rdx), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %ebx, %ebx
movq %rdx, %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movq (%r14), %r15
movq %r15, %r9
shrq %r9
cmpq %r11, %r9
jne 0xac56
leal -0x1(%rbx), %r9d
cmpl $-0x1, %ebp
cmovnel %ebp, %r9d
cmpl $-0x1, %ecx
cmovel %ebp, %r9d
cmovel %ebx, %ecx
andl $0x1, %r15d
cmpl $-0x1, %r8d
je 0xac5b
cmpl %r8d, %r15d
je 0xac5e
jmp 0xac6f
movl %ebp, %r9d
jmp 0xac5e
movl %r15d, %r8d
incq %rbx
addq $0x20, %r14
movl %r9d, %ebp
cmpq %rbx, %r10
jne 0xac22
jmp 0xac75
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl $-0x1, %ecx
je 0xacb3
cmpl $-0x1, %r9d
je 0xacb3
cmpl $-0x1, %r8d
je 0xacb3
testl %ecx, %ecx
jne 0xaca6
leal -0x2(%r10), %r11d
cmpl %r11d, %r9d
jb 0xaca6
shlq $0x21, %rcx
movl %r9d, %eax
leaq (%rcx,%rax,2), %rcx
movl %r8d, %eax
orq %rcx, %rax
jmp 0xacb3
movl %r9d, %r11d
subl %ecx, %r11d
movl %r11d, %ebx
subl %ecx, %ebx
jae 0xacc6
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
cmpl $0x2, %r10d
movl $0x1, %r15d
cmovael %r10d, %r15d
shlq $0x5, %r15
xorl %r10d, %r10d
movq (%rdx,%r10), %r12
leal (%rbx,%rcx), %r13d
shlq $0x5, %r13
cmpq (%rdx,%r13), %r12
jne 0xacb3
incl %ebx
cmpl %r11d, %ebx
cmoval %r14d, %ebx
addq $0x20, %r10
cmpq %r10, %r15
jne 0xace7
jmp 0xac93