// File: searsm8[P]FM_Partitioning/fmpart.cpp
// Function: computeGains()
void computeGains()
{
	gain_bucket[0].clear();
	gain_bucket[1].clear();
	
	//look through all cells, compute gain for each cell 
	for(int i = 0; i < cells.size(); i++)
	{	
		cells[i]->gain = 0;
		
			
		//for each net the cell is in, check if there is any gain for that net
		for (int j = 0; j < cells[i]->net_list.size(); j++)
		{	
			NET* current_net = cells[i]->net_list[j];				
						
			//if there is exactly one cell in the "From" partition, increase gain
			if(current_net->partition_count[cells[i]->partition] == 1)
			{	
				cells[i]->gain++;
				current_net->critical = true;
			}
			
			//if there is exactly zero cells in the "To" partition, decrease gain
			if(current_net->partition_count[!cells[i]->partition] == 0)
			{	
				cells[i]->gain--;
				current_net->critical = true;
			}			
		}
		
		//add this cell to a gain bucket, and initialize gain_itr				
		cells[i]->gain_itr = gain_bucket[cells[i]->partition].insert(pair <int, CELL*> (cells[i]->gain,  cells[i]));	
	} 			
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
leaq 0xd5b1(%rip), %rdi      # 0x11200
callq 0x52e0
leaq 0xd5a5(%rip), %rdi      # 0x11200
addq $0x30, %rdi
callq 0x52e0
movl $0x0, -0x4(%rbp)
movslq -0x4(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq 0xd5e6(%rip), %rdi      # 0x11260
callq 0x5260
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
jae 0x3e8a
movslq -0x4(%rbp), %rsi
leaq 0xd5c6(%rip), %rdi      # 0x11260
callq 0x5280
movq (%rax), %rax
movl $0x0, 0x80(%rax)
movl $0x0, -0x8(%rbp)
movslq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0xd59a(%rip), %rdi      # 0x11260
callq 0x5280
movq (%rax), %rdi
addq $0x98, %rdi
callq 0x52a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
cmpq %rcx, %rax
jae 0x3de4
movslq -0x4(%rbp), %rsi
leaq 0xd56b(%rip), %rdi      # 0x11260
callq 0x5280
movq (%rax), %rdi
addq $0x98, %rdi
movslq -0x8(%rbp), %rsi
callq 0x52c0
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0xd539(%rip), %rdi      # 0x11260
callq 0x5280
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq (%rcx), %rcx
movslq 0x84(%rcx), %rcx
cmpl $0x1, 0x6c(%rax,%rcx,4)
jne 0x3d6e
movslq -0x4(%rbp), %rsi
leaq 0xd511(%rip), %rdi      # 0x11260
callq 0x5280
movq (%rax), %rax
movl 0x80(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x80(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x69(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0xd4df(%rip), %rdi      # 0x11260
callq 0x5280
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq (%rcx), %rcx
cmpl $0x0, 0x84(%rcx)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl $0x0, 0x6c(%rax,%rcx,4)
jne 0x3dd4
movslq -0x4(%rbp), %rsi
leaq 0xd4ab(%rip), %rdi      # 0x11260
callq 0x5280
movq (%rax), %rax
movl 0x80(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x80(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x69(%rax)
jmp 0x3dd6
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x3cb3
movslq -0x4(%rbp), %rsi
leaq 0xd471(%rip), %rdi      # 0x11260
callq 0x5280
movq (%rax), %rax
movslq 0x84(%rax), %rcx
leaq 0xd3fb(%rip), %rax      # 0x11200
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0xd445(%rip), %rdi      # 0x11260
callq 0x5280
movq (%rax), %rax
addq $0x80, %rax
movq %rax, -0x58(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0xd428(%rip), %rdi      # 0x11260
callq 0x5280
movq -0x58(%rbp), %rsi
movq %rax, %rdx
leaq -0x28(%rbp), %rdi
callq 0x5330
movq -0x50(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x5300
movq %rax, -0x18(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0xd3f7(%rip), %rdi      # 0x11260
callq 0x5280
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq %rcx, 0x90(%rax)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x3c6b
addq $0x60, %rsp
popq %rbp
retq