// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: init_ul_str_idx_t(ul_resolve_t*)
void init_ul_str_idx_t(ul_resolve_t *p)
{
    uint64_t k, l, i, m, *a, a_n, x_n; uc_block_t *x_a; 
    all_ul_t *idx = p->idx; ul_str_idx_t *str = &(p->pstr); ul_str_t *z; uint32_t v0, v1;
    MALLOC(str->str.a, idx->n); str->str.n = str->str.m = idx->n;
    CALLOC(str->idx.a, p->l1_ug->u.n+1); str->idx.n = str->idx.m = p->l1_ug->u.n+1;
    for (i = 0; i < str->str.n; i++) {
        x_a = idx->a[i].bb.a; x_n = idx->a[i].bb.n; 
        memset(&(str->str.a[i]), 0, sizeof(str->str.a[i]));
        for (k = 0; k < x_n; k++) {
            if(x_a[k].base || (!x_a[k].el) || (!x_a[k].pchain)) continue;
            l = k; l <<= 32; l += (x_a[k].hid<<1); l += x_a[k].rev; str->idx.a[x_a[k].hid]++;
            kv_push(uint64_t, str->str.a[i], l);///idx|hid|rev
        }
        str->str.a[i].cn = str->str.a[i].n; str->str.a[i].is_cir = 0;
    }
    
    // kt_for(asm_opt.thread_num, gen_ul_str_idx_t, p, str->str.n);
    for (k = l = 0; k < str->idx.n; k++) {
		m = str->idx.a[k];
		str->idx.a[k] = l;
		l += m;
	}

    MALLOC(str->occ.a, l); str->occ.n = str->occ.m = l; 
	for (k = 0; k < p->l1_ug->u.n; k++) {
		a = str->occ.a + str->idx.a[k];
		a_n = str->idx.a[k+1] - str->idx.a[k];
		if(a_n) a[a_n-1] = 0;
	}

	for (k = 0; k < str->str.n; k++) {
        z = &(str->str.a[k]);
		for (i = 0; i < z->cn; i++) {
			a = str->occ.a + str->idx.a[((uint32_t)z->a[i])>>1];
			a_n = str->idx.a[(((uint32_t)z->a[i])>>1)+1] - str->idx.a[((uint32_t)z->a[i])>>1];
			if(a_n) {
				if(a[a_n-1] == a_n-1) {
                    m = a_n-1; a[a_n-1] = (k<<32)|i; 
                } else {
                    m = a[a_n-1]; a[a[a_n-1]++] = (k<<32)|i;
                }

                v0 = (uint32_t)z->a[(uint32_t)a[m]];
                while (m > 0 && z->is_cir == 0) {
                    m--;
                    if((a[m]>>32) != k) break;
                    v1 = (uint32_t)z->a[(uint32_t)a[m]];
                    if(v0 == v1) z->is_cir = 1;
                }
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r15
movq 0x30(%rdi), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rax), %rbx
movq %rbx, %rdi
shlq $0x5, %rdi
callq 0x2280
movq %rax, 0x1d0(%r15)
movq %rbx, 0x1c8(%r15)
movq %rbx, 0x1c0(%r15)
movq 0x18(%r15), %rax
movq (%rax), %r14
incq %r14
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x1a0(%r15)
movq %r14, 0x198(%r15)
movq %r14, 0x190(%r15)
xorl %r14d, %r14d
movabsq $0x100000000, %r8       # imm = 0x100000000
movq %r15, 0x8(%rsp)
cmpq %rbx, %r14
jae 0x1b2544
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r14, %rcx
movq 0x20(%rax,%rcx), %rbp
movq 0x30(%rax,%rcx), %r12
movq 0x1d0(%r15), %rax
movq %r14, 0x18(%rsp)
shlq $0x5, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax,%r14)
movups %xmm0, (%rax,%r14)
addq $0x20, %r12
xorl %r15d, %r15d
subq $0x1, %rbp
jb 0x1b24fa
movzbl (%r12), %r13d
movl %r13d, %eax
andb $-0x40, %al
negb %al
setno %al
testb $0x1f, %r13b
sete %cl
orb %al, %cl
jne 0x1b24ee
movl -0x20(%r12), %edx
movq 0x8(%rsp), %rbx
movq 0x1a0(%rbx), %rax
incq (%rax,%rdx,8)
movq 0x1d0(%rbx), %rcx
movq (%rcx,%r14), %rax
cmpq 0x8(%rcx,%r14), %rax
jne 0x1b24cd
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
leaq (%rcx,%r14), %rax
movq %rsi, 0x8(%rcx,%r14)
movq 0x10(%rax), %rdi
shlq $0x3, %rsi
movq %rdx, 0x20(%rsp)
callq 0x2370
movq 0x20(%rsp), %rdx
movabsq $0x100000000, %r8       # imm = 0x100000000
movq 0x1d0(%rbx), %rcx
movq %rax, 0x10(%rcx,%r14)
movq (%rcx,%r14), %rax
shrl $0x5, %r13d
andl $0x1, %r13d
leal (%r13,%rdx,2), %edx
addq %r15, %rdx
movq 0x10(%rcx,%r14), %rsi
leaq 0x1(%rax), %rdi
movq %rdi, (%rcx,%r14)
movq %rdx, (%rsi,%rax,8)
addq $0x24, %r12
addq %r8, %r15
jmp 0x1b2436
movq 0x8(%rsp), %r15
movq 0x1d0(%r15), %rax
movl (%rax,%r14), %ecx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %ecx
movl 0x18(%rax,%r14), %edx
movl $0x80000000, %edi       # imm = 0x80000000
andl %edi, %edx
orl %ecx, %edx
movl %edx, 0x18(%rax,%r14)
movq 0x1d0(%r15), %rax
andl %esi, 0x18(%rax,%r14)
movq 0x18(%rsp), %r14
incq %r14
movq 0x1c0(%r15), %rbx
jmp 0x1b23f1
xorl %ebx, %ebx
xorl %eax, %eax
cmpq 0x190(%r15), %rax
jae 0x1b256b
movq 0x1a0(%r15), %rcx
movq (%rcx,%rax,8), %rdx
addq %rbx, %rdx
movq %rbx, (%rcx,%rax,8)
incq %rax
movq %rdx, %rbx
jmp 0x1b2548
leaq (,%rbx,8), %rdi
callq 0x2280
movq %rax, 0x1b8(%r15)
movq %rbx, 0x1b0(%r15)
movq %rbx, 0x1a8(%r15)
movq 0x18(%r15), %rcx
xorl %edx, %edx
cmpq (%rcx), %rdx
jae 0x1b25c2
movq 0x1a0(%r15), %rdi
movq (%rdi,%rdx,8), %rsi
movq 0x8(%rdi,%rdx,8), %rdi
cmpq %rsi, %rdi
je 0x1b25bd
leaq (%rax,%rsi,8), %r8
notq %rsi
leaq (%r8,%rdi,8), %rdi
andq $0x0, (%rdi,%rsi,8)
incq %rdx
jmp 0x1b2593
xorl %eax, %eax
cmpq 0x1c0(%r15), %rax
jae 0x1b26a9
movq %rax, %rcx
shlq $0x5, %rcx
addq 0x1d0(%r15), %rcx
movq %rax, %rdx
shlq $0x20, %rdx
xorl %esi, %esi
movl 0x18(%rcx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
cmpq %rdi, %rsi
jae 0x1b26a1
movq 0x1a0(%r15), %r8
movq 0x10(%rcx), %rdi
movl (%rdi,%rsi,8), %r10d
shrl %r10d
movq (%r8,%r10,8), %r9
movq 0x8(%r8,%r10,8), %rbx
cmpq %r9, %rbx
jne 0x1b261f
incq %rsi
jmp 0x1b25e8
movq 0x1b8(%r15), %r11
leaq (%r11,%r9,8), %r14
movq %r9, %r8
notq %r8
addq %r8, %rbx
leaq (%r14,%rbx,8), %r10
movq (%r10), %r8
cmpq %rbx, %r8
jne 0x1b2644
movq %rbx, %r8
jmp 0x1b264f
leaq 0x1(%r8), %rbx
movq %rbx, (%r10)
leaq (%r14,%r8,8), %r10
movq %rsi, %rbx
orq %rdx, %rbx
movq %rbx, (%r10)
movl %esi, %r10d
movl (%rdi,%r10,8), %r10d
leaq (%r11,%r9,8), %r9
addq $-0x8, %r9
movq %r8, %r11
subq $0x1, %r11
jb 0x1b261a
movl 0x18(%rcx), %ebx
testl %ebx, %ebx
js 0x1b261a
movq (%r9,%r8,8), %r8
movq %r8, %r14
shrq $0x20, %r14
cmpq %rax, %r14
jne 0x1b261a
movl %r8d, %r14d
movq %r11, %r8
cmpl (%rdi,%r14,8), %r10d
jne 0x1b2667
orl $0x80000000, %ebx       # imm = 0x80000000
movl %ebx, 0x18(%rcx)
movq %r11, %r8
jmp 0x1b2667
incq %rax
jmp 0x1b25c4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq