// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movl 0x38(%rbp), %eax
movl 0x30(%rbp), %eax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movl %r8d, -0x3c(%rbp)
movq %r9, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movl %eax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl -0x50(%rbp), %eax
movl %eax, %esi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x50(%rbp), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rdi
movl -0x50(%rbp), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x10(%rbp), %rax
movq (%rax), %rdx
movq -0x48(%rbp), %rax
movq (%rax), %rcx
movl 0x30(%rbp), %r8d
callq 0x360ee0
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x35f8d0
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %r8
movq 0x20(%rbp), %r9
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, (%rsp)
callq 0x361c40
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x1e0(%rcx), %rax
jae 0x363f7a
movq -0x30(%rbp), %rax
movq 0x1d8(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x328, %rcx, %rcx      # imm = 0x328
addq %rcx, %rax
movq $0x0, 0x78(%rax)
movq -0x30(%rbp), %rax
movq 0x1d8(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x328, %rcx, %rcx      # imm = 0x328
addq %rcx, %rax
movq $0x0, 0x90(%rax)
movq -0x30(%rbp), %rax
movq 0x1d8(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x328, %rcx, %rcx      # imm = 0x328
addq %rcx, %rax
movq $0x0, 0x300(%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x363ef6
cmpl $0x0, 0x38(%rbp)
je 0x363fa6
movq -0x30(%rbp), %rax
movq 0x1e0(%rax), %rax
movl %eax, %edi
movq -0x80(%rbp), %rcx
leaq 0x278(%rip), %rsi       # 0x364210
leaq -0xc0(%rbp), %rdx
callq 0x16d710
jmp 0x363fca
movq -0x30(%rbp), %rax
movq 0x1e0(%rax), %rax
movl %eax, %edi
movq -0x80(%rbp), %rcx
leaq 0x4c2(%rip), %rsi       # 0x364480
leaq -0xc0(%rbp), %rdx
callq 0x16d710
movl $0x0, -0x54(%rbp)
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x1e0(%rcx), %rax
jae 0x364174
movq -0x30(%rbp), %rax
movq 0x1d8(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x328, %rcx, %rcx      # imm = 0x328
addq %rcx, %rax
movq 0x300(%rax), %rcx
movl -0x54(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x54(%rbp)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x54(%rbp), %ecx
cmpq %rcx, %rax
jae 0x3640fb
movl -0x54(%rbp), %eax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq 0x20(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x3640fd
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x1d8(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x328, %rcx, %rcx      # imm = 0x328
addq %rcx, %rax
movq 0x310(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x1d8(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x328, %rcx, %rcx      # imm = 0x328
addq %rcx, %rax
movq 0x300(%rax), %rdx
shlq $0x3, %rdx
callq 0x2180
movl -0x54(%rbp), %eax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x363fe3
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x30ed90
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %r8
movl -0x3c(%rbp), %r9d
movq -0x48(%rbp), %rax
movq (%rax), %r15
movq 0x10(%rbp), %rax
movq (%rax), %r14
movq 0x18(%rbp), %rax
movq (%rax), %rbx
movq 0x20(%rbp), %r11
movq 0x28(%rbp), %r10
movl -0x54(%rbp), %eax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x363650
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq