// File: 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 %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
shll %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
shll %eax
movq -0x10(%rbp), %rcx
movb 0x28(%rcx), %cl
shrb $0x6, %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x44(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x101c57
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x101c2f
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x20(%rbp), %eax
je 0x101c31
jmp 0x101c4c
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x28(%rbp)
jmp 0x101c57
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x101bf8
movl -0x24(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x101d7c
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
subl (%rcx), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x101c86
movl -0x28(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x101c8f
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jb 0x101ca5
movl -0x28(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x101cab
movl -0x2c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x280617(%rip), %xmm1   # 0x3822d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x34(%rbp)
cmpl $0x8, -0x34(%rbp)
jae 0x101cda
movl $0x8, -0x34(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
ja 0x101cee
movl $0x0, -0x4(%rbp)
jmp 0x101f68
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x101d12
movl -0x28(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x101d1b
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jb 0x101d31
movl -0x28(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x101d37
movl -0x2c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x28058b(%rip), %xmm1   # 0x3822d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x34(%rbp)
cmpl $0x8, -0x34(%rbp)
jae 0x101d66
movl $0x8, -0x34(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
ja 0x101d7a
movl $0x0, -0x4(%rbp)
jmp 0x101f68
jmp 0x101d7c
movl -0x1c(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x44(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x101e3f
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x101e17
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x20(%rbp), %eax
je 0x101e19
jmp 0x101e34
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x28(%rbp)
jmp 0x101e3f
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x101de0
movl -0x24(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x101f61
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
subl (%rcx), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x101e6e
movl -0x28(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x101e77
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jb 0x101e8d
movl -0x28(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x101e93
movl -0x2c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x28042f(%rip), %xmm1   # 0x3822d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x34(%rbp)
cmpl $0x8, -0x34(%rbp)
jae 0x101ec2
movl $0x8, -0x34(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
ja 0x101ed6
movl $0x0, -0x4(%rbp)
jmp 0x101f68
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x101efa
movl -0x28(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x101f03
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jb 0x101f19
movl -0x28(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x101f1f
movl -0x2c(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x2803a3(%rip), %xmm1   # 0x3822d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x34(%rbp)
cmpl $0x8, -0x34(%rbp)
jae 0x101f4e
movl $0x8, -0x34(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
ja 0x101f5f
movl $0x0, -0x4(%rbp)
jmp 0x101f68
jmp 0x101f61
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)