// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/rcut.cpp
// Function: test_flip_sc(mc_match_t const*, mc_svaux_t*, unsigned int*, unsigned int, bits_p*)
void test_flip_sc(const mc_match_t *ma, mc_svaux_t *b, uint32_t *a, uint32_t a_n, bits_p *vis)
{
	mc_edge_t *o = NULL; t_w_t w = 0, w_off = 0; 
	t_w_t sc_new = mc_score(ma, b), sc;
    uint32_t n, i, t, k, uid, z;
	for (k = 0; k < a_n; k++) mc_set_spin(ma, b, a[k], -b->s[a[k]]);
	for (k = 0; k < a_n; k++) {
		uid = a[k];
		fprintf(stderr, "+[M::%s::] uid::%u, z[0]::%f, z[1]::%f\n", __func__, uid, b->z[uid].z[0], b->z[uid].z[1]);
		w += ((t_w_t)(b->s[uid])) * (b->z[uid].z[0] - b->z[uid].z[1]) * 2;
		o = pt_a(*ma, uid);
		n = pt_n(*ma, uid);
		for (i = 0; i < n; ++i) {
			t = ma_y(o[i]);
			for (z = 0; z < k; z++) {
				if(a[z] == t) break;
			}
			if(z >= k) continue;
			// if(!(is_set_bits_p((*vis), t))) continue;
			// if(vis[t] == 0) continue;
			if(t == uid) continue;
			fprintf(stderr, "+[M::%s::] uid::%u, t::%u, w::%f\n", __func__, uid, t, o[i].w);
			w_off += (b->s[uid]*b->s[t]*o[i].w);
		}
	}
	w -= (w_off*4);
	sc = mc_score(ma, b);
	fprintf(stderr, "+[M::%s::] sc::%f, sc_new::%f, w::%f\n", __func__, sc, sc_new, w);

	w = w_off = 0; memset(vis->a, 0, sizeof(*(vis->a))*vis->n);
	for (k = 0; k < a_n; k++) {
		uid = a[k];
		fprintf(stderr, "-[M::%s::] uid::%u, z[0]::%f, z[1]::%f\n", __func__, uid, b->z[uid].z[0], b->z[uid].z[1]);
		w += ((t_w_t)(b->s[uid])) * (b->z[uid].z[0] - b->z[uid].z[1]) * 2;
		o = pt_a(*ma, uid);
		n = pt_n(*ma, uid);
		for (i = 0; i < n; ++i) {
			t = ma_y(o[i]);
			// for (z = 0; z < k; z++) {
			// 	if(a[z] == t) break;
			// }
			// if(z >= k) continue;
			if(!(is_set_bits_p((*vis), t))) continue;
			// if(vis[t] == 0) continue;
			if(t == uid) continue;
			fprintf(stderr, "-[M::%s::] uid::%u, t::%u, w::%f\n", __func__, uid, t, o[i].w);
			w_off += (b->s[uid]*b->s[t]*o[i].w);
		}
		set_bits_p((*vis), uid);
	}
	w -= (w_off*4);
	sc = mc_score(ma, b);
	fprintf(stderr, "-[M::%s::] sc::%f, sc_new::%f, w::%f\n", __func__, sc, sc_new, w);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, 0x20(%rsp)
movl %ecx, %ebx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbp
callq 0x169ee2
movsd %xmm0, 0x50(%rsp)
movl %ebx, %r14d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movl %ebx, 0x1c(%rsp)
testl %ebx, %ebx
movq %r15, 0x28(%rsp)
movq %rbp, 0x60(%rsp)
movq %r14, 0x58(%rsp)
je 0x1d986
xorl %ebx, %ebx
movl (%r12,%rbx,4), %edx
movq 0x50(%r15), %rax
xorl %ecx, %ecx
subb (%rax,%rdx), %cl
movsbl %cl, %ecx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x16a6bf
incq %rbx
cmpq %rbx, %r14
jne 0x1d948
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, 0x1c(%rsp)
jne 0x1dbf2
movsd 0x8(%rsp), %xmm0
mulsd 0x21f2c4(%rip), %xmm0   # 0x23cc58
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x169ee2
movq 0x27762e(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x21f7ca(%rip), %rsi    # 0x23d186
leaq 0x21f794(%rip), %rdx    # 0x23d157
movsd 0x50(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movb $0x3, %al
callq 0x22b0
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movq 0x10(%rax), %rdi
xorl %esi, %esi
callq 0x20e0
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, 0x1c(%rsp)
jne 0x1da56
movsd 0x8(%rsp), %xmm1
mulsd 0x21f250(%rip), %xmm1   # 0x23cc58
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x169ee2
movq 0x2775bc(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x21f7c8(%rip), %rsi    # 0x23d1f6
leaq 0x21f722(%rip), %rdx    # 0x23d157
movsd 0x50(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movb $0x3, %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
movsd %xmm0, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movl (%r12,%rax,4), %r14d
movq 0x27756c(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq 0x40(%r15), %rax
movq %r14, %rbx
shlq $0x4, %rbx
movsd (%rax,%rbx), %xmm0
movsd 0x8(%rax,%rbx), %xmm1
leaq 0x21f718(%rip), %rsi    # 0x23d1ac
leaq 0x21f6bc(%rip), %rdx    # 0x23d157
movl %r14d, %ecx
movb $0x2, %al
callq 0x22b0
movq 0x40(%r15), %rax
movq 0x50(%r15), %rcx
movsd (%rax,%rbx), %xmm0
subsd 0x8(%rax,%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
movsbl (%rcx,%r14), %eax
movl %eax, 0x30(%rsp)
movq 0x10(%rbp), %rax
movq (%rax,%r14,8), %rax
testl %eax, %eax
jne 0x1db31
movq 0x20(%rsp), %rsi
pushq $0x1
popq %rdi
cvtsi2sdl 0x30(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
movl %r14d, %ecx
andb $0x7, %cl
movl %edi, %eax
shll %cl, %eax
movq 0x10(%rsi), %rcx
shrl $0x3, %r14d
orb %al, (%rcx,%r14)
addsd %xmm1, %xmm1
movsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
movq 0x38(%rsp), %rax
incq %rax
cmpq 0x58(%rsp), %rax
movq 0x28(%rsp), %r15
movq 0x60(%rsp), %rbp
jne 0x1da5e
jmp 0x1d9fa
movq 0x28(%rbp), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %r15d
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rbx
addq $0x8, %rbx
shlq $0x4, %r15
xorl %ebp, %ebp
movq 0x20(%rsp), %rsi
pushq $0x1
popq %rdi
movq -0x8(%rbx,%rbp), %r13
movl %r13d, %ecx
andb $0x7, %cl
movl %edi, %eax
shll %cl, %eax
cmpl %r13d, %r14d
je 0x1db7f
movq 0x10(%rsi), %rcx
movl %r13d, %edx
shrl $0x3, %edx
movzbl (%rcx,%rdx), %ecx
andl %ecx, %eax
jne 0x1db8d
addq $0x10, %rbp
cmpq %rbp, %r15
jne 0x1db59
jmp 0x1dadb
movq 0x27744c(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movsd (%rbx,%rbp), %xmm0
leaq 0x21f631(%rip), %rsi    # 0x23d1d4
leaq 0x21f5ad(%rip), %rdx    # 0x23d157
movl %r14d, %ecx
movl %r13d, %r8d
movb $0x1, %al
callq 0x22b0
pushq $0x1
popq %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movsbl (%rax,%r14), %ecx
movl %r13d, %edx
movsbl (%rax,%rdx), %eax
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
mulsd (%rbx,%rbp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x1db7f
movsd %xmm0, 0x8(%rsp)
xorl %r13d, %r13d
movsd %xmm0, 0x10(%rsp)
movl (%r12,%r13,4), %r14d
movq 0x2773d4(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq 0x40(%r15), %rax
movq %r14, %rbx
shlq $0x4, %rbx
movsd (%rax,%rbx), %xmm0
movsd 0x8(%rax,%rbx), %xmm1
leaq 0x21f503(%rip), %rsi    # 0x23d12f
leaq 0x21f524(%rip), %rdx    # 0x23d157
movl %r14d, %ecx
movb $0x2, %al
callq 0x22b0
movq 0x40(%r15), %rax
movq 0x50(%r15), %rdx
movsd (%rax,%rbx), %xmm0
subsd 0x8(%rax,%rbx), %xmm0
movsd %xmm0, 0x30(%rsp)
movsbl (%rdx,%r14), %eax
movl %eax, 0x4c(%rsp)
movq 0x10(%rbp), %rax
movq (%rax,%r14,8), %rax
testl %eax, %eax
jne 0x1dcac
cvtsi2sdl 0x4c(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
incq %r13
cmpq 0x58(%rsp), %r13
movq 0x28(%rsp), %r15
movq 0x60(%rsp), %rbp
jne 0x1dc01
jmp 0x1d986
movq %r14, %rcx
movq %rbp, %rdx
movq %rax, %rbp
shrq $0x1c, %rbp
andq $-0x10, %rbp
addq 0x28(%rdx), %rbp
movl %eax, %ebx
xorl %r15d, %r15d
movq %r14, 0x38(%rsp)
movq %r15, %r14
shlq $0x4, %r14
movq (%rbp,%r14), %r8
xorl %eax, %eax
testq %r13, %r13
je 0x1dcf3
cmpl %r8d, (%r12,%rax,4)
je 0x1dcf1
incq %rax
movl %eax, %edx
cmpq %rdx, %r13
jne 0x1dcde
movl %r13d, %eax
movl %eax, %eax
cmpq %r13, %rax
jae 0x1dcfd
cmpl %r8d, %ecx
jne 0x1dd0a
incq %r15
cmpq %rbx, %r15
jne 0x1dccb
jmp 0x1dc6b
addq %rbp, %r14
movl %r8d, %eax
movq %rax, 0x40(%rsp)
movq 0x2772c4(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movsd 0x8(%r14), %xmm0
leaq 0x21f438(%rip), %rsi    # 0x23d164
leaq 0x21f424(%rip), %rdx    # 0x23d157
movb $0x1, %al
callq 0x22b0
movq 0x38(%rsp), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movsbl (%rax,%rcx), %edx
movq 0x40(%rsp), %rsi
movsbl (%rax,%rsi), %eax
imull %edx, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x8(%r14), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x1dcfd