// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21c580
movsd %xmm0, -0x48(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x2224d5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movl -0x60(%rbp), %ecx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x18(%rbp), %rcx
movl -0x60(%rbp), %r8d
movl (%rcx,%r8,4), %ecx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
subl %ecx, %eax
movsbl %al, %ecx
callq 0x21d470
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x22248c
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x2226cf
movq -0x18(%rbp), %rax
movl -0x60(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movq 0x1a1ae4(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x64(%rbp), %eax
movl %eax, %edx
movl %edx, %ecx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
shlq $0x4, %rdx
movsd (%rax,%rdx), %xmm0
movsd 0x8(%rax,%rdx), %xmm1
leaq 0x16b82b(%rip), %rsi    # 0x38dd4f
leaq 0x16b84c(%rip), %rdx    # 0x38dd77
movb $0x2, %al
callq 0x22a0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x64(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cvtsi2sd %eax, %xmm0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x64(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm1
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x64(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x64(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x2226bf
movq -0x30(%rbp), %rax
movl -0x58(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x60(%rbp), %eax
jae 0x222614
movq -0x18(%rbp), %rax
movl -0x68(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x5c(%rbp), %eax
jne 0x222607
jmp 0x222614
jmp 0x222609
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x2225ee
movl -0x68(%rbp), %eax
cmpl -0x60(%rbp), %eax
jb 0x222621
jmp 0x2226b1
movl -0x5c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jne 0x22262e
jmp 0x2226b1
movq 0x1a19ab(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x64(%rbp), %ecx
movl -0x5c(%rbp), %r8d
movq -0x30(%rbp), %rax
movl -0x58(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movsd 0x8(%rax), %xmm0
leaq 0x16b72b(%rip), %rsi    # 0x38dd84
leaq 0x16b717(%rip), %rdx    # 0x38dd77
movb $0x1, %al
callq 0x22a0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x64(%rbp), %ecx
movsbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rcx
movl -0x5c(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x30(%rbp), %rax
movl -0x58(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm2
movsd -0x40(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x2225c7
jmp 0x2226c1
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x2224dc
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x16b1c8(%rip), %xmm2   # 0x38d8c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21c580
movsd %xmm0, -0x50(%rbp)
movq 0x1a18c2(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
leaq 0x16b66f(%rip), %rsi    # 0x38dda6
leaq 0x16b639(%rip), %rdx    # 0x38dd77
movb $0x3, %al
callq 0x22a0
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2100
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x22297c
movq -0x18(%rbp), %rax
movl -0x60(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movq 0x1a184a(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x64(%rbp), %eax
movl %eax, %edx
movl %edx, %ecx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
shlq $0x4, %rdx
movsd (%rax,%rdx), %xmm0
movsd 0x8(%rax,%rdx), %xmm1
leaq 0x16b60e(%rip), %rsi    # 0x38ddcc
leaq 0x16b5b2(%rip), %rdx    # 0x38dd77
movb $0x2, %al
callq 0x22a0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x64(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cvtsi2sd %eax, %xmm0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x64(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm1
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x64(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x64(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x222948
movq -0x30(%rbp), %rax
movl -0x58(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x5c(%rbp), %ecx
shrl $0x3, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movl -0x5c(%rbp), %ecx
andl $0x7, %ecx
sarl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x2228aa
jmp 0x22293a
movl -0x5c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jne 0x2228b7
jmp 0x22293a
movq 0x1a1722(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x64(%rbp), %ecx
movl -0x5c(%rbp), %r8d
movq -0x30(%rbp), %rax
movl -0x58(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movsd 0x8(%rax), %xmm0
leaq 0x16b512(%rip), %rsi    # 0x38ddf4
leaq 0x16b48e(%rip), %rdx    # 0x38dd77
movb $0x1, %al
callq 0x22a0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl -0x64(%rbp), %ecx
movsbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rcx
movl -0x5c(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x30(%rbp), %rax
movl -0x58(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm2
movsd -0x40(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x222861
movl -0x64(%rbp), %ecx
andl $0x7, %ecx
movl $0x1, %esi
shll %cl, %esi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
shrl $0x3, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x222776
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x16af1b(%rip), %xmm2   # 0x38d8c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21c580
movsd %xmm0, -0x50(%rbp)
movq 0x1a1615(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
leaq 0x16b432(%rip), %rsi    # 0x38de16
leaq 0x16b38c(%rip), %rdx    # 0x38dd77
movb $0x3, %al
callq 0x22a0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)