// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: update_poa_dp(poa_g_t*, unsigned int, ma_ug_t*)
uint32_t update_poa_dp(poa_g_t *g, uint32_t debug_qid, ma_ug_t *debug_ug)
{
    uint32_t is_srt = 0/**, is_up_aln = 0**/, k, is_circle = 0;
    if(g->seq.n > g->update_seq || g->arc.n > g->update_arc) {
        if(g->seq.n > g->update_seq) {
            kv_resize(uint32_t, g->srt_b.res, g->seq.n);
            kv_resize(uint32_t, g->srt_b.res2nid, g->seq.n);
            // kv_resize(uint64_t, g->srt_b.aln, g->seq.n); g->srt_b.aln.n = g->seq.n;
            g->srt_b.res.n = g->srt_b.res2nid.n = g->seq.n;
            for (k = g->update_seq; k < g->seq.n; k++) {
                g->srt_b.res.a[k] = g->srt_b.res2nid.a[k] = k;
                // g->srt_b.aln.a[k] = (((uint64_t)(g->seq.a[k].nid))<<32)+k;
                // if(k > 0 && is_up_aln == 0) {
                //     if((g->srt_b.aln.a[k]>>32) < (g->srt_b.aln.a[k-1]>>32)) is_up_aln = 1;
                // }
            }
        }
        if(g->arc.n > g->update_arc) { ///check if it is necessary to resort
            for (k = g->update_arc; k < g->arc.n; k++) {
                if((g->arc.a[k].ul>>32)&1) continue;
                if(g->srt_b.res2nid.a[g->arc.a[k].ul>>33] >= g->srt_b.res2nid.a[g->arc.a[k].v>>1]) break;
            }
            if(k < g->arc.n) is_srt = 1;
        }
        // fprintf(stderr, "[M::%s::] is_srt::%u\n", __func__, is_srt);
        clean_poa_g_t(g); 
        if(is_srt) {
            is_circle = 1 - topo_srt_gen(g, debug_qid, debug_ug);
        } 
        // else if(is_up_aln) {
        //     radix_sort_srt64(g->srt_b.aln.a, g->srt_b.aln.a + g->srt_b.aln.n);
        // }
    }

    return is_circle;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rax
movl 0x48(%rdi), %ecx
cmpq %rcx, %rax
jbe 0x20398a
cmpq %rax, 0x88(%rbx)
jae 0x2038f1
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x88(%rbx)
movq 0x90(%rbx), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x2370
movq %rax, 0x90(%rbx)
movq (%rbx), %rax
cmpq %rax, 0xa0(%rbx)
jae 0x203957
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0xa0(%rbx)
movq 0xa8(%rbx), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x2370
movq %rax, 0xa8(%rbx)
movq (%rbx), %rax
movq %rax, 0x98(%rbx)
movq %rax, 0x80(%rbx)
movl 0x48(%rbx), %ecx
cmpq %rcx, %rax
jbe 0x203995
movq 0x90(%rbx), %rdx
movq 0xa8(%rbx), %rsi
movl %ecx, (%rsi,%rcx,4)
movl %ecx, (%rdx,%rcx,4)
incl %ecx
cmpq %rcx, %rax
ja 0x20397b
jmp 0x203995
movl 0x4c(%rbx), %ecx
xorl %eax, %eax
cmpq %rcx, 0x18(%rbx)
jbe 0x2039e7
movq 0x18(%rbx), %rax
movl 0x4c(%rbx), %edx
cmpq %rdx, %rax
jbe 0x2039dd
movq 0x28(%rbx), %rcx
leal 0x1(%rdx), %esi
shlq $0x4, %rdx
movq (%rcx,%rdx), %rdi
btq $0x20, %rdi
jb 0x2039d4
addq %rcx, %rdx
movq 0xa8(%rbx), %r8
shrq $0x21, %rdi
movl (%r8,%rdi,4), %edi
movl 0x8(%rdx), %edx
shrl %edx
cmpl (%r8,%rdx,4), %edi
jae 0x2039e9
movl %esi, %edx
incl %esi
cmpq %rdx, %rax
ja 0x2039a8
movq %rbx, %rdi
callq 0x202003
xorl %eax, %eax
popq %rbx
retq
movq %rbx, %rdi
callq 0x202003
movq %rbx, %rdi
callq 0x2030f8
xorl $0x1, %eax
jmp 0x2039e7