// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r15
movq %rcx, %r12
movq %rdx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq 0x98(%rsp), %rcx
movq 0x70(%rsp), %rax
andq $0x0, (%rax)
movq 0x68(%rsp), %r13
andq $0x0, (%r13)
movq 0x60(%rsp), %rax
andq $0x0, (%rax)
movq 0x58(%rsp), %rax
andq $0x0, (%rax)
movq 0x50(%rsp), %rbx
andq $0x0, (%rcx)
movq %r12, %rdx
movq %r9, %r8
movq %rbx, %r9
pushq %r13
pushq 0x98(%rsp)
pushq $0x3e8                  # imm = 0x3E8
pushq $0x1
callq 0x9f20d
addq $0x20, %rsp
movq %rax, %rbp
movl %ebp, 0x4(%rsp)
pushq $-0x1
popq %r14
testl %ebp, %ebp
je 0xa0d0d
movq 0x10(%rsp), %rdi
movq %r12, %rdx
movq %r15, %r8
movq %rbx, %r9
pushq %r13
pushq 0x98(%rsp)
pushq $0x3e8                  # imm = 0x3E8
pushq $0x0
callq 0x9f20d
addq $0x20, %rsp
movq %rax, %r12
movl %r12d, (%rsp)
testl %r12d, %r12d
je 0xa0d0d
movq 0x10(%r13), %r13
movl %ebp, %r15d
shlq $0x2, %r15
leaq (%r15,%r13), %rbp
addq %rbp, %r15
leaq 0x4(%rsp), %rbx
movq %rsp, %r9
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x9f847
movl (%rbx), %ecx
testl %ecx, %ecx
setne %dl
movq %rsp, %rax
movl (%rax), %eax
testl %eax, %eax
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xa0d0d
movl %r12d, %edx
leaq (%r15,%rdx,4), %r9
movq 0x8(%rsp), %rdx
movq 0x18(%rdx), %rdi
subq $0x8, %rsp
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %r8
pushq 0xa0(%rsp)
movq 0xa0(%rsp), %rbx
pushq %rbx
pushq 0xa0(%rsp)
pushq 0xa0(%rsp)
pushq 0xa0(%rsp)
pushq 0xa0(%rsp)
pushq 0x98(%rsp)
pushq 0x98(%rsp)
pushq %rax
callq 0xa074a
addq $0x50, %rsp
cmpq %rbx, %rax
pushq $-0x1
popq %r14
cmovbeq %rax, %r14
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq