// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: trans_ovlp_connect1(u_trans_t*, ma_ug_t*)
uint32_t trans_ovlp_connect1(u_trans_t *p, ma_ug_t *ug)
{
	uint32_t v = p->qn<<1, w = (p->tn<<1) + ((uint32_t)p->rev), i, dg = (uint32_t)-1, da, dif, mm;
	asg_arc_t *av = asg_arc_a(ug->g, v); uint32_t nv = asg_arc_n(ug->g, v);
	for (i = 0; i < nv; i++) {
		if(av[i].del || av[i].v != w) continue;
		dg = av[i].ol; 
		break;
	}
    // if((v>>1) == 43 && (w>>1) == 45) {
    //     fprintf(stderr, "+[M::%s::] utg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tf::%u\n", __func__,
    //     p->qn+1, "lc"[s->ug->u.a[p->qn].circ], s->ug->u.a[p->qn].len, p->qs, p->qe, 
    //     "+-"[p->rev], p->tn+1, "lc"[s->ug->u.a[p->tn].circ], s->ug->u.a[p->tn].len, p->ts, p->te, p->f);
    // }

    if(i < nv) {
	    // if(i >= nv) return 1;
        da = (p->qe - p->qs);
        dif = (dg>da? dg-da:da-dg); mm = MAX(dg, da); mm *= 0.06; if(mm < 8) mm = 8;
        if(dif <= mm) return 0;

        da = (p->te - p->ts);
        dif = (dg>da? dg-da:da-dg); mm = MAX(dg, da); mm *= 0.06; if(mm < 8) mm = 8;
        if(dif <= mm) return 0;
    }

    v ^= 1; w ^= 1; dg = (uint32_t)-1;
    av = asg_arc_a(ug->g, v); nv = asg_arc_n(ug->g, v);
    for (i = 0; i < nv; i++) {
		if(av[i].del || av[i].v != w) continue;
		dg = av[i].ol; 
		break;
	}
    if(i < nv) {
	    // if(i >= nv) return 1;
        da = (p->qe - p->qs);
        dif = (dg>da? dg-da:da-dg); mm = MAX(dg, da); mm *= 0.06; if(mm < 8) mm = 8;
        if(dif <= mm) return 0;

        da = (p->te - p->ts);
        dif = (dg>da? dg-da:da-dg); mm = MAX(dg, da); mm *= 0.06; if(mm < 8) mm = 8;
        if(dif <= mm) return 0;
    }

	return 1;
}

// Assembly:
pushq %r14
pushq %rbx
movl 0x8(%rdi), %r8d
movl 0x14(%rdi), %eax
addl %r8d, %r8d
movl 0x28(%rdi), %ecx
shrl $0x6, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %ecx
movq 0x18(%rsi), %rax
movq 0x8(%rax), %rdx
movq 0x28(%rax), %rsi
movq (%rsi,%r8,8), %rax
testl %eax, %eax
je 0xc3b01
movq %rax, %r9
shrq $0x20, %r9
movl %eax, %r10d
leaq (%r9,%r9,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %r10
leaq (%r10,%r10,2), %r10
xorl %r11d, %r11d
movl (%rax,%r11), %r9d
testl %r9d, %r9d
js 0xc3af8
cmpl %ecx, -0x4(%rax,%r11)
je 0xc3b5a
addq $0x18, %r11
cmpq %r11, %r10
jne 0xc3ae8
movl %r8d, %eax
movq 0x8(%rsi,%rax,8), %rax
testl %eax, %eax
je 0xc3b51
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %r8d
leaq (%rsi,%rsi,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %r8
leaq (%r8,%r8,2), %rsi
xorl %r8d, %r8d
movl (%rax,%r8), %edx
testl %edx, %edx
js 0xc3b48
movl -0x4(%rax,%r8), %r9d
xorl %ecx, %r9d
cmpl $0x1, %r9d
je 0xc3be2
addq $0x18, %r8
cmpq %r8, %rsi
jne 0xc3b2e
movl $0x1, %eax
popq %rbx
popq %r14
retq
movl 0x4(%rdi), %r11d
subl (%rdi), %r11d
movl %r9d, %eax
subl %r11d, %eax
movl %r11d, %r10d
cmoval %r9d, %r10d
subl %r9d, %r11d
cmovbl %eax, %r11d
cvtsi2sd %r10, %xmm0
mulsd 0x16dae6(%rip), %xmm0   # 0x231668
cvttsd2si %xmm0, %rbx
cmpl $0x9, %ebx
movl $0x8, %r10d
cmovbl %r10d, %ebx
xorl %eax, %eax
cmpl %ebx, %r11d
jbe 0xc3b56
movl 0x10(%rdi), %r11d
subl 0xc(%rdi), %r11d
movl %r9d, %ebx
subl %r11d, %ebx
movl %r11d, %r14d
cmoval %r9d, %r14d
subl %r9d, %r11d
cmovbl %ebx, %r11d
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
mulsd 0x16daa1(%rip), %xmm0   # 0x231668
cvttsd2si %xmm0, %r9
cmpl $0x9, %r9d
cmovael %r9d, %r10d
cmpl %r10d, %r11d
ja 0xc3b01
jmp 0xc3b56
movl 0x4(%rdi), %esi
subl (%rdi), %esi
movl %edx, %eax
subl %esi, %eax
movl %esi, %ecx
cmoval %edx, %ecx
subl %edx, %esi
cmovbl %eax, %esi
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x16da63(%rip), %xmm0   # 0x231668
cvttsd2si %xmm0, %r8
cmpl $0x9, %r8d
movl $0x8, %ecx
cmovbl %ecx, %r8d
xorl %eax, %eax
cmpl %r8d, %esi
jbe 0xc3b56
movl 0x10(%rdi), %esi
subl 0xc(%rdi), %esi
movl %edx, %edi
subl %esi, %edi
movl %esi, %r8d
cmoval %edx, %r8d
subl %edx, %esi
cmovbl %edi, %esi
xorps %xmm0, %xmm0
cvtsi2sd %r8, %xmm0
mulsd 0x16da20(%rip), %xmm0   # 0x231668
cvttsd2si %xmm0, %rdx
cmpl $0x9, %edx
cmovael %edx, %ecx
cmpl %ecx, %esi
ja 0xc3b51
jmp 0xc3b56