// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x70(%rsp), %r12
movl $0x1, %edi
movl $0x38, %esi
callq 0x2120
movq %rax, %r14
movl $0x1, %edi
movl $0x48, %esi
callq 0x2120
movq %rax, %r13
movq %rax, 0x18(%r14)
movq 0x8(%r12), %rbp
addq 0x8(%rbx), %rbp
movl $0x80000000, %r15d      # imm = 0x80000000
movl 0x14(%rax), %eax
andl %r15d, %eax
movl %ebp, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
orl %edi, %eax
movl %eax, 0x14(%r13)
movl %edi, 0x10(%r13)
shlq $0x3, %rdi
callq 0x2280
movq %rax, 0x20(%r13)
movq %rbp, (%r14)
movq %rbp, 0x8(%r14)
movl $0x28, %esi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0x10(%r14)
movq 0x18(%r14), %rdi
testl $0x7fffffff, 0x14(%rdi) # imm = 0x7FFFFFFF
je 0xdf3fa
xorl %eax, %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x20(%rdi), %rdx
movb $0x0, 0x4(%rdx,%rax,8)
andb $0x7f, 0x3(%rdx,%rax,8)
movq %rax, %rdx
subq 0x8(%rbx), %rdx
jae 0xdf35a
movq %rax, %rdx
shlq $0x5, %rdx
addq (%rbx), %rdx
jmp 0xdf362
shlq $0x5, %rdx
addq (%r12), %rdx
movq 0x8(%rdx), %rsi
testq %rsi, %rsi
je 0xdf3a9
movq 0x78(%rsp), %rdi
movq 0x10(%rdi), %rdi
movq 0x18(%rdx), %r8
xorl %edx, %edx
xorl %r9d, %r9d
movq (%r8,%r9,8), %r10
movl %r10d, %r11d
shrl %r11d
leaq (%r11,%r11,4), %r11
movl (%rdi,%r11,8), %r11d
shrq $0x20, %r10
addq %r10, %rdx
addq %r11, %rdx
incq %r9
cmpq %r9, %rsi
jne 0xdf37d
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0xdf3ab
xorl %edx, %edx
movq 0x18(%r14), %rsi
movq 0x20(%rsi), %rsi
movl (%rsi,%rax,8), %edi
andl %r15d, %edi
orl %edx, %edi
movl %edi, (%rsi,%rax,8)
movq 0x10(%r14), %rdx
movq 0x18(%r14), %rsi
movq 0x20(%rsi), %rsi
movl (%rsi,%rax,8), %esi
andl %ecx, %esi
leaq (%rax,%rax,4), %rdi
movl (%rdx,%rdi,8), %r8d
andl %r15d, %r8d
orl %esi, %r8d
movl %r8d, (%rdx,%rdi,8)
incq %rax
movq 0x18(%r14), %rdi
movl 0x14(%rdi), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rax
jb 0xdf337
callq 0xa02fa
movq 0x18(%r14), %r13
movq %r13, %rdi
callq 0xa0333
movq %r13, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%r13)
movl 0x8(%r12), %edi
movq %rbx, 0x8(%rsp)
addl 0x8(%rbx), %edi
callq 0x3883c
movq %rax, %r13
cmpq $0x0, 0x8(%rax)
je 0xdf49c
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %rbx, %rdi
movq 0x8(%rsp), %rax
subq 0x8(%rax), %rdi
jae 0xdf454
movq (%rax), %rdi
addq %r15, %rdi
jmp 0xdf460
shlq $0x5, %rdi
movq 0x70(%rsp), %rax
addq (%rax), %rdi
movq 0x10(%r14), %rax
movl (%rax,%r12), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq (%r13), %r8
addq %rbp, %r8
movq 0x78(%rsp), %rdx
movq 0x80(%rsp), %rcx
callq 0xded78
incq %rbx
addq $0x58, %rbp
addq $0x28, %r12
addq $0x20, %r15
cmpq 0x8(%r13), %rbx
jb 0xdf43e
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
movq %r13, %rcx
movq 0x20(%rsp), %r8
movq 0x28(%rsp), %r9
pushq $0x1
pushq %rax
pushq 0x40(%rsp)
movq 0x20(%rsp), %rbx
pushq 0x8(%rbx)
callq 0x28a75
addq $0x20, %rsp
movq 0x70(%rsp), %rax
movl 0x8(%rax), %esi
addl 0x8(%rbx), %esi
movq %r12, %rdi
callq 0xc405a
movq %r12, %rdi
callq 0xda47b
movq %r14, %rdi
callq 0xa0004
movq %r13, %rdi
callq 0x38876
movq %r12, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq