// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, -0x2c(%rbp)
xorl %r14d, %r14d
movl %r14d, 0x789c(%rip)     # 0xbb60
movl %r14d, 0x7899(%rip)     # 0xbb64
movl %r14d, 0x7896(%rip)     # 0xbb68
movl %r14d, 0x7893(%rip)     # 0xbb6c
movl %r14d, 0x7890(%rip)     # 0xbb70
movl %r14d, 0x788d(%rip)     # 0xbb74
movb $0x1, 0x6ed6(%rip)      # 0xb1c4
movb %r14b, 0x78a7(%rip)     # 0xbb9c
movb %r14b, 0x78a1(%rip)     # 0xbb9d
movl %r14d, 0x7875(%rip)     # 0xbb78
movl %r14d, 0x7872(%rip)     # 0xbb7c
movl %r14d, 0x786f(%rip)     # 0xbb80
movl %r14d, 0x786c(%rip)     # 0xbb84
movl %r14d, 0x7869(%rip)     # 0xbb88
movl %r14d, 0x7866(%rip)     # 0xbb8c
movl %r14d, 0x7863(%rip)     # 0xbb90
movl %r14d, 0x7860(%rip)     # 0xbb94
movl %r14d, 0x785d(%rip)     # 0xbb98
leaq 0x7836(%rip), %r15      # 0xbb78
leaq 0x7887(%rip), %r12      # 0xbbd0
leaq 0x7918(%rip), %rax      # 0xbc68
cmpq %rax, 0x7921(%rip)      # 0xbc78
je 0x46b9
leaq 0x7904(%rip), %rbx      # 0xbc68
movb %r14b, 0x7831(%rip)     # 0xbb9c
movb %r14b, 0x782b(%rip)     # 0xbb9d
movl $0x0, 0x77e4(%rip)      # 0xbb60
movq %rbx, %rdi
callq 0x2210
movq 0x28(%rax), %rcx
cmpq %rcx, 0x30(%rax)
je 0x468f
xorl %r13d, %r13d
movl (%rcx,%r13,4), %eax
movl %eax, 0x77d9(%rip)      # 0xbb78
movq %rbx, %rdi
callq 0x2210
movl 0x20(%rax), %eax
movl %eax, 0x77bc(%rip)      # 0xbb6c
movq %r12, %rdi
movq %r15, %rsi
callq 0x5f62
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x4465
movq %r12, %rdi
movq %r15, %rsi
callq 0x5f62
movq (%rax), %rax
movl 0x4(%rax), %eax
movl %eax, 0x779d(%rip)      # 0xbb7c
movq %r12, %rdi
movq %r15, %rsi
callq 0x5f62
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x778b(%rip)      # 0xbb80
movl 0x7781(%rip), %ecx      # 0xbb7c
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cmpl $0x1, %ecx
jne 0x4435
movss 0x7711(%rip), %xmm1     # 0xbb20
movaps %xmm1, %xmm2
subss %xmm0, %xmm2
addss 0x7706(%rip), %xmm1     # 0xbb24
divss %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
ucomisd 0x3bd7(%rip), %xmm0     # 0x8008
jb 0x4465
jmp 0x449b
movss 0x76e7(%rip), %xmm1     # 0xbb24
movaps %xmm1, %xmm2
subss %xmm0, %xmm2
addss 0x76d4(%rip), %xmm1     # 0xbb20
divss %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
ucomisd 0x3ba9(%rip), %xmm0     # 0x8008
jae 0x4543
movslq 0x76f4(%rip), %r13      # 0xbb60
incq %r13
movl %r13d, 0x76ea(%rip)     # 0xbb60
movq %rbx, %rdi
callq 0x2210
movq 0x28(%rax), %rcx
movq 0x30(%rax), %rax
subq %rcx, %rax
sarq $0x2, %rax
cmpq %r13, %rax
ja 0x4395
jmp 0x468f
movl 0x76d7(%rip), %ecx      # 0xbb78
movl %ecx, 0x76a5(%rip)      # 0xbb4c
movl $0x1, %r14d
movl %r14d, 0x76a0(%rip)     # 0xbb54
movl %eax, 0x7696(%rip)      # 0xbb50
movq %r12, %rdi
leaq 0x7688(%rip), %r13      # 0xbb4c
movq %r13, %rsi
callq 0x5f62
movq (%rax), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq %r12, %rdi
movq %r13, %rsi
callq 0x5f62
movq (%rax), %rax
movl %r14d, 0x8(%rax)
movss 0x7630(%rip), %xmm0     # 0xbb20
xorps %xmm1, %xmm1
cvtsi2ssl 0x7655(%rip), %xmm1 # 0xbb50
subss %xmm1, %xmm0
movss %xmm0, 0x7619(%rip)     # 0xbb20
addss 0x7615(%rip), %xmm1     # 0xbb24
movss %xmm1, 0x760d(%rip)     # 0xbb24
movq 0x77c2(%rip), %rsi      # 0xbce0
cmpq 0x77c3(%rip), %rsi      # 0xbce8
je 0x45e4
movl 0x761b(%rip), %eax      # 0xbb4c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x77a2(%rip)      # 0xbce0
jmp 0x45f3
movl 0x762f(%rip), %edx      # 0xbb78
movl %edx, 0x75fd(%rip)      # 0xbb4c
movl %ecx, 0x75ff(%rip)      # 0xbb54
movl %eax, 0x75f5(%rip)      # 0xbb50
movq %r12, %rdi
leaq 0x75e7(%rip), %r13      # 0xbb4c
movq %r13, %rsi
callq 0x5f62
movq (%rax), %rax
movl $0x1, %r14d
movl %r14d, 0x4(%rax)
movq %r12, %rdi
movq %r13, %rsi
callq 0x5f62
movq (%rax), %rax
movl %r14d, 0x8(%rax)
xorps %xmm0, %xmm0
cvtsi2ssl 0x75b9(%rip), %xmm0 # 0xbb50
movss 0x7581(%rip), %xmm1     # 0xbb20
addss %xmm0, %xmm1
movss %xmm1, 0x7575(%rip)     # 0xbb20
movss 0x7571(%rip), %xmm1     # 0xbb24
subss %xmm0, %xmm1
movss %xmm1, 0x7565(%rip)     # 0xbb24
movq 0x771a(%rip), %rsi      # 0xbce0
cmpq 0x771b(%rip), %rsi      # 0xbce8
je 0x461c
movl 0x7577(%rip), %eax      # 0xbb4c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x76fe(%rip)      # 0xbce0
jmp 0x462b
leaq 0x76ed(%rip), %rdi      # 0xbcd8
movq %r13, %rdx
callq 0x6ba2
movl 0x7573(%rip), %eax      # 0xbb6c
addl 0x7575(%rip), %eax      # 0xbb74
movl %eax, 0x756f(%rip)      # 0xbb74
movl 0x758d(%rip), %ecx      # 0xbb98
incl %ecx
movl %ecx, 0x7585(%rip)      # 0xbb98
leaq 0x7582(%rip), %rdx      # 0xbb9c
jmp 0x4652
leaq 0x76b5(%rip), %rdi      # 0xbcd8
movq %r13, %rdx
callq 0x6ba2
movl 0x753b(%rip), %eax      # 0xbb6c
addl 0x753d(%rip), %eax      # 0xbb74
movl %eax, 0x7537(%rip)      # 0xbb74
movl 0x7555(%rip), %ecx      # 0xbb98
incl %ecx
movl %ecx, 0x754d(%rip)      # 0xbb98
leaq 0x754b(%rip), %rdx      # 0xbb9d
cmpl %eax, 0x7518(%rip)      # 0xbb70
movl $0x0, %r14d
jge 0x468c
movl %eax, 0x750a(%rip)      # 0xbb70
movl %ecx, 0x7528(%rip)      # 0xbb94
movss 0x74ac(%rip), %xmm0     # 0xbb20
movss %xmm0, 0x74ac(%rip)     # 0xbb28
movss 0x74a0(%rip), %xmm0     # 0xbb24
movss %xmm0, 0x74a0(%rip)     # 0xbb2c
movb $0x1, (%rdx)
cmpb $0x0, 0x7506(%rip)      # 0xbb9c
jne 0x46b9
cmpb $0x0, 0x74fe(%rip)      # 0xbb9d
jne 0x46b9
movq %rbx, %rdi
callq 0x2210
movq %rax, %rbx
cmpq 0x75c5(%rip), %rax      # 0xbc78
jne 0x4364
callq 0x4050
callq 0x2eb7
cmpq $0x0, 0x75bd(%rip)      # 0xbc88
je 0x472a
movq 0x75a4(%rip), %rsi      # 0xbc78
addq $0x20, %rsi
leaq 0x7581(%rip), %r13      # 0xbc60
movq %r13, %rdi
callq 0x5f62
movq %rax, %rbx
movq 0x7587(%rip), %rsi      # 0xbc78
addq $0x20, %rsi
movq %r13, %rdi
callq 0x5f62
movq 0x8(%rax), %rcx
subq (%rax), %rcx
movq (%rbx), %rdx
movl 0x746b(%rip), %eax      # 0xbb78
cmpl %eax, -0x4(%rdx,%rcx)
jne 0x471b
cmpl 0x7433(%rip), %eax      # 0xbb4c
jne 0x472a
testb $0x1, 0x6aa2(%rip)      # 0xb1c4
jne 0x4349
jmp 0x4731
movb $0x0, 0x6a93(%rip)      # 0xb1c4
movl -0x2c(%rbp), %ebx
subl 0x7436(%rip), %ebx      # 0xbb70
callq 0x29b7
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq