// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %r8, 0x38(%rsp)
movl %ecx, %ebp
movq %rdx, %r12
movq %rdi, %r15
movq %rsi, 0x20(%rsp)
callq 0x12584f
movsd %xmm0, 0x40(%rsp)
movl %ebp, %eax
movq %rax, 0x28(%rsp)
xorl %ebx, %ebx
cmpq %rbx, 0x28(%rsp)
je 0x1289a2
movl (%r12,%rbx,4), %edx
movq 0x20(%rsp), %rsi
movq 0x50(%rsi), %rax
movb (%rax,%rdx), %al
xorl %ecx, %ecx
subb %al, %cl
movsbl %cl, %ecx
movq %r15, %rdi
callq 0x125fc0
incq %rbx
jmp 0x128977
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r13d, %r13d
movsd %xmm0, 0x18(%rsp)
movq %r15, 0x48(%rsp)
cmpq 0x28(%rsp), %r13
je 0x128b17
movl (%r12,%r13,4), %ebp
movq 0x12a610(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movq 0x20(%rsp), %r14
movq 0x40(%r14), %rax
movq %rbp, %rbx
shlq $0x4, %rbx
movsd (%rax,%rbx), %xmm0
movsd 0x8(%rax,%rbx), %xmm1
leaq 0xc65fa(%rip), %rsi     # 0x1eefef
leaq 0xc661b(%rip), %rdx     # 0x1ef017
movl %ebp, %ecx
movb $0x2, %al
callq 0x22b0
movq %rbp, %rcx
movq 0x40(%r14), %rax
movq 0x50(%r14), %rdx
movsbl (%rdx,%rbp), %edx
cvtsi2sd %edx, %xmm0
movsd (%rax,%rbx), %xmm1
subsd 0x8(%rax,%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
movq 0x10(%r15), %rax
movq (%rax,%rbp,8), %rbx
movl %ebx, %esi
shrq $0x1c, %rbx
andq $-0x10, %rbx
addq 0x28(%r15), %rbx
xorl %r15d, %r15d
movq %rbp, 0x10(%rsp)
movq %rsi, 0x30(%rsp)
cmpq %rsi, %r15
je 0x128af0
movq %r15, %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %r14
movq (%rbx,%rax), %r8
movl %r8d, %ebp
xorl %edx, %edx
movl %edx, %eax
cmpq %rax, %r13
je 0x128a7f
leal 0x1(%rax), %edx
cmpl %r8d, (%r12,%rax,4)
jne 0x128a6d
jmp 0x128a82
movq %r13, %rax
cmpq %r13, %rax
jae 0x128a8c
cmpl %r8d, %ecx
jne 0x128a91
incq %r15
jmp 0x128a50
movq 0x12a548(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movsd 0x8(%r14), %xmm0
leaq 0xc657c(%rip), %rsi     # 0x1ef024
leaq 0xc6568(%rip), %rdx     # 0x1ef017
movb $0x1, %al
callq 0x22b0
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
movsbl (%rax,%rcx), %edx
movsbl (%rax,%rbp), %eax
imull %edx, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x8(%r14), %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
jmp 0x128a8c
movsd 0x50(%rsp), %xmm1
addsd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
incq %r13
movq 0x48(%rsp), %r15
jmp 0x1289ba
movsd 0x18(%rsp), %xmm0
mulsd 0xc6023(%rip), %xmm0    # 0x1eeb48
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x12584f
movq 0x12a497(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0xc64f3(%rip), %rsi     # 0x1ef046
leaq 0xc64bd(%rip), %rdx     # 0x1ef017
movsd 0x40(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movb $0x3, %al
callq 0x22b0
movq 0x38(%rsp), %rax
movq (%rax), %rdx
movq 0x10(%rax), %rdi
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x20e0
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
cmpq 0x28(%rsp), %rbx
je 0x128d12
movq %rbx, 0x30(%rsp)
movl (%r12,%rbx,4), %r14d
movq 0x12a433(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movq %r15, %r13
movq 0x20(%rsp), %r15
movq 0x40(%r15), %rax
movq %r14, %rbx
shlq $0x4, %rbx
movsd (%rax,%rbx), %xmm0
movsd 0x8(%rax,%rbx), %xmm1
leaq 0xc6497(%rip), %rsi     # 0x1ef06c
leaq 0xc643b(%rip), %rdx     # 0x1ef017
movl %r14d, %ecx
movb $0x2, %al
callq 0x22b0
pushq $0x1
popq %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%r15), %rax
movq 0x50(%r15), %rcx
movsbl (%rcx,%r14), %ecx
cvtsi2sd %ecx, %xmm0
movsd (%rax,%rbx), %xmm1
subsd 0x8(%rax,%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq 0x10(%r13), %rax
movq 0x28(%r13), %rcx
movq (%rax,%r14,8), %rax
movl %eax, %ebx
shlq $0x4, %rbx
shrq $0x1c, %rax
andq $-0x10, %rax
leaq (%rcx,%rax), %r15
addq $0x8, %r15
xorl %ebp, %ebp
movq 0x10(%rsi), %rax
cmpq %rbp, %rbx
je 0x128cd4
movq -0x8(%r15,%rbp), %r13
movl %r13d, %ecx
andb $0x7, %cl
movl %edi, %edx
shll %cl, %edx
cmpl %r13d, %r14d
je 0x128c67
movl %r13d, %ecx
shrl $0x3, %ecx
movzbl (%rax,%rcx), %eax
andl %eax, %edx
jne 0x128c6d
addq $0x10, %rbp
jmp 0x128c38
movq 0x12a36c(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movsd (%r15,%rbp), %xmm0
leaq 0xc6410(%rip), %rsi     # 0x1ef094
leaq 0xc638c(%rip), %rdx     # 0x1ef017
movl %r14d, %ecx
movl %r13d, %r8d
movb $0x1, %al
callq 0x22b0
pushq $0x1
popq %rdi
movq 0x38(%rsp), %rsi
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
movsbl (%rax,%r14), %ecx
movl %r13d, %edx
movsbl (%rax,%rdx), %eax
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
mulsd (%r15,%rbp), %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
jmp 0x128c67
movsd 0x8(%rsp), %xmm1
addsd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movl %r14d, %ecx
andb $0x7, %cl
movl %edi, %edx
shll %cl, %edx
shrl $0x3, %r14d
orb %dl, (%rax,%r14)
movq 0x30(%rsp), %rbx
incq %rbx
movq 0x48(%rsp), %r15
jmp 0x128b92
movsd 0x18(%rsp), %xmm0
mulsd 0xc5e28(%rip), %xmm0    # 0x1eeb48
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x12584f
movq 0x12a29c(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0xc6368(%rip), %rsi     # 0x1ef0b6
leaq 0xc62c2(%rip), %rdx     # 0x1ef017
movsd 0x40(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movb $0x3, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0