// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: is_small_tangle(u_trans_t*, u_trans_t*, ma_ug_t*, ma_ug_t*, ma_ug_t*, scaf_res_t*, scaf_res_t*, asg32_v*, asg32_v*, asg32_v*, asg32_v*, unsigned char*, unsigned char*, unsigned char*, unsigned long, unsigned long*)
uint64_t is_small_tangle(u_trans_t *s, u_trans_t *e, ma_ug_t *ref, ma_ug_t *hu1, ma_ug_t *hu2, scaf_res_t *cp1, scaf_res_t *cp2, asg32_v *b1, asg32_v *b2, asg32_v *b3, asg32_v *b4, uint8_t *f, uint8_t *fs, uint8_t *fsk, uint64_t max_len, uint64_t *is_dip)
{
    uint64_t tot; uint32_t *va = NULL, *vd = NULL, *wa = NULL, *wd = NULL, vn = 0, wn = 0;
    b1->n = b2->n = b3->n = b4->n = 0; (*is_dip) = 0;
    // v = get_ref_nid(s, hu1, hu2, cp1, cp2, 1, 1000); if(v == ((uint64_t)-1)) return ((uint64_t)-1);
    // w = get_ref_nid(e, hu1, hu2, cp1, cp2, 0, 1000); if(w == ((uint64_t)-1)) return ((uint64_t)-1);
    // if((v>>1) == (w>>1)) return ((uint64_t)-1);
    
    // fprintf(stderr, "-0-[M::%s]\n", __func__);
    vn = get_ref_nid_flank(s, ref, hu1, hu2, cp1, cp2, 1, 1000, max_len, b3); if(!vn) return ((uint64_t)-1); 
    // fprintf(stderr, "-1-[M::%s]\n", __func__);
    wn = get_ref_nid_flank(e, ref, hu1, hu2, cp1, cp2, 0, 1000, max_len, b3); if(!wn) return ((uint64_t)-1);
    // fprintf(stderr, "-2-[M::%s]\n", __func__);
    va = b3->a; vd = va + vn; wa = vd + vn; wd = wa + wn; 
    // prt_scf_dbg_nds(s, va, vd, vn, ref, hu1, hu2, 0, 1, "rawS");
    // prt_scf_dbg_nds(e, wa, wd, wn, ref, hu1, hu2, 1, 0, "rawE");
    dedup_tang_flank(va, vd, &vn, wa, wd, &wn);
    if((!vn) || (!wn)) return ((uint64_t)-1);
    // prt_scf_dbg_nds(s, va, vd, vn, ref, hu1, hu2, 0, 1, "fffS");
    // prt_scf_dbg_nds(e, wa, wd, wn, ref, hu1, hu2, 1, 0, "fffE");

    tot = cal_self_close_tang_flank(ref->g, va, vd, vn, wa, wd, wn, b1, b2, b4, f, fs, fsk, max_len, is_dip);
    if(tot > max_len) tot = ((uint64_t)-1);
    return tot;

    // l0 = cal_self_close_tang(ref->g, v, w, b1, b2, f, max_len); if(l0 == ((uint64_t)-1)) return ((uint64_t)-1);
    // l1 = cal_self_close_tang(ref->g, w^1, v^1, b1, b2, f, max_len); if(l1 == ((uint64_t)-1)) return ((uint64_t)-1);
    // return MIN(l0, l1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movq %r9, -0x60(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movl $0x0, -0x90(%rbp)
movq 0x30(%rbp), %rax
movq $0x0, (%rax)
movq 0x28(%rbp), %rax
movq $0x0, (%rax)
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
movq 0x18(%rbp), %rax
movq $0x0, (%rax)
movq 0x58(%rbp), %rax
movq $0x0, (%rax)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x50(%rbp), %r10
movq 0x28(%rbp), %rax
movq $0x1, (%rsp)
movq $0x3e8, 0x8(%rsp)       # imm = 0x3E8
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x1298c0
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
jne 0x12cd2e
movq $-0x1, -0x30(%rbp)
jmp 0x12cecf
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x50(%rbp), %r10
movq 0x28(%rbp), %rax
xorl %r11d, %r11d
movq $0x0, (%rsp)
movq $0x3e8, 0x8(%rsp)       # imm = 0x3E8
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x1298c0
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
jne 0x12cd8d
movq $-0x1, -0x30(%rbp)
jmp 0x12cecf
movq 0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl -0x8c(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl -0x8c(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl -0x90(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %r8
leaq -0x8c(%rbp), %rdx
leaq -0x90(%rbp), %r9
callq 0x12a800
cmpl $0x0, -0x8c(%rbp)
je 0x12ce13
cmpl $0x0, -0x90(%rbp)
jne 0x12ce20
movq $-0x1, -0x30(%rbp)
jmp 0x12cecf
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x70(%rbp), %rsi
movq -0x78(%rbp), %rdx
movl -0x8c(%rbp), %ecx
movq -0x80(%rbp), %r8
movq -0x88(%rbp), %r9
movl -0x90(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq 0x18(%rbp), %r13
movq 0x20(%rbp), %r12
movq 0x30(%rbp), %r15
movq 0x38(%rbp), %r14
movq 0x40(%rbp), %rbx
movq 0x48(%rbp), %r11
movq 0x50(%rbp), %r10
movq 0x58(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, (%rsp)
movq -0x98(%rbp), %rax
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq %rax, 0x40(%rsp)
callq 0x12c4a0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq 0x50(%rbp), %rax
jbe 0x12cec7
movq $-0x1, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)