// File: monikakushwaha28[P]Fiduccia_Matthesys-using-c-/Fiduccia_Mattheyses_v1.0.cpp
// Function: cutset_cal(int)
int cutset_cal(int cutset)
{
	//Realizing the FM Algorithm
	//Variables
	x = 0; p = 0; q = 0; gain_cell = 0; max_gain = 0; cum_gain = 0;
	STOP = true; found_baseC1 = false; found_baseCn1 = false;
	check_cell = 0; check_part = 0; check_wgt = 0; nb_node = 0; node_gain = 0; count_p = 0; final_cutset = 0;
	max_gain_pos = 0;
	cum_gain_pos = 0;

	////////////////////////////////////////////////////////////////////////////START OF THE PASS//////////////////////////////////////////////////////////////////////////////////////
	while (STOP)
	{
		//Iterating the gain bucket
		for (gain_buk_iter b = gain_bucket.rbegin(); b != gain_bucket.rend(); b++) //Scanning key in DECENDING ORDER.
		{
			//Initializing checks for finding cells.
			found_baseC1 = false;
			found_baseCn1 = false;
			for (x = 0; x < b->second.size(); x++) //Scanning all cells in a particular key.
			{
				check_cell = b->second[x];
				gain_cell = b->first;
				if (node_map[check_cell][2] == 0) //Checking if Cell is fixed or not.
				{
					check_part = node_map[check_cell][1];
					check_wgt = node_map[check_cell][0];
					if (check_part == 1) //Checking in which partition does the cell lie.
					{
						if ((((wp1 - check_wgt) / (wp1 + wpn1)) >= 0.4)) //Checking if the cell satisfies the balance criterion.
						{
							//Qualifying the cell as the base cell.
							base_cell = check_cell;
							base_part = check_part;
							base_wgt = check_wgt;

							//MOVING THE CELL//
							//Changing the cell partition
							node_map[base_cell][1] = -1; //* (base_part);
							node_map[base_cell][2] = 1; //Fixing the cell
							wp1 = wp1 - base_wgt;
							wpn1 = wpn1 + base_wgt;

							fixed_cell_list.push_back(base_cell);

							cum_gain = cum_gain + gain_cell;
							cum_gain_pos = cum_gain_pos + 1;

							if (max_gain < cum_gain)
							{
								max_gain = cum_gain;
								max_gain_pos = cum_gain_pos;
								wp1_mincut = wp1;
								wpn1_mincut = wpn1;
							}

							found_baseC1 = true;
							break;
						}
					}
					else
					{
						if ((((wpn1 - check_wgt) / (wp1 + wpn1)) >= 0.4)) //Checking if the cell satisfies the balance criterion.
						{
							base_cell = check_cell;
							base_part = check_part;
							base_wgt = check_wgt;

							//MOVING THE CELL
							node_map[base_cell][1] = 1; // *(base_part); //change Part
							node_map[base_cell][2] = 1;
							wp1 = wp1 + base_wgt;
							wpn1 = wpn1 - base_wgt;

							fixed_cell_list.push_back(base_cell);

							cum_gain = cum_gain + gain_cell;
							cum_gain_pos = cum_gain_pos + 1;

							if (max_gain < cum_gain)
							{
								max_gain = cum_gain;
								max_gain_pos = cum_gain_pos;
								wp1_mincut = wp1;
								wpn1_mincut = wpn1;
							}

							found_baseCn1 = true;
							break;
						}
					}
				}
			}

			if (found_baseC1 || found_baseCn1)
			{
				break;
			}
		}

		//deleting the base cell from the gain bucket and also the empty keys created from updating gains of neighbours
		delete_base_and_empty_keys();

		//calling update gain function
		update_gain();

		//stop condition for the pass
		if (!gain_bucket.empty())
		{
			if ((gain_bucket[gain_bucket.begin()->first][(gain_bucket[gain_bucket.begin()->first].size() - 1)] == check_cell) && (check_cell != base_cell))
			{
				STOP = false;
			}
		}
		else
		{
			STOP = false;
		}

	}
	//final cutset
	cutset = cutset - max_gain;
	///////////////////////////////////////////////////////////////////////////////end of the pass /////////////////////////////////////////////////////////////////////////////

	//re constructing data structure
	re_cal_DS();
	return cutset;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movl $0x0, 0x12193(%rip)     # 0x16b68
movl $0x0, 0x1218d(%rip)     # 0x16b6c
movl $0x0, 0x12187(%rip)     # 0x16b70
movl $0x0, 0x12181(%rip)     # 0x16b74
movl $0x0, 0x1217b(%rip)     # 0x16b78
movl $0x0, 0x12175(%rip)     # 0x16b7c
movb $0x1, 0x117be(%rip)     # 0x161cc
movb $0x0, 0x1218f(%rip)     # 0x16ba4
movb $0x0, 0x12189(%rip)     # 0x16ba5
movl $0x0, 0x1215a(%rip)     # 0x16b80
movl $0x0, 0x12154(%rip)     # 0x16b84
movl $0x0, 0x1214e(%rip)     # 0x16b88
movl $0x0, 0x12148(%rip)     # 0x16b8c
movl $0x0, 0x12142(%rip)     # 0x16b90
movl $0x0, 0x1213c(%rip)     # 0x16b94
movl $0x0, 0x12136(%rip)     # 0x16b98
movl $0x0, 0x12130(%rip)     # 0x16b9c
movl $0x0, 0x1212a(%rip)     # 0x16ba0
testb $0x1, 0x1174f(%rip)     # 0x161cc
je 0x4fa2
leaq -0x10(%rbp), %rdi
leaq 0x121da(%rip), %rsi     # 0x16c68
callq 0x7440
leaq -0x18(%rbp), %rdi
leaq 0x121ca(%rip), %rsi     # 0x16c68
callq 0x74e0
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x74b0
testb $0x1, %al
jne 0x4ab9
jmp 0x4ed9
movb $0x0, 0x120e4(%rip)     # 0x16ba4
movb $0x0, 0x120de(%rip)     # 0x16ba5
movl $0x0, 0x12097(%rip)     # 0x16b68
movslq 0x12090(%rip), %rax     # 0x16b68
movq %rax, -0x38(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x7470
movq %rax, %rdi
addq $0x8, %rdi
callq 0x6c80
movq %rax, %rcx
movq -0x38(%rbp), %rax
cmpq %rcx, %rax
jae 0x4eaf
leaq -0x10(%rbp), %rdi
callq 0x7470
movq %rax, %rdi
addq $0x8, %rdi
movslq 0x12050(%rip), %rsi     # 0x16b68
callq 0x6ca0
movl (%rax), %eax
movl %eax, 0x1205b(%rip)     # 0x16b80
leaq -0x10(%rbp), %rdi
callq 0x7470
movl (%rax), %eax
movl %eax, 0x1203e(%rip)     # 0x16b74
leaq 0x1209b(%rip), %rdi     # 0x16bd8
leaq 0x1203c(%rip), %rsi     # 0x16b80
callq 0x6cc0
movq %rax, %rdi
movl $0x2, %esi
callq 0x6ca0
cmpl $0x0, (%rax)
jne 0x4e99
leaq 0x12072(%rip), %rdi     # 0x16bd8
leaq 0x12013(%rip), %rsi     # 0x16b80
callq 0x6cc0
movq %rax, %rdi
movl $0x1, %esi
callq 0x6ca0
movl (%rax), %eax
movl %eax, 0x11ffd(%rip)     # 0x16b84
leaq 0x1204a(%rip), %rdi     # 0x16bd8
leaq 0x11feb(%rip), %rsi     # 0x16b80
callq 0x6cc0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6ca0
movl (%rax), %eax
movl %eax, 0x11fda(%rip)     # 0x16b88
cmpl $0x1, 0x11fcf(%rip)     # 0x16b84
jne 0x4d2c
movss 0x11f65(%rip), %xmm0    # 0x16b28
cvtsi2ssl 0x11fbd(%rip), %xmm1 # 0x16b88
subss %xmm1, %xmm0
movss 0x11f51(%rip), %xmm1    # 0x16b28
addss 0x11f4d(%rip), %xmm1    # 0x16b2c
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xa419(%rip), %xmm1     # 0xf008
ucomisd %xmm1, %xmm0
jb 0x4d27
movl 0x11f81(%rip), %eax     # 0x16b80
movl %eax, 0x11f4f(%rip)     # 0x16b54
movl 0x11f79(%rip), %eax     # 0x16b84
movl %eax, 0x11f4b(%rip)     # 0x16b5c
movl 0x11f71(%rip), %eax     # 0x16b88
movl %eax, 0x11f3b(%rip)     # 0x16b58
leaq 0x11fb4(%rip), %rdi     # 0x16bd8
leaq 0x11f29(%rip), %rsi     # 0x16b54
callq 0x6cc0
movq %rax, %rdi
movl $0x1, %esi
callq 0x6ca0
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x11f8e(%rip), %rdi     # 0x16bd8
leaq 0x11f03(%rip), %rsi     # 0x16b54
callq 0x6cc0
movq %rax, %rdi
movl $0x2, %esi
callq 0x6ca0
movl $0x1, (%rax)
movss 0x11eb7(%rip), %xmm0    # 0x16b28
cvtsi2ssl 0x11edf(%rip), %xmm1 # 0x16b58
subss %xmm1, %xmm0
movss %xmm0, 0x11ea3(%rip)    # 0x16b28
movss 0x11e9f(%rip), %xmm0    # 0x16b2c
cvtsi2ssl 0x11ec3(%rip), %xmm1 # 0x16b58
addss %xmm1, %xmm0
movss %xmm0, 0x11e8b(%rip)    # 0x16b2c
leaq 0x12038(%rip), %rdi     # 0x16ce0
leaq 0x11ea5(%rip), %rsi     # 0x16b54
callq 0x6fc0
movl 0x11ec2(%rip), %eax     # 0x16b7c
addl 0x11eb4(%rip), %eax     # 0x16b74
movl %eax, 0x11eb6(%rip)     # 0x16b7c
movl 0x11ed4(%rip), %eax     # 0x16ba0
addl $0x1, %eax
movl %eax, 0x11ecb(%rip)     # 0x16ba0
movl 0x11e9d(%rip), %eax     # 0x16b78
cmpl 0x11e9b(%rip), %eax     # 0x16b7c
jge 0x4d1b
movl 0x11e93(%rip), %eax     # 0x16b7c
movl %eax, 0x11e89(%rip)     # 0x16b78
movl 0x11eab(%rip), %eax     # 0x16ba0
movl %eax, 0x11ea1(%rip)     # 0x16b9c
movss 0x11e25(%rip), %xmm0    # 0x16b28
movss %xmm0, 0x11e25(%rip)    # 0x16b30
movss 0x11e19(%rip), %xmm0    # 0x16b2c
movss %xmm0, 0x11e19(%rip)    # 0x16b34
movb $0x1, 0x11e82(%rip)     # 0x16ba4
jmp 0x4eaf
jmp 0x4e97
movss 0x11df8(%rip), %xmm0    # 0x16b2c
cvtsi2ssl 0x11e4c(%rip), %xmm1 # 0x16b88
subss %xmm1, %xmm0
movss 0x11de0(%rip), %xmm1    # 0x16b28
addss 0x11ddc(%rip), %xmm1    # 0x16b2c
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xa2a8(%rip), %xmm1     # 0xf008
ucomisd %xmm1, %xmm0
jb 0x4e95
movl 0x11e10(%rip), %eax     # 0x16b80
movl %eax, 0x11dde(%rip)     # 0x16b54
movl 0x11e08(%rip), %eax     # 0x16b84
movl %eax, 0x11dda(%rip)     # 0x16b5c
movl 0x11e00(%rip), %eax     # 0x16b88
movl %eax, 0x11dca(%rip)     # 0x16b58
leaq 0x11e43(%rip), %rdi     # 0x16bd8
leaq 0x11db8(%rip), %rsi     # 0x16b54
callq 0x6cc0
movq %rax, %rdi
movl $0x1, %esi
callq 0x6ca0
movl $0x1, (%rax)
leaq 0x11e1d(%rip), %rdi     # 0x16bd8
leaq 0x11d92(%rip), %rsi     # 0x16b54
callq 0x6cc0
movq %rax, %rdi
movl $0x2, %esi
callq 0x6ca0
movl $0x1, (%rax)
movss 0x11d46(%rip), %xmm0    # 0x16b28
cvtsi2ssl 0x11d6e(%rip), %xmm1 # 0x16b58
addss %xmm1, %xmm0
movss %xmm0, 0x11d32(%rip)    # 0x16b28
movss 0x11d2e(%rip), %xmm0    # 0x16b2c
cvtsi2ssl 0x11d52(%rip), %xmm1 # 0x16b58
subss %xmm1, %xmm0
movss %xmm0, 0x11d1a(%rip)    # 0x16b2c
leaq 0x11ec7(%rip), %rdi     # 0x16ce0
leaq 0x11d34(%rip), %rsi     # 0x16b54
callq 0x6fc0
movl 0x11d51(%rip), %eax     # 0x16b7c
addl 0x11d43(%rip), %eax     # 0x16b74
movl %eax, 0x11d45(%rip)     # 0x16b7c
movl 0x11d63(%rip), %eax     # 0x16ba0
addl $0x1, %eax
movl %eax, 0x11d5a(%rip)     # 0x16ba0
movl 0x11d2c(%rip), %eax     # 0x16b78
cmpl 0x11d2a(%rip), %eax     # 0x16b7c
jge 0x4e8c
movl 0x11d22(%rip), %eax     # 0x16b7c
movl %eax, 0x11d18(%rip)     # 0x16b78
movl 0x11d3a(%rip), %eax     # 0x16ba0
movl %eax, 0x11d30(%rip)     # 0x16b9c
movss 0x11cb4(%rip), %xmm0    # 0x16b28
movss %xmm0, 0x11cb4(%rip)    # 0x16b30
movss 0x11ca8(%rip), %xmm0    # 0x16b2c
movss %xmm0, 0x11ca8(%rip)    # 0x16b34
movb $0x1, 0x11d12(%rip)     # 0x16ba5
jmp 0x4eaf
jmp 0x4e97
jmp 0x4e99
jmp 0x4e9b
movl 0x11cc7(%rip), %eax     # 0x16b68
addl $0x1, %eax
movl %eax, 0x11cbe(%rip)     # 0x16b68
jmp 0x4ad1
testb $0x1, 0x11cee(%rip)     # 0x16ba4
jne 0x4ec1
testb $0x1, 0x11ce6(%rip)     # 0x16ba5
je 0x4ec3
jmp 0x4ed9
jmp 0x4ec5
leaq -0x20(%rbp), %rdi
leaq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x7510
jmp 0x4a93
callq 0x46f0
callq 0x3060
leaq 0x11d7e(%rip), %rdi     # 0x16c68
callq 0x7210
testb $0x1, %al
jne 0x4f96
leaq 0x11d6a(%rip), %rdi     # 0x16c68
callq 0x6da0
movq %rax, -0x28(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6e30
movq %rax, %rsi
leaq 0x11d4e(%rip), %rdi     # 0x16c68
callq 0x6cc0
movq %rax, -0x48(%rbp)
leaq 0x11d3e(%rip), %rdi     # 0x16c68
callq 0x6da0
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x6e30
movq %rax, %rsi
leaq 0x11d22(%rip), %rdi     # 0x16c68
callq 0x6cc0
movq %rax, %rdi
callq 0x6c80
movq -0x48(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x6ca0
movl (%rax), %ecx
xorl %eax, %eax
cmpl 0x11c13(%rip), %ecx     # 0x16b80
movb %al, -0x39(%rbp)
jne 0x4f84
movl 0x11c08(%rip), %eax     # 0x16b80
cmpl 0x11bd6(%rip), %eax     # 0x16b54
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x4f8d
jmp 0x4f94
movb $0x0, 0x11238(%rip)     # 0x161cc
jmp 0x4f9d
movb $0x0, 0x1122f(%rip)     # 0x161cc
jmp 0x4a76
movl -0x4(%rbp), %eax
subl 0x11bcd(%rip), %eax     # 0x16b78
movl %eax, -0x4(%rbp)
callq 0x2aa0
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)