// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_scaffold_id(void*, long, int)
static void gen_scaffold_id(void *data, long i, int tid) // callback for kt_for()
{
    scaf_mul_t *ss = (scaf_mul_t *)data;
    ma_ug_t *ug = ss->ug;
    usc_t *z = &(ss->a[i]);
    uint32_t v = z->raw_sid, w = z->raw_eid, sv, sw;
    uint64_t *a, a_n, k; int64_t ql, mmql, max_ql; 
    uc_block_t *p, *n, *m0, *m1;
    sv = (v&1?((ug->u.a[v>>1].a[0]>>32)^1):(ug->u.a[v>>1].a[ug->u.a[v>>1].n-1]>>32));
    sw = (w&1?((ug->u.a[w>>1].a[ug->u.a[w>>1].n-1]>>32)^1):(ug->u.a[w>>1].a[0]>>32));
    // if((((v>>1) == 15016) && ((w>>1) == 2778)) || (((v>>1) == 2778) && ((w>>1) == 15016))) {
    //     fprintf(stderr, "[M::%s::]\t%.*s(%c)(sv>>1::%u)(utg%.6ul(%c))\t%.*s(%c)(sw>>1::%u)(utg%.6ul(%c))\n", __func__, 
    //         (int)Get_NAME_LENGTH(R_INF, (sv>>1)), Get_NAME(R_INF, (sv>>1)), "+-"[sv&1], sv>>1, (v>>1)+1, "+-"[v&1],
    //         (int)Get_NAME_LENGTH(R_INF, (sw>>1)), Get_NAME(R_INF, (sw>>1)), "+-"[sw&1], sw>>1, (w>>1)+1, "+-"[w&1]);
    // }
    sv = Get_READ_LENGTH(R_INF, (sv>>1)); sw = Get_READ_LENGTH(R_INF, (sw>>1));
    max_ql = MIN(sv, sw); max_ql = -max_ql;
    // if((((v>>1) == 235) && ((w>>1) == 153)) || (((v>>1) == 153) && ((w>>1) == 235))) {
    //     fprintf(stderr, "[M::%s] sv::%u, sw::%u, max_ql::%ld, v>>1::%u(%c), w>>1::%u(%c)\n", 
    //     __func__, sv, sw, max_ql, v>>1, "+-"[v&1], w>>1, "+-"[w&1]);
    // }
    // if((((v>>1) == 235) && ((w>>1) == 153)) || (((v>>1) == 153) && ((w>>1) == 235))) {
    //     print_ul_alignment(ug, &UL_INF, 5625, "+++");
    // }
    uint32_t uv, uw, rev = 0, id = (uint32_t)-1;
    p = n = m0 = m1 = NULL;
    a = UL_INF.ridx.occ.a + UL_INF.ridx.idx.a[v>>1];
	a_n = UL_INF.ridx.idx.a[(v>>1)+1] - UL_INF.ridx.idx.a[v>>1]; 
	for (k = 0, mmql = INT32_MAX; k < a_n; k++) {
        p = &(UL_INF.a[a[k]>>32].bb.a[(uint32_t)(a[k])]); assert(p->hid == (v>>1));
        if(UL_INF.a[a[k]>>32].dd != 3) continue;///dd = 3 is saved
		if(p->base || (!p->el) || (!p->pchain)) continue;
        uv = (((uint32_t)(p->hid))<<1)|((uint32_t)(p->rev));

        // if((uv == v) && (p->aidx != (uint32_t)-1)) {
        if((uv == v) && (p->aidx == (uint32_t)-1) && (((uint32_t)(a[k]))+1 < UL_INF.a[a[k]>>32].bb.n)) {
			n = &(UL_INF.a[a[k]>>32].bb.a[((uint32_t)(a[k]))+1]);
            if(n->base || (!n->el) || (!n->pchain) || (n->pidx != (uint32_t)-1)) continue;
			uw = (((uint32_t)(n->hid))<<1)|((uint32_t)(n->rev));
			if(uw == w) {
                // if((((v>>1) == 15016) && ((w>>1) == 2778)) || (((v>>1) == 2778) && ((w>>1) == 15016))) {
                //     fprintf(stderr, "+[M::%s] ul_id::%lu, qs::%u, qe::%u\n", __func__, a[k]>>32, n->qs, n->qe);
                //     // print_ul_alignment(ug, &UL_INF, a[k]>>32, "+++");
                // }
                ql = ((int64_t)n->qs) - ((int64_t)p->qe);
                if(ql > max_ql && n->qe > p->qe && n->qs > p->qs) {
                    if(ql < mmql) {
                        mmql = ql; rev = 0; m0 = p; m1 = n; id = a[k]>>32;
                    }
                }
            }
		}

		// if(((uv^1) == v) && (p->pidx != (uint32_t)-1)) {
        if(((uv^1) == v) && (p->pidx == (uint32_t)-1) && (((uint32_t)(a[k])) > 0)) {
			n = &(UL_INF.a[a[k]>>32].bb.a[((uint32_t)(a[k]))-1]);
            if(n->base || (!n->el) || (!n->pchain) || (n->aidx != (uint32_t)-1)) continue;
			uw = (((uint32_t)(n->hid))<<1)|((uint32_t)(n->rev)); uw ^= 1;
			if(uw == w) {
                // if((((v>>1) == 15016) && ((w>>1) == 2778)) || (((v>>1) == 2778) && ((w>>1) == 15016))) {
                //     fprintf(stderr, "-[M::%s] ul_id::%lu, qs::%u, qe::%u\n", __func__, a[k]>>32, n->qs, n->qe);
                //     // print_ul_alignment(ug, &UL_INF, a[k]>>32, "+++");
                // }
                ql = ((int64_t)p->qs) - ((int64_t)n->qe);
                if(ql > max_ql && n->qe < p->qe && n->qs < p->qs) {
                    if(ql < mmql) {
                        mmql = ql; rev = 1; m0 = n; m1 = p; id = a[k]>>32;
                    }
                }
            }
		}
    }

    if(m0 && m1 && id != ((uint32_t)-1)) {
        z->ulid = (id<<1)|rev;
        z->raw_sof = m0->qe;
        z->raw_eof = m1->qs;
        // if((((v>>1) == 15016) && ((w>>1) == 2778)) || (((v>>1) == 2778) && ((w>>1) == 15016))) {
        //     fprintf(stderr, "[M::%s] id::%u, v>>1::%u(%c), w>>1::%u(%c), raw_sof::%u, raw_eof::%u\n", 
        //     __func__, id, v>>1, "+-"[v&1], w>>1, "+-"[w&1], z->raw_sof, z->raw_eof);
        // }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq (%rdi), %rcx
movq 0x10(%rdi), %rax
leaq (%rsi,%rsi,2), %rdx
movl 0x8(%rcx,%rdx,8), %r8d
movq %rcx, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movl 0xc(%rcx,%rdx,8), %edx
movl %r8d, %esi
shrl %esi
movq 0x10(%rax), %rcx
leaq (%rsi,%rsi,4), %rdi
movq %r8, 0x38(%rsp)
testb $0x1, %r8b
jne 0x216a81
movl 0x10(%rcx,%rdi,8), %esi
decl %esi
shlq $0x3, %rsi
addq 0x18(%rcx,%rdi,8), %rsi
jmp 0x216a86
movq 0x18(%rcx,%rdi,8), %rsi
movq (%rsi), %rcx
shrq $0x21, %rcx
movl %edx, %esi
shrl %esi
movq 0x10(%rax), %rax
testb $0x1, %dl
jne 0x216aa5
leaq (%rsi,%rsi,4), %rsi
movq 0x18(%rax,%rsi,8), %rsi
jmp 0x216ab8
leaq (%rsi,%rsi,4), %rdi
movl 0x10(%rax,%rdi,8), %esi
decl %esi
shlq $0x3, %rsi
addq 0x18(%rax,%rdi,8), %rsi
movq (%rsi), %rax
leaq 0x7476e(%rip), %rsi     # 0x28b230
movq 0x18(%rsi), %rsi
movl (%rsi,%rcx,8), %ecx
shrq $0x21, %rax
movl (%rsi,%rax,8), %esi
cmpl %esi, %ecx
cmovbl %ecx, %esi
leaq 0x7483c(%rip), %rax     # 0x28b318
movq 0x28(%rax), %rcx
movq 0x38(%rsp), %r8
shrl %r8d
movl (%rcx,%r8,4), %r9d
movl 0x4(%rcx,%r8,4), %r10d
subl %r9d, %r10d
jne 0x216b1e
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
jmp 0x216d71
movq %rdx, 0x48(%rsp)
negq %rsi
movq %rsi, 0x40(%rsp)
shlq $0x3, %r9
addq 0x40(%rax), %r9
movq 0x48(%rax), %r15
cmpl $0x1, %r10d
adcl $0x0, %r10d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
xorl %r13d, %r13d
movq (%r9,%r13,8), %r11
movq %r11, %r12
shrq $0x20, %r12
imulq $0x58, %r12, %rbx
movq 0x30(%r15,%rbx), %rcx
movl %r11d, %esi
leaq (%rsi,%rsi,8), %rdi
movl (%rcx,%rdi,4), %eax
cmpl %r8d, %eax
jne 0x216dc0
leaq (%r15,%rbx), %rbp
cmpb $0x3, 0x50(%rbp)
jne 0x216d65
movq %r8, %r14
movq %r10, %r8
movq %r9, %r10
leaq (%rcx,%rdi,4), %rdx
movq %rdx, 0x10(%rsp)
movzbl 0x20(%rdx), %edi
movl %edi, %edx
andb $-0x40, %dl
negb %dl
setno %dl
testb $0x1f, %dil
sete %r9b
orb %dl, %r9b
je 0x216bdf
movq %r10, %r9
movq %r8, %r10
movq %r14, %r8
jmp 0x216d65
shrl $0x5, %edi
andl $0x1, %edi
leal (%rdi,%rax,2), %eax
cmpl 0x38(%rsp), %eax
movq %r10, %r9
jne 0x216cb0
movq 0x10(%rsp), %rdx
cmpl $-0x1, 0x1c(%rdx)
jne 0x216cb0
leal 0x1(%r11), %edi
cmpq 0x20(%rbp), %rdi
jae 0x216cb0
leaq (%rdi,%rdi,8), %rdi
movzbl 0x20(%rcx,%rdi,4), %ebp
movl %ebp, %edx
andb $-0x40, %dl
negb %dl
setno %dl
testb $0x1f, %bpl
sete %r9b
orb %dl, %r9b
jne 0x216bd1
leaq (%rcx,%rdi,4), %rcx
cmpl $-0x1, 0x14(%rcx)
movq %r10, %r9
jne 0x216bd4
movl (%rcx), %edx
shrl $0x5, %ebp
andl $0x1, %ebp
leal (%rbp,%rdx,2), %edx
cmpl 0x48(%rsp), %edx
movq %r8, %r10
jne 0x216cb3
movl 0x4(%rcx), %ebp
movq 0x10(%rsp), %rdx
movl 0x8(%rdx), %edi
movq %rbp, 0x50(%rsp)
subq %rdi, %rbp
cmpq 0x40(%rsp), %rbp
movq %r14, %r8
jle 0x216cb6
cmpl %edi, 0x8(%rcx)
jbe 0x216cb6
movq 0x10(%rsp), %rdx
movq 0x50(%rsp), %rdi
cmpl 0x4(%rdx), %edi
jbe 0x216cb6
cmpq 0x18(%rsp), %rbp
jge 0x216cb6
movq $0x0, 0x20(%rsp)
movq %rbp, 0x18(%rsp)
movq 0x10(%rsp), %rdx
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movl %r12d, 0xc(%rsp)
jmp 0x216cb6
movq %r8, %r10
movq %r14, %r8
xorl 0x38(%rsp), %eax
cmpl $0x1, %eax
jne 0x216d65
testq %rsi, %rsi
je 0x216d65
movq 0x10(%rsp), %r14
cmpl $-0x1, 0x14(%r14)
jne 0x216d65
movq 0x30(%r15,%rbx), %rax
decl %r11d
leaq (%r11,%r11,8), %rsi
movzbl 0x20(%rax,%rsi,4), %ecx
movl %ecx, %edx
andb $-0x40, %dl
negb %dl
setno %dl
testb $0x1f, %cl
sete %dil
orb %dl, %dil
jne 0x216d65
leaq (%rax,%rsi,4), %rax
cmpl $-0x1, 0x1c(%rax)
jne 0x216d65
movl (%rax), %edx
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rdx,2), %ecx
xorl 0x48(%rsp), %ecx
cmpl $0x1, %ecx
jne 0x216d65
movl 0x4(%r14), %esi
movl 0x8(%rax), %edi
movq %rsi, %rcx
subq %rdi, %rcx
cmpq 0x40(%rsp), %rcx
jle 0x216d65
cmpl 0x8(%r14), %edi
jae 0x216d65
cmpl %esi, 0x4(%rax)
jae 0x216d65
cmpq 0x18(%rsp), %rcx
jge 0x216d65
movl $0x1, %edx
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %rax, 0x30(%rsp)
movq %r14, 0x28(%rsp)
movl %r12d, 0xc(%rsp)
incq %r13
cmpq %r13, %r10
jne 0x216b6f
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
movl 0xc(%rsp), %esi
movq 0x28(%rsp), %rdi
je 0x216db1
testq %rdi, %rdi
je 0x216db1
cmpl $-0x1, %esi
je 0x216db1
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq (%rax,%rcx,8), %rax
addl %esi, %esi
orl 0x20(%rsp), %esi
movl %esi, 0x4(%rax)
movl 0x8(%rdx), %ecx
movl %ecx, 0x10(%rax)
movl 0x4(%rdi), %ecx
movl %ecx, 0x14(%rax)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x275b9(%rip), %rdi     # 0x23e380
leaq 0x22557(%rip), %rsi     # 0x239325
leaq 0x275bc(%rip), %rcx     # 0x23e391
movl $0x3a12, %edx           # imm = 0x3A12
callq 0x2110