// File: /workspace/github_cpp_makefile_star2_O1/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 0x6f74a
movl %ecx, %r10d
shrl %r10d
leaq (%r10,%r10,4), %rbx
cmpl $0x0, (%rax,%rbx,8)
js 0x6f74a
leaq (%rax,%rdi,8), %rdi
movq 0x18(%rdi), %r10
testb $0x1, %dl
jne 0x6f47b
movl 0x10(%rdi), %r11d
decl %r11d
jmp 0x6f47e
xorl %r11d, %r11d
leaq (%rax,%rbx,8), %rdi
movq (%r10,%r11,8), %rax
andl $0x1, %ecx
jne 0x6f490
xorl %r11d, %r11d
jmp 0x6f497
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
movq $-0x1, %r15
testq %r14, %r14
je 0x6f70f
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
leaq (%rbx,%r10,8), %rsi
movq (%rsi), %r10
shrq $0x21, %rdx
leaq 0x21bd31(%rip), %rsi    # 0x28b230
movq 0x18(%rsi), %r11
leaq 0x21b24e(%rip), %rsi    # 0x28a758
movss 0x158(%rsi), %xmm1
movl %eax, %eax
movq %rax, -0x8(%rsp)
shlq $0x3, %r14
leaq (%r14,%r14,4), %rax
xorl %r15d, %r15d
movq %rsi, -0x30(%rsp)
movq %rdx, -0x50(%rsp)
movq %r11, -0x18(%rsp)
movq %rax, -0x48(%rsp)
movl 0xc(%r10,%r15), %edi
cmpl %edi, %edx
jne 0x6f638
movl %ecx, %r13d
movq 0x18(%r10,%r15), %r8
movl (%r11,%rdi,8), %eax
testl %r8d, %r8d
js 0x6f567
movl 0x10(%r10,%r15), %ecx
subl 0x14(%r10,%r15), %eax
movl %eax, %r9d
movl %ecx, %eax
jmp 0x6f571
subl 0x14(%r10,%r15), %eax
movl 0x10(%r10,%r15), %r9d
movq (%r10,%r15), %rbx
movq %rbx, %rcx
shrq $0x20, %rcx
movl (%r11,%rcx,8), %r11d
cmpl %ebx, %eax
movl %ebx, %r14d
cmovll %eax, %r14d
movl 0x8(%r10,%r15), %r12d
movl %r11d, %ebp
subl %r12d, %ebp
cmpl %r9d, %ebp
movl %r9d, %esi
cmovll %ebp, %esi
movl %r13d, %ecx
cmpl %r13d, %r14d
jg 0x6f5fc
cmpl %ecx, %esi
jg 0x6f5fc
movl %r12d, %ecx
subl %ebx, %ecx
xorps %xmm2, %xmm2
cvtsi2ss %rcx, %xmm2
addl %r14d, %ecx
addl %esi, %ecx
xorps %xmm3, %xmm3
cvtsi2ss %rcx, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
ja 0x6f5f9
movl 0x14(%r10,%r15), %edx
subl 0x10(%r10,%r15), %edx
xorps %xmm2, %xmm2
cvtsi2ss %rdx, %xmm2
addl %r14d, %esi
addl %edx, %esi
xorps %xmm3, %xmm3
cvtsi2ss %rsi, %xmm3
mulss %xmm1, %xmm3
ucomiss %xmm2, %xmm3
jbe 0x6f64a
movq -0x50(%rsp), %rdx
movl %r13d, %ecx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x6f60b
movq -0x18(%rsp), %r11
jmp 0x6f633
movq -0x10(%rsp), %rax
shrq $0x20, %rax
cmpl -0x8(%rsp), %eax
movq -0x18(%rsp), %r11
jne 0x6f633
movl -0x38(%rsp), %eax
cmpl -0x34(%rsp), %eax
movq -0x48(%rsp), %rax
jne 0x6f638
jmp 0x6f6f9
movq -0x48(%rsp), %rax
addq $0x28, %r15
cmpq %r15, %rax
jne 0x6f538
jmp 0x6f6e6
cmpl %r9d, %ebp
setl -0x51(%rsp)
setg %dl
cmpl %eax, %ebx
setg %bpl
setl %r14b
orb %dl, %bpl
cmpb $0x1, %bpl
jne 0x6f5f4
orb -0x51(%rsp), %r14b
movq -0x50(%rsp), %rdx
movl -0x3c(%rsp), %ebp
je 0x6f5f9
cmpl %ebp, %ecx
jl 0x6f5f9
cmpl %ebp, %esi
movl %r13d, %ecx
movb $0x1, %bpl
jl 0x6f5ff
testl %r8d, %r8d
setns %cl
addl %r12d, %r9d
movl %r11d, %edx
subl %r9d, %edx
xorl %esi, %esi
movl %ebx, %ebp
subl %eax, %ebp
setle %sil
setg %al
cmovlel %edx, %ebp
movq -0x50(%rsp), %rdx
xorb %cl, %al
movl %r13d, %ecx
movzbl %al, %eax
shrq $0x1f, %rbx
andl $-0x2, %ebx
orl %ebx, %esi
leal (%rax,%rdi,2), %eax
movl %eax, -0x38(%rsp)
shlq $0x20, %rsi
movq %rsi, -0x10(%rsp)
subl %ebp, %r11d
shrl $0x1f, %ebp
movl %r11d, %eax
movq %rax, -0x30(%rsp)
jmp 0x6f5ff
movq -0x20(%rsp), %r8
movq -0x28(%rsp), %r9
movq $-0x1, %r15
jmp 0x6f70f
movq -0x30(%rsp), %r15
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq -0x20(%rsp), %r8
movq -0x28(%rsp), %r9
testq %r15, %r15
js 0x6f74a
movq %r15, %rax
subq %r9, %rax
cmovgq %r15, %r9
movq %rax, %rcx
negq %rcx
cmovsq %rax, %rcx
xorps %xmm1, %xmm1
cvtsi2sd %r9, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
cmpq %r8, %rax
cmovgq %rax, %r8
xorl %eax, %eax
cmpq %r8, %rcx
setle %al
jmp 0x6f74c
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq