// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x2140
movq %rax, -0x38(%rbp)
callq 0xcd150
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rbp), %rcx
addq 0x8(%rcx), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %ecx, %edx
movl %edx, 0x14(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rbp), %rax
addq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movl $0x28, %esi
callq 0x2140
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x131439
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movb $0x0, 0x4(%rax,%rcx,8)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x0, %edx
movl %edx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x131394
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
jmp 0x1313b2
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq 0x8(%rdx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq 0x18(%rbp), %rsi
callq 0x167fc0
movl %eax, %esi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x13131a
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xcdd10
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xce020
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rbp), %rcx
addq 0x8(%rcx), %rax
movl %eax, %edi
callq 0x13bf0
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x131520
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1314ae
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
jmp 0x1314cc
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq 0x8(%rdx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %esi
movq 0x18(%rbp), %rdx
movq 0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq (%rax), %r8
imulq $0x58, -0x48(%rbp), %rax
addq %rax, %r8
callq 0x1305d0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x131476
movq $0x0, -0x58(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2140
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %r8
movq -0x20(%rbp), %r9
movq -0x30(%rbp), %rax
movq 0x8(%rax), %r11
movq -0x18(%rbp), %r10
movq -0x58(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movl $0x1, 0x18(%rsp)
callq 0x2ffd20
movq -0x58(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rbp), %rcx
addq 0x8(%rcx), %rax
movl %eax, %esi
callq 0x104540
movq -0x58(%rbp), %rdi
callq 0x127a10
movq -0x38(%rbp), %rdi
callq 0xcd6f0
movq -0x40(%rbp), %rdi
callq 0x13c50
movq -0x58(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)