// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %r9, %rbx
movq %r8, 0x10(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x70(%rsp), %r14
movl $0x1, %edi
movl $0x38, %esi
callq 0x2120
movq %rax, %r13
movl $0x1, %edi
movl $0x48, %esi
callq 0x2120
movq %rax, %rbp
movq %rax, 0x18(%r13)
movq 0x8(%r14), %r14
addq 0x8(%rbx), %r14
movl %r14d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl %edi, 0x14(%rax)
movl %edi, 0x10(%rax)
shlq $0x3, %rdi
callq 0x2280
movq %rax, %r15
movq %rax, 0x20(%rbp)
movq %r14, (%r13)
movq %r14, 0x8(%r13)
movl $0x28, %esi
movq %r14, %rdi
callq 0x2120
movq %rax, %r12
movq %r13, 0x30(%rsp)
movq %rax, 0x10(%r13)
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
je 0xe076d
xorl %eax, %eax
movl $0x80000000, %ecx       # imm = 0x80000000
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movb $0x0, 0x4(%r15,%rax,8)
andb $0x7f, 0x3(%r15,%rax,8)
movq %rax, %rsi
subq 0x8(%rbx), %rsi
jae 0xe06d5
movq %rax, %rsi
shlq $0x5, %rsi
addq (%rbx), %rsi
jmp 0xe06e1
shlq $0x5, %rsi
movq 0x70(%rsp), %rdi
addq (%rdi), %rsi
movq 0x8(%rsi), %rdi
testq %rdi, %rdi
je 0xe0728
movq 0x78(%rsp), %r8
movq 0x10(%r8), %r8
movq 0x18(%rsi), %r9
xorl %esi, %esi
xorl %r10d, %r10d
movq (%r9,%r10,8), %r11
movl %r11d, %r14d
shrl %r14d
leaq (%r14,%r14,4), %r14
movl (%r8,%r14,8), %r14d
shrq $0x20, %r11
addq %r11, %rsi
addq %r14, %rsi
incq %r10
cmpq %r10, %rdi
jne 0xe06fc
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
jmp 0xe072a
xorl %esi, %esi
movq 0x20(%rbp), %rdi
movl (%rdi,%rax,8), %r8d
andl %ecx, %r8d
orl %esi, %r8d
movl %r8d, (%rdi,%rax,8)
movq 0x20(%rbp), %r15
movl (%r15,%rax,8), %esi
andl %edx, %esi
leaq (%rax,%rax,4), %rdi
movl (%r12,%rdi,8), %r8d
andl %ecx, %r8d
orl %esi, %r8d
movl %r8d, (%r12,%rdi,8)
incq %rax
movl 0x14(%rbp), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
cmpq %rsi, %rax
jb 0xe06b4
movq %rbp, %rdi
callq 0xa0a7d
movq %rbp, %rdi
callq 0xa0ab6
movq %rbp, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%rbp)
movq 0x70(%rsp), %rax
movl 0x8(%rax), %edi
addl 0x8(%rbx), %edi
callq 0x37dfd
movq %rax, %rbp
cmpq $0x0, 0x8(%rax)
je 0xe0801
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r15, %rdi
subq 0x8(%rbx), %rdi
jae 0xe07bd
movq (%rbx), %rdi
addq %r14, %rdi
jmp 0xe07c9
shlq $0x5, %rdi
movq 0x70(%rsp), %rax
addq (%rax), %rdi
movl (%r12), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq (%rbp), %r8
addq %r13, %r8
movq 0x78(%rsp), %rdx
movq 0x80(%rsp), %rcx
callq 0xe00e3
incq %r15
addq $0x58, %r13
addq $0x28, %r12
addq $0x20, %r14
cmpq 0x8(%rbp), %r15
jb 0xe07ac
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %r15
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x30(%rsp), %r14
movq %r14, %rdx
movq %rbp, %rcx
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %r9
pushq $0x1
pushq %rax
pushq 0x38(%rsp)
pushq 0x8(%rbx)
callq 0x27feb
addq $0x20, %rsp
movq 0x70(%rsp), %rax
movl 0x8(%rax), %esi
addl 0x8(%rbx), %esi
movq %r15, %rdi
callq 0xc4edd
movq %r15, %rdi
callq 0xdb90d
movq %r14, %rdi
callq 0xa0761
movq %rbp, %rdi
callq 0x37e37
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq