// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: seed_uid(ma_utg_t*, unsigned long*, R_to_U*, ma_ug_t*)
uint32_t seed_uid(ma_utg_t *vu, uint64_t* ps_idx, R_to_U* ruIndex, ma_ug_t *rug)
{
    int64_t v_i, v, w, w_i, wb, we, vb, ve, k;
    uint32_t uid, is_u;
    ma_utg_t *wu = NULL;
    for (v_i = 0; v_i < vu->n; v_i++) {
        v = vu->a[v_i]>>32;
        get_R_to_U(ruIndex, v>>1, &uid, &is_u);
        if(is_u == 0 || uid == (uint32_t)-1 || ps_idx[v>>1] == (uint64_t)-1) continue;
        w_i = (uint32_t)ps_idx[v>>1];
        wu = &(rug->u.a[uid]);
        w = wu->a[w_i]>>32;
        if((v>>1)!=(w>>1)) continue;
        vb = 0; ve = vu->n; ///[vb, ve)
        if(v == w){ ///[wb, we)
            wb = w_i - v_i;
            we = wb + vu->n;
            if(wb < 0 || we > wu->n) continue;
            for (k = 0; k < vu->n; k++){
                if((vu->a[k+vb]>>32) != (wu->a[k+wb]>>32)) break;
            }
            if(k >= vu->n) return uid;
        } else {
            wb = w_i + 1 - (ve - v_i);
            we = wb + vu->n;
            if(wb < 0 || we > wu->n) continue;
            for (k = 0; k < vu->n; k++){
                if((vu->a[k+vb]>>32) != ((wu->a[we-k-1]>>32)^1)) break;
            }
            if(k >= vu->n) return uid;
        }
    }
    return (uint32_t)-1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x0, 0x10(%rdi)
je 0x118417
movq %rdi, %r13
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x18(%r13), %rax
movq (%rax,%r12,8), %r15
movq %r15, %r14
shrq $0x21, %r14
movq 0x20(%rsp), %rdi
movl %r14d, %esi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0xa3c62
cmpl $0x0, 0x8(%rsp)
sete %cl
movl 0xc(%rsp), %eax
cmpl $-0x1, %eax
sete %dl
orb %cl, %dl
jne 0x1183c4
movq 0x18(%rsp), %rcx
movq (%rcx,%r14,8), %rcx
cmpq $-0x1, %rcx
je 0x1183c4
movl %eax, %edi
movl %ecx, %esi
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rdx
leaq (%rdi,%rdi,4), %rdi
movq 0x18(%rdx,%rdi,8), %rcx
movq (%rcx,%rsi,8), %r8
movq %r8, %r9
shrq $0x21, %r9
cmpl %r9d, %r14d
jne 0x1183c4
leaq (%rdx,%rdi,8), %rdi
movl 0x10(%r13), %edx
xorq %r15, %r8
shrq $0x20, %r8
jne 0x1183b0
movq %rsi, %r8
subq %r12, %r8
js 0x1183c4
addq %rdx, %r8
movl 0x10(%rdi), %edi
cmpq %rdi, %r8
ja 0x1183c4
testq %rdx, %rdx
je 0x118417
movq 0x18(%r13), %rdi
leaq (,%rsi,8), %rsi
addq %rbp, %rsi
addq %rsi, %rcx
xorl %esi, %esi
movq (%rcx,%rsi,8), %r8
xorq (%rdi,%rsi,8), %r8
shrq $0x20, %r8
jne 0x1183c4
incq %rsi
cmpq %rsi, %rdx
jne 0x118398
jmp 0x118417
leaq (%rsi,%r12), %r8
incq %r8
cmpq %rdx, %r8
jb 0x1183c4
movl 0x10(%rdi), %edi
cmpq %rdi, %r8
jbe 0x1183de
incq %r12
movl 0x10(%r13), %eax
addq $0x8, %rbx
addq $-0x8, %rbp
cmpq %rax, %r12
jb 0x1182de
jmp 0x118412
testq %rdx, %rdx
je 0x118417
movq 0x18(%r13), %rdi
negq %rdx
leaq (%rbx,%rsi,8), %rsi
addq %rsi, %rcx
xorl %esi, %esi
movq (%rcx,%rsi,8), %r8
xorq (%rdi), %r8
shrq $0x20, %r8
cmpl $0x1, %r8d
jne 0x1183c4
decq %rsi
addq $0x8, %rdi
cmpq %rsi, %rdx
jne 0x1183f3
jmp 0x118417
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq