// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: cal_scaf_trans(ug_opt_t*, ma_ug_t*, bubble_type*, kv_u_trans_t*, asg_t*, kvect_sec_t*, kvect_sec_t*, ma_ug_t*, scaf_res_t*)
kv_u_trans_t* cal_scaf_trans(ug_opt_t *opt, ma_ug_t *ref, bubble_type *bu, kv_u_trans_t *bd, asg_t *sg, kvect_sec_t *sc0, kvect_sec_t *sc1, ma_ug_t *mg, scaf_res_t *ms)
{
    ma_ug_t *smg = NULL; scaf_res_t *sms = NULL; uint64_t k; sec_t *u;
    ///build ug
    CALLOC(smg, 1); 
    smg->g = asg_init(); 
    smg->g->m_seq = smg->g->n_seq = sc0->n + sc1->n; MALLOC(smg->g->seq, smg->g->n_seq);
    smg->u.m = smg->u.n = sc0->n + sc1->n; CALLOC(smg->u.a, smg->u.n);
    for (k = 0; k < smg->g->n_seq; k++) {
        smg->g->seq[k].c = 0; smg->g->seq[k].del = 0; 
        u = ((k<sc0->n)?&(sc0->a[k]):&(sc1->a[k-sc0->n]));
        smg->g->seq[k].len = get_scp_len(u, mg);
        smg->u.a[k].len = smg->g->seq[k].len;
    }
    asg_cleanup(smg->g); asg_symm(smg->g);
    
    ///build scaf
    sms = init_scaf_res_t(sc0->n + sc1->n); 
    for (k = 0; k < sms->n; k++) {
        u = ((k<sc0->n)?&(sc0->a[k]):&(sc1->a[k-sc0->n]));
        gen_scaf_res_via(u, smg->u.a[k].len, mg, ms, &(sms->a[k]));
    }

    kv_u_trans_t *p = NULL; CALLOC(p, 1);
    gen_contig_self(opt, sg, smg, sms, ref, bd, sc0->n, bu, p, 1);

    kt_u_trans_t_idx(p, sc0->n + sc1->n);
    update_ctg_trans_cc(p);
    
    ma_ug_destroy(smg); 
    destroy_scaf_res_t(sms);
    return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %rbx
movq %r8, 0x20(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x80(%rsp), %r14
pushq $0x1
popq %rdi
pushq $0x38
popq %rsi
callq 0x2120
movq %rax, %r13
callq 0x68f5d
movq %rax, %r15
movq %rax, 0x18(%r13)
movq 0x8(%r14), %rbp
movq %rbx, 0x8(%rsp)
addq 0x8(%rbx), %rbp
movl $0x80000000, %eax       # imm = 0x80000000
movl 0x14(%r15), %r12d
andl %eax, %r12d
movl %ebp, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
orl %edi, %r12d
movl %r12d, 0x14(%r15)
movl %edi, 0x10(%r15)
shlq $0x3, %rdi
callq 0x2280
movq %rax, %r14
movq %rax, 0x20(%r15)
movq %rbp, (%r13)
movq %rbp, 0x8(%r13)
pushq $0x28
popq %rsi
movq %rbp, %rdi
callq 0x2120
movq %rax, %rbp
movq %r13, 0x40(%rsp)
movq %rax, 0x10(%r13)
xorl %r13d, %r13d
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
cmpq %r12, %rbx
jae 0xa2e41
movb $0x0, 0x4(%r14,%rbx,8)
andb $0x7f, 0x3(%r14,%rbx,8)
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
cmpq %rax, %rbx
jae 0xa2ddd
movq %rbx, %rdi
shlq $0x5, %rdi
addq (%rcx), %rdi
jmp 0xa2df2
movq 0x80(%rsp), %rcx
movq (%rcx), %rdi
shlq $0x5, %rax
subq %rax, %rdi
addq %r13, %rdi
movq 0x88(%rsp), %rsi
callq 0xc38e6
movq 0x20(%r15), %rcx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %eax
movl (%rcx,%rbx,8), %edx
movl $0x80000000, %esi       # imm = 0x80000000
andl %esi, %edx
orl %eax, %edx
movl %edx, (%rcx,%rbx,8)
movq 0x20(%r15), %r14
movl (%r14,%rbx,8), %eax
andl %edi, %eax
movl (%rbp), %ecx
andl %esi, %ecx
orl %eax, %ecx
movl %ecx, (%rbp)
incq %rbx
movl 0x14(%r15), %r12d
addq $0x20, %r13
addq $0x28, %rbp
jmp 0xa2da7
movq %r15, %rdi
callq 0x694eb
movq %r15, %rdi
callq 0x69638
movq 0x80(%rsp), %rbp
movl 0x8(%rbp), %edi
movq 0x8(%rsp), %r12
addl 0x8(%r12), %edi
callq 0xbadd
movq %rax, %r15
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq 0x8(%r15), %r13
jae 0xa2ee7
movq 0x8(%r12), %rax
cmpq %rax, %r13
jae 0xa2e93
movq %r13, %rdi
shlq $0x5, %rdi
addq (%r12), %rdi
jmp 0xa2ea8
movq 0x80(%rsp), %rcx
movq (%rcx), %rdi
shlq $0x5, %rax
subq %rax, %rdi
addq %r14, %rdi
movq 0x10(%rsp), %rbp
movl (%rbp), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq (%r15), %r8
addq %rbx, %r8
movq 0x88(%rsp), %rdx
movq 0x90(%rsp), %rcx
callq 0xa2819
incq %r13
addq $0x20, %r14
addq $0x28, %rbp
movq %rbp, 0x10(%rsp)
addq $0x58, %rbx
jmp 0xa2e76
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x2120
movq %rax, %r14
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %rbx
movq %rbx, %rdx
movq %r15, %rcx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
pushq $0x1
pushq %rax
pushq 0x48(%rsp)
pushq 0x8(%r12)
callq 0x19c162
addq $0x20, %rsp
movq 0x80(%rsp), %rax
movl 0x8(%rax), %esi
addl 0x8(%r12), %esi
movq %r14, %rdi
callq 0x88a31
movq %r14, %rdi
callq 0x9e234
movq %rbx, %rdi
callq 0x6921d
movq %r15, %rdi
callq 0xbb11
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq