// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movl %r8d, 0x4(%rsp)
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, 0x8(%rsp)
movq %rdi, %rbp
movq 0xd0(%rsp), %r14
movl 0x8(%rcx), %ebx
addl %ebx, %ebx
movq (%r9), %rdi
movq %rbx, %rsi
callq 0x2370
movq %rax, (%r15)
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 (%r15), %rcx
movq %r12, %rdi
movq %r13, %rsi
movl 0xe0(%rsp), %r8d
callq 0x1cfb2b
movq %r12, %rdi
movq %rbp, %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
callq 0x1cefc1
movq (%rbx), %rdx
movq 0x10(%rbx), %rsi
movq (%rbp), %r8
movq 0x10(%rbp), %rcx
subq $0x8, %rsp
movq %r13, %rdi
movq %r14, %r9
movq 0xd0(%rsp), %rax
pushq (%rax)
callq 0x1d0236
popq %rax
popq %rcx
movq %r15, 0x18(%rsp)
movq (%r15), %rax
movq %rax, 0x48(%rsp)
movq %r13, 0x10(%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(%rbp), %rax
movq %rax, 0x68(%rsp)
movq %rbp, %r13
movq (%rbp), %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
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, %rdi
jbe 0x1d1734
movq 0x1d8(%r12), %rdx
imulq $0x328, %rax, %rsi      # imm = 0x328
andq $0x0, 0x78(%rdx,%rsi)
andq $0x0, 0x90(%rdx,%rsi)
andq $0x0, 0x300(%rdx,%rsi)
incl %eax
jmp 0x1d1702
cmpl $0x0, 0xe8(%rsp)
leaq 0x27c(%rip), %rax       # 0x1d19bf
leaq 0x12d(%rip), %rsi       # 0x1d1877
cmoveq %rax, %rsi
leaq 0x20(%rsp), %rdx
callq 0xc67c0
andq $0x0, (%r14)
xorl %ecx, %ecx
xorl %ebp, %ebp
xorl %ebx, %ebx
movl %ebp, %ebp
cmpq %rbp, 0x1e0(%r12)
jbe 0x1d181b
movq 0x1d8(%r12), %rsi
imulq $0x328, %rbp, %r15      # imm = 0x328
movq 0x300(%rsi,%r15), %rdx
addl %edx, %ebx
movq 0x10(%r14), %rax
cmpq %rbx, 0x8(%r14)
jae 0x1d17f9
leaq -0x1(%rbx), %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 %rbx, (%r14)
incl %ebp
movq %rbx, %rcx
jmp 0x1d1762
movq 0x10(%r14), %rdi
leaq (%rdi,%rcx,8), %rsi
callq 0x1a3def
movq 0x10(%r13), %r8
movl %ebx, %eax
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movl 0x4(%rsp), %r9d
pushq %rax
pushq 0xe0(%rsp)
pushq %r14
movq 0xe0(%rsp), %rax
pushq (%rax)
movq 0xe0(%rsp), %rax
pushq (%rax)
movq 0x40(%rsp), %rax
pushq (%rax)
callq 0x1d11bc
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq