// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0x8, %esi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x1a0(%r15)
movq %r14, 0x198(%r15)
movq %r14, 0x190(%r15)
testq %rbx, %rbx
je 0x1fe4ae
xorl %r14d, %r14d
movabsq $0x100000000, %r8       # imm = 0x100000000
movq %r15, 0x8(%rsp)
movq 0x8(%rsp), %rbx
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)
testq %rbp, %rbp
je 0x1fe45c
addq $0x20, %r12
xorl %r15d, %r15d
movzbl (%r12), %r13d
movl %r13d, %eax
andb $-0x40, %al
negb %al
setno %al
testb $0x1f, %r13b
sete %cl
orb %al, %cl
jne 0x1fe44c
movl -0x20(%r12), %edx
movq 0x1a0(%rbx), %rax
incq (%rax,%rdx,8)
movq 0x1d0(%rbx), %rcx
movq (%rcx,%r14), %rax
cmpq 0x8(%rcx,%r14), %rax
jne 0x1fe42b
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
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 %r8, %r15
addq $0x24, %r12
decq %rbp
jne 0x1fe3a1
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
cmpq 0x1c0(%r15), %r14
jb 0x1fe35c
movq 0x190(%r15), %r14
testq %r14, %r14
je 0x1fe4da
movq 0x1a0(%r15), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq (%rax,%rcx,8), %rbx
addq %rdx, %rbx
movq %rdx, (%rax,%rcx,8)
incq %rcx
movq %rbx, %rdx
cmpq 0x190(%r15), %rcx
jb 0x1fe4be
jmp 0x1fe4dc
xorl %ebx, %ebx
leaq (,%rbx,8), %rdi
callq 0x2280
movq %rax, 0x1b8(%r15)
movq %rbx, 0x1b0(%r15)
movq %rbx, 0x1a8(%r15)
movq 0x18(%r15), %rcx
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x1fe53f
movq 0x1a0(%r15), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %r8
movq 0x8(%rdx,%rsi,8), %r9
cmpq %r8, %r9
je 0x1fe537
leaq (%rax,%r8,8), %rdi
notq %r8
leaq (%rdi,%r9,8), %rdi
movq $0x0, (%rdi,%r8,8)
movq (%rcx), %rdi
incq %rsi
cmpq %rdi, %rsi
jb 0x1fe513
movq 0x1c0(%r15), %rdx
testq %rdx, %rdx
je 0x1fe644
xorl %eax, %eax
movq 0x1d0(%r15), %rcx
movq %rax, %rsi
shlq $0x5, %rsi
movl 0x18(%rcx,%rsi), %r8d
testl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
je 0x1fe638
addq %rsi, %rcx
movq %rax, %rdx
shlq $0x20, %rdx
movq 0x10(%rcx), %rsi
xorl %edi, %edi
movq 0x1a0(%r15), %r9
movl (%rsi,%rdi,8), %r11d
shrl %r11d
movq (%r9,%r11,8), %r10
movq 0x8(%r9,%r11,8), %r11
cmpq %r10, %r11
je 0x1fe61b
movq 0x1b8(%r15), %rbx
leaq (%rbx,%r10,8), %r14
movq %r10, %r8
notq %r8
addq %r8, %r11
leaq (%r14,%r11,8), %r8
movq (%r8), %r9
cmpq %r11, %r9
jne 0x1fe5c2
movq %r11, %r9
jmp 0x1fe5cd
leaq 0x1(%r9), %r11
movq %r11, (%r8)
leaq (%r14,%r9,8), %r8
movq %rdi, %r11
orq %rdx, %r11
movq %r11, (%r8)
movl 0x18(%rcx), %r8d
testq %r9, %r9
je 0x1fe61b
movl %edi, %r11d
movl (%rsi,%r11,8), %r11d
leaq (%rbx,%r10,8), %r10
addq $-0x8, %r10
testl %r8d, %r8d
js 0x1fe61b
movq (%r10,%r9,8), %rbx
movq %rbx, %r14
shrq $0x20, %r14
cmpq %rax, %r14
jne 0x1fe61b
movl %ebx, %ebx
cmpl (%rsi,%rbx,8), %r11d
jne 0x1fe616
orl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, 0x18(%rcx)
decq %r9
jne 0x1fe5ee
incq %rdi
movl %r8d, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
cmpq %r9, %rdi
jb 0x1fe581
movq 0x1c0(%r15), %rdx
incq %rax
cmpq %rdx, %rax
jb 0x1fe551
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq