// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movl %ecx, %ebx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbp
callq 0x163573
movsd %xmm0, 0x40(%rsp)
movl %ebx, %r14d
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movl %ebx, 0x38(%rsp)
testl %ebx, %ebx
movq %r15, 0x10(%rsp)
movq %rbp, 0x50(%rsp)
movq %r14, 0x48(%rsp)
jne 0x1e7ba
movsd (%rsp), %xmm1
mulsd 0x212354(%rip), %xmm1   # 0x230a50
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x163573
movq 0x26b8c9(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x212815(%rip), %rsi    # 0x230f36
leaq 0x2127df(%rip), %rdx    # 0x230f07
movsd 0x40(%rsp), %xmm1
movsd (%rsp), %xmm2
movb $0x3, %al
callq 0x22b0
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x10(%rax), %rdi
xorl %esi, %esi
callq 0x20e0
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
cmpl $0x0, 0x38(%rsp)
jne 0x1e95c
movsd (%rsp), %xmm1
mulsd 0x2122e2(%rip), %xmm1   # 0x230a50
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x163573
movq 0x26b857(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x212813(%rip), %rsi    # 0x230fa6
leaq 0x21276d(%rip), %rdx    # 0x230f07
movsd 0x40(%rsp), %xmm1
movsd (%rsp), %xmm2
movb $0x3, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0
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 0x163d25
incq %rbx
cmpq %rbx, %r14
jne 0x1e7bc
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %r14d, %r14d
movsd %xmm0, 0x20(%rsp)
movl (%r12,%r14,4), %r13d
movq 0x26b7e4(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movq 0x40(%r15), %rax
movq %r13, %rbx
shlq $0x4, %rbx
movsd (%rax,%rbx), %xmm0
movsd 0x8(%rax,%rbx), %xmm1
leaq 0x2126c3(%rip), %rsi    # 0x230edf
leaq 0x2126e4(%rip), %rdx    # 0x230f07
movl %r13d, %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, 0x18(%rsp)
movsbl (%rdx,%r13), %eax
movl %eax, 0x3c(%rsp)
movq 0x10(%rbp), %rax
movq (%rax,%r13,8), %rax
testl %eax, %eax
jne 0x1e896
cvtsi2sdl 0x3c(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm1, %xmm1
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
incq %r14
cmpq 0x48(%rsp), %r14
movq 0x10(%rsp), %r15
movq 0x50(%rsp), %rbp
jne 0x1e7eb
jmp 0x1e6ef
movq %r13, %rcx
movq %rbp, %rdx
movq %rax, %rbp
shrq $0x1c, %rbp
andq $-0x10, %rbp
addq 0x28(%rdx), %rbp
movl %eax, %ebx
xorl %r15d, %r15d
movq %r13, 0x28(%rsp)
movq %r15, %r13
shlq $0x4, %r13
movq (%rbp,%r13), %r8
xorl %eax, %eax
testq %r14, %r14
je 0x1e8dd
cmpl %r8d, (%r12,%rax,4)
je 0x1e8db
incq %rax
movl %eax, %edx
cmpq %rdx, %r14
jne 0x1e8c8
movl %r14d, %eax
movl %eax, %eax
cmpq %r14, %rax
jae 0x1e8e7
cmpl %r8d, %ecx
jne 0x1e8f4
incq %r15
cmpq %rbx, %r15
jne 0x1e8b5
jmp 0x1e85b
addq %rbp, %r13
movl %r8d, %eax
movq %rax, 0x30(%rsp)
movq 0x26b6da(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movsd 0x8(%r13), %xmm0
leaq 0x2125fe(%rip), %rsi    # 0x230f14
leaq 0x2125ea(%rip), %rdx    # 0x230f07
movb $0x1, %al
callq 0x22b0
movq 0x28(%rsp), %rcx
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rax
movsbl (%rax,%rcx), %edx
movq 0x30(%rsp), %rsi
movsbl (%rax,%rsi), %eax
imull %edx, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x8(%r13), %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
jmp 0x1e8e7
movsd %xmm0, (%rsp)
xorl %eax, %eax
movsd %xmm0, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movl (%r12,%rax,4), %r13d
movq 0x26b667(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movq 0x40(%r15), %rax
movq %r13, %rbx
shlq $0x4, %rbx
movsd (%rax,%rbx), %xmm0
movsd 0x8(%rax,%rbx), %xmm1
leaq 0x2125c3(%rip), %rsi    # 0x230f5c
leaq 0x212567(%rip), %rdx    # 0x230f07
movl %r13d, %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, 0x20(%rsp)
movsbl (%rcx,%r13), %eax
movl %eax, 0x18(%rsp)
movq 0x10(%rbp), %rax
movq (%rax,%r13,8), %rax
testl %eax, %eax
jne 0x1ea36
movq 0x8(%rsp), %rsi
pushq $0x1
popq %rdi
cvtsi2sdl 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
movl %r13d, %ecx
andb $0x7, %cl
movl %edi, %eax
shll %cl, %eax
movq 0x10(%rsi), %rcx
shrl $0x3, %r13d
orb %al, (%rcx,%r13)
addsd %xmm1, %xmm1
movsd 0x30(%rsp), %xmm0
addsd %xmm1, %xmm0
movq 0x28(%rsp), %rax
incq %rax
cmpq 0x48(%rsp), %rax
movq 0x10(%rsp), %r15
movq 0x50(%rsp), %rbp
jne 0x1e963
jmp 0x1e761
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 0x8(%rsp), %rsi
pushq $0x1
popq %rdi
movq -0x8(%rbx,%rbp), %r14
movl %r14d, %ecx
andb $0x7, %cl
movl %edi, %eax
shll %cl, %eax
cmpl %r14d, %r13d
je 0x1ea84
movq 0x10(%rsi), %rcx
movl %r14d, %edx
shrl $0x3, %edx
movzbl (%rcx,%rdx), %ecx
andl %ecx, %eax
jne 0x1ea92
addq $0x10, %rbp
cmpq %rbp, %r15
jne 0x1ea5e
jmp 0x1e9e0
movq 0x26b547(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movsd (%rbx,%rbp), %xmm0
leaq 0x2124dc(%rip), %rsi    # 0x230f84
leaq 0x212458(%rip), %rdx    # 0x230f07
movl %r13d, %ecx
movl %r14d, %r8d
movb $0x1, %al
callq 0x22b0
pushq $0x1
popq %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rax
movsbl (%rax,%r13), %ecx
movl %r14d, %edx
movsbl (%rax,%rdx), %eax
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
mulsd (%rbx,%rbp), %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
jmp 0x1ea84