// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ug_ext_free(asg64_v*, asg64_v*, ul_resolve_t*, usg_t*, unsigned int, unsigned char**, unsigned int**, unsigned long**, asg64_v*, asg64_v*, unsigned int, unsigned int)
uint32_t ug_ext_free(asg64_v *ob, asg64_v *ub, ul_resolve_t *uidx, usg_t *ng, uint32_t max_ext, 
uint8_t **ff, uint32_t **ng_occ, uint64_t **i_idx, asg64_v *b64, asg64_v *ub64, uint32_t rocc_cut, 
uint32_t thread_path)
{
    // fprintf(stderr, "[M::%s::] rocc_cut::%u\n", __func__, rocc_cut);
    uint32_t k, n_vtx = ng->n<<1, a_n; unique_bridge_check_t u_aux;
    REALLOC((*ff), n_vtx); REALLOC((*ng_occ), n_vtx); REALLOC((*i_idx), n_vtx);
    renew_usg_t_bub(uidx, ng, *ng_occ, *ff, rocc_cut);
    u2g_hybrid_aln(uidx, ng, ob, ub);
    gen_hybrid_aln_idx(ng, ub->a, ub->n, ob->a, ob->n, b64, *i_idx);
    // if(rocc_cut == 10) 
    // {
    //     fprintf(stderr, "\n[M::%s::] rocc_cut::%u\n", __func__, rocc_cut);
    //     debug_prt_renew_aln(ng, ub->a, ub->n, ob->a, ob->n, b64, *i_idx);
    // }

    u_aux.f = *ff; u_aux.ng = ng; u_aux.int_idx = ub->a; u_aux.int_idx_n = ub->n; u_aux.uidx = uidx;
    u_aux.int_a = ob->a; u_aux.int_an = ob->n; u_aux.ridx_a = b64->a; u_aux.ridx = *i_idx;
    for (k = 0; k < uidx->str_b.n_thread; k++) {
        uidx->str_b.buf[k].res_dump.n = uidx->str_b.buf[k].u.n = uidx->str_b.buf[k].o.n = 0;
    }

    if(thread_path) {
        kt_for(uidx->str_b.n_thread, worker_ul_aln_path, &u_aux, u_aux.int_idx_n);
    } else {
        kt_for(uidx->str_b.n_thread, worker_ul_aln_pair, &u_aux, u_aux.int_idx_n);
    }

    for (k = b64->n = a_n = 0; k < uidx->str_b.n_thread; k++) {
        a_n += uidx->str_b.buf[k].res_dump.n;
        kv_resize(uint64_t, *b64, a_n);
        memcpy(b64->a+b64->n, uidx->str_b.buf[k].res_dump.a, uidx->str_b.buf[k].res_dump.n*(sizeof(*(b64->a))));
        b64->n = a_n;
    }
    radix_sort_srt64(b64->a, b64->a + b64->n);///keeps the coordinates within int_a[]
    // fprintf(stderr, "[M::%s::] a_n::%u, int_idx_n::%u, int_n::%u\n", 
    //                 __func__, a_n, (uint32_t)ub->n, (uint32_t)ob->n);
    a_n = ug_ext_0(uidx, ng, ub->a, ub->n, ob->a, max_ext, *ff, *ng_occ, *i_idx, b64, ub64, a_n);
    // if(a_n) usg_cleanup(ng);
    return a_n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %rbp
movl %r8d, 0x4(%rsp)
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
movq 0xd0(%rsp), %r14
movl 0x8(%rcx), %ebx
addl %ebx, %ebx
movq (%r9), %rdi
movq %rbx, %rsi
callq 0x2370
movq %rax, (%rbp)
movq 0xc0(%rsp), %rax
movq (%rax), %rdi
leaq (,%rbx,4), %rsi
callq 0x2370
movq 0xc0(%rsp), %rcx
movq %rax, (%rcx)
movq 0xc8(%rsp), %rax
movq (%rax), %rdi
shlq $0x3, %rbx
movq %rbx, %rsi
callq 0x2370
movq 0xc8(%rsp), %rcx
movq %rax, (%rcx)
movq 0xc0(%rsp), %rax
movq (%rax), %rdx
movq (%rbp), %rcx
movq %r12, %rdi
movq %r13, %rsi
movl 0xe0(%rsp), %r8d
callq 0x21e98e
movq %r12, %rdi
movq %r15, %rdx
movq 0x10(%rsp), %rbx
movq %rbx, %rcx
callq 0x21dd4b
movq (%rbx), %rdx
movq 0x10(%rbx), %rsi
movq (%r15), %r8
movq 0x10(%r15), %rcx
subq $0x8, %rsp
movq %r13, %rdi
movq %r14, %r9
movq 0xd0(%rsp), %rax
pushq (%rax)
callq 0x21f140
addq $0x10, %rsp
movq %rbp, 0x8(%rsp)
movq (%rbp), %rax
movq %rax, 0x48(%rsp)
movq %r13, 0x18(%rsp)
movq %r13, 0x50(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x58(%rsp)
movq (%rbx), %rcx
movq %rcx, 0x60(%rsp)
movq %r12, 0x20(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x68(%rsp)
movq %r15, %r13
movq (%r15), %rax
movq %rax, 0x70(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x78(%rsp)
movq 0xc8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x80(%rsp)
movq 0x1e0(%r12), %rdi
testq %rdi, %rdi
je 0x220688
movq 0x1d8(%r12), %rax
addq $0x78, %rax
movl $0x1, %edx
xorl %esi, %esi
movq %rsi, (%rax)
movq %rsi, 0x18(%rax)
movq %rsi, 0x288(%rax)
movl %edx, %r8d
addq $0x328, %rax            # imm = 0x328
incl %edx
cmpq %r8, %rdi
ja 0x22066a
movq 0xd8(%rsp), %r15
cmpl $0x0, 0xe8(%rsp)
leaq 0x296(%rip), %rax       # 0x220935
leaq 0x147(%rip), %rsi       # 0x2207ed
cmoveq %rax, %rsi
leaq 0x20(%rsp), %rdx
callq 0x108f2c
movq $0x0, (%r14)
xorl %ebp, %ebp
cmpq $0x0, 0x1e0(%r12)
je 0x220798
movl $0x1, %ebx
xorl %ecx, %ecx
xorl %eax, %eax
movq 0x1d8(%r12), %rsi
imulq $0x328, %rax, %r15      # imm = 0x328
movq 0x300(%rsi,%r15), %rdx
addl %edx, %ebp
movq 0x10(%r14), %rax
cmpq %rbp, 0x8(%r14)
jae 0x22075c
leaq -0x1(%rbp), %rcx
movq %rcx, %rdx
shrq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x10, %rdx
orq %rcx, %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x8(%r14)
leaq 0x8(,%rdx,8), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movq 0x1d8(%r12), %rsi
movq 0x300(%rsi,%r15), %rdx
leaq (%rax,%rcx,8), %rdi
movq 0x310(%rsi,%r15), %rsi
shlq $0x3, %rdx
callq 0x2160
movq %rbp, (%r14)
movl %ebx, %eax
incl %ebx
movq %rbp, %rcx
cmpq %rax, 0x1e0(%r12)
ja 0x2206d5
movq 0x8(%rsp), %rbx
movq 0xd8(%rsp), %r15
jmp 0x22079d
movq 0x8(%rsp), %rbx
movq 0x10(%r14), %rdi
leaq (%rdi,%rbp,8), %rsi
callq 0x1ee586
movq 0x10(%r13), %r8
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movl 0x4(%rsp), %r9d
pushq %rbp
pushq %r15
pushq %r14
movq 0xe0(%rsp), %rax
pushq (%rax)
movq 0xe0(%rsp), %rax
pushq (%rax)
pushq (%rbx)
callq 0x2200d2
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq