// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq 0x50(%rax), %rdi
shlq $0x5, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x50(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x58(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
addq $0x1, %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0x32751d
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x58, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x58, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x20(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x3274ab
movq -0x48(%rbp), %rax
imulq $0x24, -0x10(%rbp), %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
jne 0x327301
movq -0x48(%rbp), %rax
imulq $0x24, -0x10(%rbp), %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x327301
movq -0x48(%rbp), %rax
imulq $0x24, -0x10(%rbp), %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
jne 0x327306
jmp 0x32749a
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x18(%rbp)
movq -0x48(%rbp), %rax
imulq $0x24, -0x10(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shll %eax
movl %eax, %eax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x48(%rbp), %rax
imulq $0x24, -0x10(%rbp), %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
imulq $0x24, -0x10(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq -0x20(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jne 0x327459
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0x3273e2
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x3273ed
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x3273ed
movq -0x70(%rbp), %rcx
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rdx
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %rcx
movq 0x40(%rcx), %rsi
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x32749a
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x3272b0
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %edx
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x327247
movq $0x0, -0x18(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x32757c
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdx
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x32752d
movq -0x18(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq (%rcx), %rax
jae 0x327637
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x10(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x327624
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x327626
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x3275b0
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0x32786c
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x60(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x327859
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x60(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0x20(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrl %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x60(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0x20(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
subq (%rcx,%rdx,8), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x327846
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x327758
movq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdx
shlq $0x20, %rdx
orq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x32779b
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdx
shlq $0x20, %rdx
orq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rax
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdi
subq $0x1, %rdi
movq (%rsi,%rdi,8), %rcx
movq %rcx, %r8
addq $0x1, %r8
movq %r8, (%rsi,%rdi,8)
movq %rdx, (%rax,%rcx,8)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x64(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x71(%rbp)
jbe 0x3277d7
movq -0x60(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x3277e0
jmp 0x327844
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
cmpq -0x10(%rbp), %rax
je 0x327804
jmp 0x327844
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
jne 0x32783f
movq -0x60(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x18(%rax)
jmp 0x3277b8
jmp 0x327846
jmp 0x327848
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x327670
jmp 0x32785b
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x32763f
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)