// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq (%rdi), %rdx
movq 0x10(%rdi), %rcx
leaq (%rsi,%rsi,2), %r10
movl 0x8(%rdx,%r10,8), %eax
movl 0xc(%rdx,%r10,8), %r11d
movl %eax, %esi
shrl %esi
movq 0x10(%rcx), %rcx
leaq (%rsi,%rsi,4), %rdi
testb $0x1, %al
jne 0x221e6b
movl 0x10(%rcx,%rdi,8), %esi
decl %esi
shlq $0x3, %rsi
addq 0x18(%rcx,%rdi,8), %rsi
jmp 0x221e70
movq 0x18(%rcx,%rdi,8), %rsi
movq (%rsi), %rsi
shrq $0x21, %rsi
movl %r11d, %edi
shrl %edi
testb $0x1, %r11b
jne 0x221e8d
leaq (%rdi,%rdi,4), %rdi
movq 0x18(%rcx,%rdi,8), %rdi
jmp 0x221ea1
leaq (%rdi,%rdi,4), %r8
movl 0x10(%rcx,%r8,8), %edi
decl %edi
shlq $0x3, %rdi
addq 0x18(%rcx,%r8,8), %rdi
movq (%rdi), %rcx
leaq 0x74385(%rip), %rdi     # 0x296230
movq 0x18(%rdi), %rdi
movl (%rdi,%rsi,8), %esi
shrq $0x21, %rcx
movl (%rdi,%rcx,8), %ebx
cmpl %ebx, %esi
cmovbl %esi, %ebx
leaq 0x74453(%rip), %rcx     # 0x296318
movq 0x28(%rcx), %rsi
movl %eax, %edi
shrl %edi
movl (%rsi,%rdi,4), %r8d
movl 0x4(%rsi,%rdi,4), %r9d
subl %r8d, %r9d
je 0x22214c
movq %r11, 0x48(%rsp)
leaq (%rdx,%r10,8), %rdx
movq %rdx, 0x50(%rsp)
negq %rbx
movq %rbx, 0x40(%rsp)
shlq $0x3, %r8
addq 0x40(%rcx), %r8
movq 0x48(%rcx), %r11
cmpl $0x1, %r9d
adcl $0x0, %r9d
movl %eax, %ecx
andl $-0x2, %ecx
movl %ecx, 0x3c(%rsp)
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rcx, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
xorl %r13d, %r13d
movq (%r8,%r13,8), %r10
movq %r10, %r12
shrq $0x20, %r12
imulq $0x58, %r12, %rcx
movq 0x30(%r11,%rcx), %rdx
movl %r10d, %r14d
leaq (%r14,%r14,8), %rsi
cmpl %edi, (%rdx,%rsi,4)
jne 0x22215b
addq %r11, %rcx
cmpb $0x3, 0x50(%rcx)
jne 0x222109
leaq (%rdx,%rsi,4), %rbx
movzbl 0x20(%rbx), %r15d
movl %r15d, %esi
andb $-0x40, %sil
negb %sil
setno %sil
testb $0x1f, %r15b
sete %bpl
orb %sil, %bpl
jne 0x222109
shrl $0x5, %r15d
andl $0x1, %r15d
orl 0x3c(%rsp), %r15d
cmpl %eax, %r15d
jne 0x222061
cmpl $-0x1, 0x1c(%rbx)
jne 0x222061
leal 0x1(%r10), %esi
cmpq 0x20(%rcx), %rsi
jae 0x222061
leaq (%rsi,%rsi,8), %rcx
movq %rcx, 0x18(%rsp)
movzbl 0x20(%rdx,%rcx,4), %ecx
movl %ecx, %ebp
andb $-0x40, %bpl
negb %bpl
setno %bpl
testb $0x1f, %cl
sete %sil
orb %bpl, %sil
jne 0x222109
movq 0x18(%rsp), %rsi
leaq (%rdx,%rsi,4), %rbp
cmpl $-0x1, 0x14(%rbp)
jne 0x222109
movl (%rbp), %esi
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rsi,2), %ecx
cmpl 0x48(%rsp), %ecx
jne 0x222061
movl 0x4(%rbp), %ecx
movl 0x8(%rbx), %esi
movq %rcx, 0x18(%rsp)
subq %rsi, %rcx
cmpq 0x40(%rsp), %rcx
jle 0x222061
cmpl %esi, 0x8(%rbp)
jbe 0x222061
movq 0x18(%rsp), %rsi
cmpl 0x4(%rbx), %esi
jbe 0x222061
cmpq 0x10(%rsp), %rcx
jge 0x222061
movq $0x0, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %rbx, 0x28(%rsp)
movq %rbp, 0x30(%rsp)
movl %r12d, 0xc(%rsp)
xorl %eax, %r15d
cmpl $0x1, %r15d
jne 0x222109
testq %r14, %r14
je 0x222109
cmpl $-0x1, 0x14(%rbx)
jne 0x222109
decl %r10d
leaq (%r10,%r10,8), %rsi
movzbl 0x20(%rdx,%rsi,4), %ecx
movl %ecx, %r10d
andb $-0x40, %r10b
negb %r10b
setno %r10b
testb $0x1f, %cl
sete %bpl
orb %r10b, %bpl
jne 0x222109
leaq (%rdx,%rsi,4), %rdx
cmpl $-0x1, 0x1c(%rdx)
jne 0x222109
movl (%rdx), %esi
shrl $0x5, %ecx
andl $0x1, %ecx
leal (%rcx,%rsi,2), %ecx
xorl 0x48(%rsp), %ecx
cmpl $0x1, %ecx
jne 0x222109
movl 0x4(%rbx), %esi
movl 0x8(%rdx), %r10d
movq %rsi, %rcx
subq %r10, %rcx
cmpq 0x40(%rsp), %rcx
jle 0x222109
cmpl 0x8(%rbx), %r10d
jae 0x222109
cmpl %esi, 0x4(%rdx)
jae 0x222109
cmpq 0x10(%rsp), %rcx
jge 0x222109
movl $0x1, %esi
movq %rsi, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movl %r12d, 0xc(%rsp)
incq %r13
cmpq %r13, %r9
jne 0x221f42
movq 0x28(%rsp), %rax
testq %rax, %rax
movq 0x30(%rsp), %rdx
movl 0xc(%rsp), %esi
je 0x22214c
testq %rdx, %rdx
je 0x22214c
cmpl $-0x1, %esi
je 0x22214c
addl %esi, %esi
orl 0x20(%rsp), %esi
movq 0x50(%rsp), %rcx
movl %esi, 0x4(%rcx)
movl 0x8(%rax), %eax
movl %eax, 0x10(%rcx)
movl 0x4(%rdx), %eax
movl %eax, 0x14(%rcx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28502(%rip), %rdi     # 0x24a664
leaq 0x234a0(%rip), %rsi     # 0x245609
leaq 0x28505(%rip), %rcx     # 0x24a675
movl $0x3a12, %edx           # imm = 0x3A12
callq 0x2110