// File: 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
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movslq 0x84(%rax), %rcx
leaq 0xbdbb(%rip), %rdi      # 0x11200
imulq $0x30, %rcx, %rcx
addq %rcx, %rdi
movq 0x90(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rsi
callq 0x67a0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x18(%rbp)
movb $0x1, 0x7d(%rax)
movl 0x80(%rax), %edx
movl 0xbe2d(%rip), %ecx      # 0x112a8
subl %edx, %ecx
movl %ecx, 0xbe25(%rip)      # 0x112a8
movl 0x84(%rax), %ecx
movl %ecx, -0x1c(%rbp)
movl 0x78(%rax), %ecx
movslq 0x84(%rax), %rdx
leaq 0xbe0f(%rip), %rsi      # 0x112ac
movl (%rsi,%rdx,4), %esi
subl %ecx, %esi
leaq 0xbe03(%rip), %rcx      # 0x112ac
movl %esi, (%rcx,%rdx,4)
cmpl $0x0, 0x84(%rax)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl %ecx, 0x84(%rax)
movl 0x78(%rax), %esi
movslq 0x84(%rax), %rdx
leaq 0xbdd6(%rip), %rcx      # 0x112ac
addl (%rcx,%rdx,4), %esi
leaq 0xbdcc(%rip), %rcx      # 0x112ac
movl %esi, (%rcx,%rdx,4)
cmpl $0x0, 0x80(%rax)
jge 0x54f3
movb $0x1, 0xbde9(%rip)      # 0x112dc
movl $0x0, -0x20(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
addq $0x98, %rdi
callq 0x52a0
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jae 0x59c9
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rax
testb $0x1, 0x6a(%rax)
je 0x5561
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rax
testb $0x1, 0x6b(%rax)
je 0x5561
jmp 0x59bb
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq -0x40(%rbp), %rdi
movq (%rax), %rax
cmpl $0x0, 0x84(%rdi)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl 0x6c(%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq -0x40(%rbp), %rcx
movq (%rax), %rax
movslq 0x84(%rcx), %rcx
movl 0x6c(%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x5673
movl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x2c(%rbp), %rax
movq %rax, -0x50(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
callq 0x5260
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0x566e
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x5280
movq (%rax), %rax
testb $0x1, 0x7d(%rax)
jne 0x565e
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x5280
movq (%rax), %rdi
movl $0x1, %esi
callq 0x67e0
jmp 0x5660
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x55cc
jmp 0x576b
cmpl $0x1, -0x28(%rbp)
jne 0x5769
movl $0x0, -0x30(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
callq 0x5260
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jae 0x5767
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x30(%rbp), %rsi
callq 0x5280
movq (%rax), %rax
testb $0x1, 0x7d(%rax)
jne 0x5757
movq -0x40(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, -0x5c(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x30(%rbp), %rsi
callq 0x5280
movq %rax, %rcx
movl -0x5c(%rbp), %eax
movq (%rcx), %rcx
cmpl 0x84(%rcx), %eax
je 0x5757
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x30(%rbp), %rsi
callq 0x5280
movq (%rax), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x67e0
jmp 0x5767
jmp 0x5759
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x5684
jmp 0x5769
jmp 0x576b
movq -0x40(%rbp), %rdi
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq -0x40(%rbp), %rdi
movq (%rax), %rax
cmpl $0x0, 0x84(%rdi)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl 0x6c(%rax,%rcx,4), %edx
addl $-0x1, %edx
movl %edx, 0x6c(%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq -0x40(%rbp), %rcx
movq (%rax), %rax
movslq 0x84(%rcx), %rcx
movl 0x6c(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x6c(%rax,%rcx,4)
cmpl $0x0, -0x24(%rbp)
jne 0x5897
movl $0x0, -0x34(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x34(%rbp), %rax
movq %rax, -0x68(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
callq 0x5260
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jae 0x5892
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x34(%rbp), %rsi
callq 0x5280
movq (%rax), %rax
testb $0x1, 0x7d(%rax)
jne 0x5882
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x34(%rbp), %rsi
callq 0x5280
movq (%rax), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x67e0
jmp 0x5884
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x57f0
jmp 0x598f
cmpl $0x1, -0x24(%rbp)
jne 0x598d
movl $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
callq 0x5260
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jae 0x598b
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x38(%rbp), %rsi
callq 0x5280
movq (%rax), %rax
testb $0x1, 0x7d(%rax)
jne 0x597b
movq -0x40(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, -0x74(%rbp)
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x38(%rbp), %rsi
callq 0x5280
movq %rax, %rcx
movl -0x74(%rbp), %eax
movq (%rcx), %rcx
cmpl 0x84(%rcx), %eax
jne 0x597b
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rdi
addq $0x78, %rdi
movslq -0x38(%rbp), %rsi
callq 0x5280
movq (%rax), %rdi
movl $0x1, %esi
callq 0x67e0
jmp 0x598b
jmp 0x597d
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x58a8
jmp 0x598d
jmp 0x598f
movq -0x40(%rbp), %rdi
addq $0x98, %rdi
movslq -0x20(%rbp), %rsi
callq 0x52c0
movq (%rax), %rax
cmpl $0x0, -0x1c(%rbp)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
movb $0x1, 0x6a(%rax,%rcx)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x54fa
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)