// File: /workspace/github_cpp_makefile_star2_O3/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
leaq (%rdi,%rdi,4), %rdi
cmpl $0x0, (%rax,%rdi,8)
js 0x6f095
movl %ecx, %r10d
shrl %r10d
leaq (%r10,%r10,4), %rbx
cmpl $0x0, (%rax,%rbx,8)
js 0x6f095
leaq (%rax,%rdi,8), %rdi
movq 0x18(%rdi), %r10
testb $0x1, %dl
jne 0x6ee45
movl 0x10(%rdi), %r11d
decl %r11d
jmp 0x6ee48
xorl %r11d, %r11d
leaq (%rax,%rbx,8), %rdi
movq (%r10,%r11,8), %rax
andl $0x1, %ecx
jne 0x6ee5a
xorl %r11d, %r11d
jmp 0x6ee61
movl 0x10(%rdi), %r11d
decl %r11d
movq 0x8(%rsi), %rbx
movq %rax, %r10
shrq $0x21, %r10
leaq (%r10,%r10,2), %r10
movl 0xc(%rbx,%r10,8), %r14d
testq %r14, %r14
je 0x6f095
movq %r9, -0x28(%rsp)
movq %r8, -0x20(%rsp)
shrq $0x20, %rax
andl $0x1, %edx
movq 0x18(%rdi), %rdi
xorl %edx, %eax
movq (%rdi,%r11,8), %rdx
movq %rdx, %rdi
shrq $0x20, %rdi
xorl %edi, %ecx
movl %ecx, -0x34(%rsp)
movl 0x44(%rsi), %ecx
movl %ecx, -0x3c(%rsp)
movl 0x40(%rsi), %ecx
movl %ecx, -0x38(%rsp)
leaq (%rbx,%r10,8), %rsi
movq (%rsi), %r10
shrq $0x21, %rdx
leaq 0x22736a(%rip), %rsi    # 0x296230
movq 0x18(%rsi), %rcx
movq %rcx, -0x30(%rsp)
leaq 0x226882(%rip), %rsi    # 0x295758
movss 0x158(%rsi), %xmm1
movl %eax, %eax
movq %rax, -0x18(%rsp)
shlq $0x3, %r14
leaq (%r14,%r14,4), %rax
movq %rax, -0x8(%rsp)
xorl %r15d, %r15d
movl 0xc(%r10,%r15), %r12d
cmpl %r12d, %edx
jne 0x6efc0
movq 0x18(%r10,%r15), %rcx
movq -0x30(%rsp), %rax
movl (%rax,%rdx,8), %ebx
movq %rcx, -0x10(%rsp)
testl %ecx, %ecx
js 0x6ef2c
movl 0x10(%r10,%r15), %ecx
movl 0x14(%r10,%r15), %r9d
subl %r9d, %ebx
movl %ebx, %esi
movl %ecx, %ebx
jmp 0x6ef3b
movl 0x10(%r10,%r15), %ecx
movl 0x14(%r10,%r15), %r9d
subl %r9d, %ebx
movl %ecx, %esi
movq (%r10,%r15), %rdi
movq %rdi, %rax
shrq $0x20, %rax
movq -0x30(%rsp), %r8
movl (%r8,%rax,8), %ebp
cmpl %edi, %ebx
movl %edi, %r13d
cmovll %ebx, %r13d
movl 0x8(%r10,%r15), %r8d
movl %ebp, %r14d
subl %r8d, %r14d
cmpl %esi, %r14d
movl %esi, %eax
cmovll %r14d, %eax
cmpl -0x38(%rsp), %r13d
jg 0x6efc0
cmpl -0x38(%rsp), %eax
jg 0x6efc0
movl %r8d, %r11d
subl %edi, %r11d
xorps %xmm2, %xmm2
cvtsi2ss %r11, %xmm2
addl %r13d, %r11d
addl %eax, %r11d
xorps %xmm3, %xmm3
cvtsi2ss %r11, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
ja 0x6efc0
subl %ecx, %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9, %xmm2
addl %r13d, %eax
addl %r9d, %eax
xorps %xmm3, %xmm3
cvtsi2ss %rax, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jbe 0x6efd4
addq $0x28, %r15
cmpq %r15, -0x8(%rsp)
jne 0x6eef5
jmp 0x6f095
cmpl %esi, %r14d
setl %cl
setg %r14b
cmpl %ebx, %edi
setg %r13b
setl %r9b
orb %r14b, %r13b
cmpb $0x1, %r13b
jne 0x6efc0
orb %cl, %r9b
je 0x6efc0
cmpl -0x3c(%rsp), %r11d
jl 0x6efc0
cmpl -0x3c(%rsp), %eax
jl 0x6efc0
addl %r8d, %esi
movl %ebp, %ecx
subl %esi, %ecx
movl %edi, %eax
subl %ebx, %eax
cmovlel %ecx, %eax
testl %eax, %eax
js 0x6efc0
xorl %r8d, %r8d
cmpl %ebx, %edi
setle %r8b
setg %cl
cmpl $0x0, -0x10(%rsp)
setns %sil
shrq $0x1f, %rdi
andl $-0x2, %edi
orl %edi, %r8d
cmpl -0x18(%rsp), %r8d
jne 0x6efc0
xorb %cl, %sil
movzbl %sil, %ecx
leal (%rcx,%r12,2), %ecx
cmpl -0x34(%rsp), %ecx
jne 0x6efc0
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 0x6f097
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq