// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movq 0x30(%rdi), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rax), %rbx
movq %rbx, %rdi
shlq $0x5, %rdi
callq 0x2280
movq %rax, 0x1d0(%r13)
movq %rbx, 0x1c8(%r13)
movq %rbx, 0x1c0(%r13)
movq 0x18(%r13), %rax
movq (%rax), %r14
incq %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x2120
movq %rax, 0x1a0(%r13)
movq %r14, 0x198(%r13)
movq %r14, 0x190(%r13)
cmpq $0x0, 0x1c0(%r13)
je 0x1f2fa1
xorl %r14d, %r14d
movabsq $0x100000000, %r8       # imm = 0x100000000
movq %r13, 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(%r13), %rax
movq %r14, 0x18(%rsp)
shlq $0x5, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax,%r14)
movups %xmm0, (%rax,%r14)
testq %rbp, %rbp
je 0x1f2f56
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 0x1f2f46
movl -0x20(%r12), %edx
movq 0x1a0(%rbx), %rax
incq (%rax,%rdx,8)
movq 0x1d0(%rbx), %rax
movq 0x8(%rax,%r14), %rcx
cmpq %rcx, (%rax,%r14)
jne 0x1f2f1a
movq %rdx, 0x20(%rsp)
leaq (%rax,%r14), %rdx
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rax,%r14)
movq 0x8(%rdx), %rsi
movq 0x10(%rdx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x20(%rsp), %rdx
movabsq $0x100000000, %r8       # imm = 0x100000000
movq 0x1d0(%rbx), %rcx
movq %rax, 0x10(%rcx,%r14)
shrl $0x5, %r13d
andl $0x1, %r13d
leal (%r13,%rdx,2), %eax
addq %r15, %rax
movq 0x1d0(%rbx), %rcx
movq (%rcx,%r14), %rdx
movq 0x10(%rcx,%r14), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, (%rcx,%r14)
movq %rax, (%rsi,%rdx,8)
addq %r8, %r15
addq $0x24, %r12
decq %rbp
jne 0x1f2e90
movq 0x8(%rsp), %r13
movq 0x1d0(%r13), %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(%r13), %rax
andl %esi, 0x18(%rax,%r14)
movq 0x18(%rsp), %r14
incq %r14
cmpq 0x1c0(%r13), %r14
jb 0x1f2e4b
cmpq $0x0, 0x190(%r13)
je 0x1f2fd2
movq 0x1a0(%r13), %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(%r13), %rcx
jb 0x1f2fb6
jmp 0x1f2fd4
xorl %ebx, %ebx
leaq (,%rbx,8), %rdi
callq 0x2280
movq %rax, 0x1b8(%r13)
movq %rbx, 0x1b0(%r13)
movq %rbx, 0x1a8(%r13)
movq 0x18(%r13), %rcx
cmpq $0x0, (%rcx)
je 0x1f3032
movq 0x1a0(%r13), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movq 0x8(%rdx,%rsi,8), %r8
cmpq %rdi, %r8
je 0x1f302a
leaq (%rax,%rdi,8), %r9
notq %rdi
leaq (%r9,%r8,8), %r8
movq $0x0, (%r8,%rdi,8)
incq %rsi
cmpq (%rcx), %rsi
jb 0x1f3009
cmpq $0x0, 0x1c0(%r13)
je 0x1f313c
xorl %eax, %eax
movq 0x1d0(%r13), %rcx
movq %rax, %rdx
shlq $0x5, %rdx
testl $0x7fffffff, 0x18(%rcx,%rdx) # imm = 0x7FFFFFFF
je 0x1f312c
addq %rdx, %rcx
movq %rax, %rdx
shlq $0x20, %rdx
xorl %esi, %esi
movq 0x1a0(%r13), %rdi
movq 0x10(%rcx), %r8
movl (%r8,%rsi,8), %r9d
shrl %r9d
movq (%rdi,%r9,8), %r10
movq 0x8(%rdi,%r9,8), %rdi
cmpq %r10, %rdi
je 0x1f3117
movq 0x1b8(%r13), %r11
leaq (%r11,%r10,8), %r9
movq %r10, %rbx
notq %rbx
addq %rbx, %rdi
movq (%r9,%rdi,8), %rbx
cmpq %rdi, %rbx
jne 0x1f30b7
movq %rsi, %rbx
orq %rdx, %rbx
movq %rbx, (%r9,%rdi,8)
jmp 0x1f30cc
movq %rsi, %r14
orq %rdx, %r14
leaq 0x1(%rbx), %r15
movq %r15, (%r9,%rdi,8)
movq %r14, (%r9,%rbx,8)
movq %rbx, %rdi
testq %rdi, %rdi
je 0x1f3117
movl (%r9,%rdi,8), %r9d
movl (%r8,%r9,8), %r8d
movl 0x18(%rcx), %r9d
leaq (%r11,%r10,8), %r10
addq $-0x8, %r10
testl %r9d, %r9d
js 0x1f3117
movq (%r10,%rdi,8), %r11
movq %r11, %rbx
shrq $0x20, %rbx
cmpq %rax, %rbx
jne 0x1f3117
movq 0x10(%rcx), %rbx
movl %r11d, %r11d
cmpl (%rbx,%r11,8), %r8d
jne 0x1f3112
orl $0x80000000, %r9d       # imm = 0x80000000
movl %r9d, 0x18(%rcx)
decq %rdi
jne 0x1f30e5
incq %rsi
movl 0x18(%rcx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
cmpq %rdi, %rsi
jb 0x1f306a
incq %rax
cmpq 0x1c0(%r13), %rax
jb 0x1f3042
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq