// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: check_connect_rg(ul_idx_t const*, ug_opt_t const*, unsigned int, unsigned int, long, double, long)
uint64_t check_connect_rg(const ul_idx_t *uref, const ug_opt_t *uopt, uint32_t uv, uint32_t uw, int64_t bw, double diff_ec_ul, int64_t dq)
{
	int64_t dt = -1;
	if(uref->ug->u.a[uv>>1].circ || uref->ug->u.a[uw>>1].circ) return 0;
	uint32_t rv = (uref->ug->u.a[uv>>1].a[(uv&1)?(0):(uref->ug->u.a[uv>>1].n-1)]>>32)^(uv&1);
	uint32_t rw = (uref->ug->u.a[uw>>1].a[(uw&1)?(uref->ug->u.a[uw>>1].n-1):(0)]>>32)^(uw&1);
	ma_hit_t_alloc* src = uopt->sources;
	int64_t min_ovlp = uopt->min_ovlp;
	int64_t max_hang = uopt->max_hang;
	uint64_t z, qn, tn, x = rv>>1; int32_t r = 1; asg_arc_t e;
	for (z = 0; z < src[x].length; z++) {
		qn = Get_qn(src[x].buffer[z]); tn = Get_tn(src[x].buffer[z]);
		if(tn != (rw>>1)) continue;
		r = ma_hit2arc(&(src[x].buffer[z]), Get_READ_LENGTH(R_INF, qn), Get_READ_LENGTH(R_INF, tn), max_hang, asm_opt.max_hang_rate, min_ovlp, &e);
		if(r < 0) continue;
		if((e.ul>>32) != rv || e.v != rw) continue;
		dt = e.ol; 
		break;
	}
	if(dt < 0) return 0;
	int64_t diff = (dq>dt? dq-dt:dt-dq), mm = MAX(dq, dt);
	mm *= diff_ec_ul; if(mm < bw) mm = bw;
	if(diff <= mm) return 1;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdi), %rax
movq 0x10(%rax), %rax
movl %edx, %edi
shrl %edi
imulq $0x28, %rdi, %rdi
cmpl $0x0, (%rax,%rdi)
js 0x3d89b
movl %ecx, %r10d
shrl %r10d
imulq $0x28, %r10, %r10
cmpl $0x0, (%rax,%r10)
js 0x3d89b
movq %r8, -0x20(%rsp)
addq %rax, %rdi
addq %rax, %r10
movq 0x18(%rdi), %r8
movl %edx, %eax
andl $0x1, %eax
testb $0x1, %dl
jne 0x3d66f
movl 0x10(%rdi), %edx
decl %edx
jmp 0x3d671
xorl %edx, %edx
movq (%r8,%rdx,8), %rdi
movq %rdi, %rdx
shrq $0x20, %rdx
xorl %edx, %eax
movq 0x18(%r10), %rdx
andl $0x1, %ecx
movq %r9, -0x28(%rsp)
jne 0x3d691
xorl %r8d, %r8d
jmp 0x3d698
movl 0x10(%r10), %r8d
decl %r8d
movq (%rdx,%r8,8), %rdx
movq %rdx, %r8
shrq $0x20, %r8
xorl %r8d, %ecx
movl %ecx, -0x34(%rsp)
movq 0x8(%rsi), %rcx
movl 0x44(%rsi), %r8d
movl %r8d, -0x3c(%rsp)
movl 0x40(%rsi), %esi
movl %esi, -0x38(%rsp)
shrq $0x21, %rdi
imulq $0x18, %rdi, %rsi
leaq (%rcx,%rsi), %rdi
movq %rdi, -0x10(%rsp)
movl 0xc(%rcx,%rsi), %ecx
shrq $0x21, %rdx
leaq 0x216b52(%rip), %rsi    # 0x254230
movq 0x18(%rsi), %rsi
movq %rsi, -0x30(%rsp)
leaq 0x21606a(%rip), %rsi    # 0x253758
movss 0x158(%rsi), %xmm1
movl %eax, %eax
movq %rax, -0x18(%rsp)
imulq $0x28, %rcx, %rax
movq %rax, -0x8(%rsp)
xorl %r15d, %r15d
cmpq %r15, -0x8(%rsp)
je 0x3d89b
movq -0x10(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rax,%r15), %r12d
cmpl %r12d, %edx
jne 0x3d7d6
movq 0x18(%rax,%r15), %r13
movq -0x30(%rsp), %rcx
movl (%rcx,%rdx,8), %ebx
testl %r13d, %r13d
js 0x3d74f
movl 0x10(%rax,%r15), %ecx
movl 0x14(%rax,%r15), %esi
subl %esi, %ebx
movl %ebx, %r8d
movl %ecx, %ebx
jmp 0x3d75e
movl 0x10(%rax,%r15), %ecx
movl 0x14(%rax,%r15), %esi
subl %esi, %ebx
movl %ecx, %r8d
movq (%rax,%r15), %rdi
movq %rdi, %r9
shrq $0x20, %r9
movq -0x30(%rsp), %r10
movl (%r10,%r9,8), %ebp
cmpl %edi, %ebx
movl %edi, %r14d
cmovll %ebx, %r14d
movl 0x8(%rax,%r15), %r9d
movl %ebp, %r11d
subl %r9d, %r11d
cmpl %r8d, %r11d
movl %r8d, %eax
cmovll %r11d, %eax
cmpl -0x38(%rsp), %r14d
jg 0x3d7d6
cmpl -0x38(%rsp), %eax
jg 0x3d7d6
movl %r9d, %r10d
subl %edi, %r10d
cvtsi2ss %r10, %xmm2
addl %r14d, %r10d
addl %eax, %r10d
cvtsi2ss %r10, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
ja 0x3d7d6
subl %ecx, %esi
cvtsi2ss %rsi, %xmm2
addl %r14d, %eax
addl %esi, %eax
cvtsi2ss %rax, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jbe 0x3d7df
addq $0x28, %r15
jmp 0x3d709
cmpl %r8d, %r11d
setl %cl
setg %r11b
cmpl %ebx, %edi
setg %r14b
setl %sil
orb %r11b, %r14b
cmpb $0x1, %r14b
jne 0x3d7d6
orb %cl, %sil
je 0x3d7d6
cmpl -0x3c(%rsp), %r10d
jl 0x3d7d6
cmpl -0x3c(%rsp), %eax
jl 0x3d7d6
addl %r9d, %r8d
movl %ebp, %ecx
subl %r8d, %ecx
movl %edi, %eax
subl %ebx, %eax
cmovlel %ecx, %eax
testl %eax, %eax
js 0x3d7d6
xorl %r8d, %r8d
cmpl %ebx, %edi
setle %r8b
setg %cl
testl %r13d, %r13d
setns %sil
shrq $0x1f, %rdi
andl $-0x2, %edi
orl %edi, %r8d
cmpl -0x18(%rsp), %r8d
jne 0x3d7d6
xorb %cl, %sil
movzbl %sil, %ecx
leal (%rcx,%r12,2), %ecx
cmpl -0x34(%rsp), %ecx
jne 0x3d7d6
subl %eax, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq %rbp, %rax
movq -0x28(%rsp), %rdx
subq %rdx, %rax
cmovgq %rbp, %rdx
movq %rax, %rcx
negq %rcx
cmovsq %rax, %rcx
cvtsi2sd %rdx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq -0x20(%rsp), %rdx
cmpq %rdx, %rax
cmovgq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
setle %al
jmp 0x3d89d
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq