// File: /workspace/github_cpp_makefile_star2_O2/searsm8[P]FM_Partitioning/fmpart.cpp
// Function: CELL::changePartition()
void changePartition()
	{		
		//remove the cell from the bucket i.e. "lock" the cell until the next pass
		gain_bucket[partition].erase(gain_itr);				
		locked = true;	
		
		//update cut_size. cutsize is reduced by the gain of the moved cell.
		cut_size -= gain;		
			
		int base_partition = partition;
		
		//change partition for this cell
		partition_area[partition] -= area; //decrease area in old partition
		partition = !partition;		
		partition_area[partition] += area; //increase area in new partition
		
		if(gain < 0)
			positive_gains_exhausted = true;
											
		//Update the gain of all neighboring cells		
		//Loop through all nets the cell is on. Update gains for neighboring cells on critical nets
		for(int i = 0; i < net_list.size(); i++)
		{						
			//if the net has a locked (or fixed) cell in both partitions,
			//then the net is "dead" and cannot cause any change in cutstate (prevents wasting time)
			if(net_list[i]->has_locked[0] && net_list[i]->has_locked[1])
			{				
				continue;
			}
							
			//create "From" and "To" partition counts
			int from = net_list[i]->partition_count[!partition];   //i.e. F(n), where the cell came from
			int to   = net_list[i]->partition_count[partition];    //i.e. T(n), where the cell is going to
			
		//check critical nets before the move
			if(to == 0)
			{
			//increment gain on all free cells on this net
				for(int k = 0; k < net_list[i]->cell_list.size(); k++)
				{
					if((!net_list[i]->cell_list[k]->locked))		
					{
						net_list[i]->cell_list[k]->updateGain(1);
					}
				}
			}								
			else if (to == 1)
			{
			//decrement gain of the only "to" cell
				for(int k = 0; k < net_list[i]->cell_list.size(); k++)
				{
					if(!net_list[i]->cell_list[k]->locked && base_partition != net_list[i]->cell_list[k]->partition)
					{						
						net_list[i]->cell_list[k]->updateGain(-1);
						break;
					}
				}
			}
							
			//update from and to counts
			from--;
			net_list[i]->partition_count[!partition]--;
			to++;
			net_list[i]->partition_count[partition]++;
			
			//check critical nets after the move
			if(from == 0)
			{ 
			//decrement gain on all free cells on this net
				for(int k = 0; k < net_list[i]->cell_list.size(); k++)
				{
					if(!net_list[i]->cell_list[k]->locked)		
					{
						net_list[i]->cell_list[k]->updateGain(-1);
					}
				}
			}								
			else if (from == 1)
			{
			//increment gain of the only "from" cell
				for(int k = 0; k < net_list[i]->cell_list.size(); k++)
				{
					if(!net_list[i]->cell_list[k]->locked && base_partition == net_list[i]->cell_list[k]->partition)
					{
						net_list[i]->cell_list[k]->updateGain(1);
						break;
					}
				}
			}
			
			//update the has_locked member for this net for the "To" partition
			net_list[i]->has_locked[!base_partition] = true;
		}	
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movslq 0x84(%rdi), %rax
imulq $0x30, %rax, %rax
leaq 0x48a9(%rip), %rdi      # 0x81b0
addq %rax, %rdi
movq 0x90(%rbx), %rsi
callq 0x3ce6
movb $0x1, 0x7d(%rbx)
movl 0x80(%rbx), %eax
subl %eax, 0x4932(%rip)      # 0x8258
movslq 0x84(%rbx), %r12
xorl %r15d, %r15d
testq %r12, %r12
sete %r15b
movl 0x78(%rbx), %ecx
leaq 0x491b(%rip), %rdx      # 0x825c
subl %ecx, (%rdx,%r12,4)
movl %r15d, 0x84(%rbx)
addl %ecx, (%rdx,%r15,4)
testl %eax, %eax
jns 0x395b
movb $0x1, 0x4931(%rip)      # 0x828c
movq 0x98(%rbx), %rax
xorl %r13d, %r13d
movq %r15, -0x30(%rbp)
movq 0xa0(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
jbe 0x3af6
movq (%rax,%r13,8), %rcx
cmpb $0x1, 0x6a(%rcx)
jne 0x3994
cmpb $0x0, 0x6b(%rcx)
jne 0x3aee
movslq 0x84(%rbx), %rdx
xorl %esi, %esi
testq %rdx, %rdx
sete %sil
movl 0x6c(%rcx,%rsi,4), %r14d
movl 0x6c(%rcx,%rdx,4), %edx
cmpl $0x1, %edx
je 0x39fc
testl %edx, %edx
jne 0x3a41
xorl %r15d, %r15d
movq 0x78(%rcx), %rdx
movq 0x80(%rcx), %rsi
subq %rdx, %rsi
sarq $0x3, %rsi
cmpq %r15, %rsi
jbe 0x39f6
movq (%rdx,%r15,8), %rdi
cmpb $0x0, 0x7d(%rdi)
jne 0x39f1
pushq $0x1
popq %rsi
callq 0x3c68
movq 0x98(%rbx), %rax
movq (%rax,%r13,8), %rcx
incq %r15
jmp 0x39bd
movq -0x30(%rbp), %r15
jmp 0x3a41
movq 0x78(%rcx), %rdx
movq 0x80(%rcx), %rsi
subq %rdx, %rsi
sarq $0x3, %rsi
xorl %r8d, %r8d
cmpq %r8, %rsi
je 0x3a41
movq (%rdx,%r8,8), %rdi
cmpb $0x0, 0x7d(%rdi)
jne 0x3a29
cmpl 0x84(%rdi), %r12d
jne 0x3a2e
incq %r8
jmp 0x3a11
pushq $-0x1
popq %rsi
callq 0x3c68
movq 0x98(%rbx), %rax
movq (%rax,%r13,8), %rcx
xorl %edx, %edx
cmpl $0x0, 0x84(%rbx)
sete %dl
decl 0x6c(%rcx,%rdx,4)
movslq 0x84(%rbx), %rdx
incl 0x6c(%rcx,%rdx,4)
cmpl $0x2, %r14d
je 0x3aa4
cmpl $0x1, %r14d
jne 0x3ae4
xorl %r14d, %r14d
movq 0x78(%rcx), %rdx
movq 0x80(%rcx), %rsi
subq %rdx, %rsi
sarq $0x3, %rsi
cmpq %r14, %rsi
jbe 0x3ae4
movq (%rdx,%r14,8), %rdi
cmpb $0x0, 0x7d(%rdi)
jne 0x3a9f
pushq $-0x1
popq %rsi
callq 0x3c68
movq 0x98(%rbx), %rax
movq (%rax,%r13,8), %rcx
incq %r14
jmp 0x3a6b
movq 0x78(%rcx), %rdx
movq 0x80(%rcx), %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x3ae4
movq (%rdx,%rsi,8), %rdi
cmpb $0x0, 0x7d(%rdi)
jne 0x3ad0
cmpl 0x84(%rdi), %r12d
je 0x3ad5
incq %rsi
jmp 0x3ab8
pushq $0x1
popq %rsi
callq 0x3c68
movq 0x98(%rbx), %rax
movq (%rax,%r13,8), %rcx
movb $0x1, 0x6a(%rcx,%r15)
incq %r13
jmp 0x3969
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq