// File: /workspace/github_cpp_makefile_star2_O1/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 %eax, %eax
movl %eax, 0x78e6(%rip)      # 0xbb60
movl %eax, 0x78e4(%rip)      # 0xbb64
movl %eax, 0x78e2(%rip)      # 0xbb68
movl %eax, 0x78e0(%rip)      # 0xbb6c
movl %eax, 0x78de(%rip)      # 0xbb70
movl %eax, 0x78dc(%rip)      # 0xbb74
movb $0x1, 0x6f25(%rip)      # 0xb1c4
movb %al, 0x78f7(%rip)       # 0xbb9c
movb %al, 0x78f2(%rip)       # 0xbb9d
movl %eax, 0x78c7(%rip)      # 0xbb78
movl %eax, 0x78c5(%rip)      # 0xbb7c
movl %eax, 0x78c3(%rip)      # 0xbb80
movl %eax, 0x78c1(%rip)      # 0xbb84
movl %eax, 0x78bf(%rip)      # 0xbb88
movl %eax, 0x78bd(%rip)      # 0xbb8c
movl %eax, 0x78bb(%rip)      # 0xbb90
movl %eax, 0x78b9(%rip)      # 0xbb94
movl %eax, 0x78b7(%rip)      # 0xbb98
testb %al, %al
jne 0x46f5
xorl %r14d, %r14d
leaq 0x7885(%rip), %r15      # 0xbb78
leaq 0x78d6(%rip), %r12      # 0xbbd0
leaq 0x7967(%rip), %rax      # 0xbc68
cmpq %rax, 0x7970(%rip)      # 0xbc78
je 0x467f
leaq 0x7953(%rip), %rbx      # 0xbc68
movb %r14b, 0x7880(%rip)     # 0xbb9c
movb %r14b, 0x787a(%rip)     # 0xbb9d
movl $0x0, 0x7833(%rip)      # 0xbb60
movq %rbx, %rdi
callq 0x2210
movq 0x28(%rax), %rcx
cmpq %rcx, 0x30(%rax)
je 0x4605
xorl %r13d, %r13d
movl (%rcx,%r13,4), %eax
movl %eax, 0x7828(%rip)      # 0xbb78
movq %rbx, %rdi
callq 0x2210
movl 0x20(%rax), %eax
movl %eax, 0x780b(%rip)      # 0xbb6c
movq %r12, %rdi
movq %r15, %rsi
callq 0x5f42
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x4416
movq %r12, %rdi
movq %r15, %rsi
callq 0x5f42
movq (%rax), %rax
movl 0x4(%rax), %eax
movl %eax, 0x77ec(%rip)      # 0xbb7c
movq %r12, %rdi
movq %r15, %rsi
callq 0x5f42
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x77da(%rip)      # 0xbb80
movl 0x77d0(%rip), %ecx      # 0xbb7c
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cmpl $0x1, %ecx
jne 0x43e6
movss 0x7760(%rip), %xmm1     # 0xbb20
movaps %xmm1, %xmm2
subss %xmm0, %xmm2
addss 0x7755(%rip), %xmm1     # 0xbb24
divss %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
ucomisd 0x3c26(%rip), %xmm0     # 0x8008
jb 0x4416
jmp 0x444c
movss 0x7736(%rip), %xmm1     # 0xbb24
movaps %xmm1, %xmm2
subss %xmm0, %xmm2
addss 0x7723(%rip), %xmm1     # 0xbb20
divss %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
ucomisd 0x3bf8(%rip), %xmm0     # 0x8008
jae 0x44f0
movslq 0x7743(%rip), %r13      # 0xbb60
incq %r13
movl %r13d, 0x7739(%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 0x4346
jmp 0x4605
movl 0x7726(%rip), %edx      # 0xbb78
movl %edx, 0x76f4(%rip)      # 0xbb4c
movl %ecx, 0x76f6(%rip)      # 0xbb54
movl %eax, 0x76ec(%rip)      # 0xbb50
movq %r12, %rdi
leaq 0x76de(%rip), %r13      # 0xbb4c
movq %r13, %rsi
callq 0x5f42
movq (%rax), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq %r12, %rdi
movq %r13, %rsi
callq 0x5f42
movq (%rax), %rax
movl $0x1, 0x8(%rax)
movss 0x7683(%rip), %xmm0     # 0xbb20
xorps %xmm1, %xmm1
cvtsi2ssl 0x76a8(%rip), %xmm1 # 0xbb50
subss %xmm1, %xmm0
movss %xmm0, 0x766c(%rip)     # 0xbb20
addss 0x7668(%rip), %xmm1     # 0xbb24
movss %xmm1, 0x7660(%rip)     # 0xbb24
movq 0x7815(%rip), %rsi      # 0xbce0
cmpq 0x7816(%rip), %rsi      # 0xbce8
je 0x4598
movl 0x766e(%rip), %eax      # 0xbb4c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x77f5(%rip)      # 0xbce0
jmp 0x45a7
movl 0x7682(%rip), %edx      # 0xbb78
movl %edx, 0x7650(%rip)      # 0xbb4c
movl %ecx, 0x7652(%rip)      # 0xbb54
movl %eax, 0x7648(%rip)      # 0xbb50
movq %r12, %rdi
leaq 0x763a(%rip), %r13      # 0xbb4c
movq %r13, %rsi
callq 0x5f42
movq (%rax), %rax
movl $0x1, %r14d
movl %r14d, 0x4(%rax)
movq %r12, %rdi
movq %r13, %rsi
callq 0x5f42
movq (%rax), %rax
movl %r14d, 0x8(%rax)
xorps %xmm0, %xmm0
cvtsi2ssl 0x760c(%rip), %xmm0 # 0xbb50
movss 0x75d4(%rip), %xmm1     # 0xbb20
addss %xmm0, %xmm1
movss %xmm1, 0x75c8(%rip)     # 0xbb20
movss 0x75c4(%rip), %xmm1     # 0xbb24
subss %xmm0, %xmm1
movss %xmm1, 0x75b8(%rip)     # 0xbb24
movq 0x776d(%rip), %rsi      # 0xbce0
cmpq 0x776e(%rip), %rsi      # 0xbce8
je 0x4631
movl 0x75c6(%rip), %eax      # 0xbb4c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x774d(%rip)      # 0xbce0
jmp 0x4644
leaq 0x7739(%rip), %rdi      # 0xbcd8
movq %r13, %rdx
callq 0x6bbc
movl 0x75bf(%rip), %eax      # 0xbb6c
addl 0x75c1(%rip), %eax      # 0xbb74
movl %eax, 0x75bb(%rip)      # 0xbb74
movl 0x75d9(%rip), %ecx      # 0xbb98
incl %ecx
movl %ecx, 0x75d1(%rip)      # 0xbb98
leaq 0x75ce(%rip), %rdx      # 0xbb9c
cmpl %eax, 0x759c(%rip)      # 0xbb70
jge 0x4602
movl %eax, 0x7594(%rip)      # 0xbb70
movl %ecx, 0x75b2(%rip)      # 0xbb94
movss 0x7536(%rip), %xmm0     # 0xbb20
movss %xmm0, 0x7536(%rip)     # 0xbb28
movss 0x752a(%rip), %xmm0     # 0xbb24
movss %xmm0, 0x752a(%rip)     # 0xbb2c
movb $0x1, (%rdx)
cmpb $0x0, 0x7590(%rip)      # 0xbb9c
jne 0x467f
cmpb $0x0, 0x7588(%rip)      # 0xbb9d
jne 0x467f
movq %rbx, %rdi
callq 0x2210
movq %rax, %rbx
cmpq 0x764f(%rip), %rax      # 0xbc78
jne 0x4315
jmp 0x467f
leaq 0x76a0(%rip), %rdi      # 0xbcd8
leaq 0x750d(%rip), %rdx      # 0xbb4c
callq 0x6bbc
movl 0x7522(%rip), %eax      # 0xbb6c
addl 0x7524(%rip), %eax      # 0xbb74
movl %eax, 0x751e(%rip)      # 0xbb74
movl 0x753c(%rip), %ecx      # 0xbb98
incl %ecx
movl %ecx, 0x7534(%rip)      # 0xbb98
leaq 0x7532(%rip), %rdx      # 0xbb9d
cmpl %eax, 0x74ff(%rip)      # 0xbb70
movl $0x0, %r14d
jl 0x45d6
jmp 0x4602
callq 0x4010
callq 0x2eb7
cmpq $0x0, 0x75f7(%rip)      # 0xbc88
je 0x46e1
movq 0x75de(%rip), %rsi      # 0xbc78
addq $0x20, %rsi
leaq 0x75bb(%rip), %r13      # 0xbc60
movq %r13, %rdi
callq 0x5f42
movq %rax, %rbx
movq 0x75c1(%rip), %rsi      # 0xbc78
addq $0x20, %rsi
movq %r13, %rdi
callq 0x5f42
movq 0x8(%rax), %rcx
subq (%rax), %rcx
movq (%rbx), %rdx
movl 0x74a5(%rip), %eax      # 0xbb78
cmpl %eax, -0x4(%rdx,%rcx)
jne 0x46e8
cmpl 0x746d(%rip), %eax      # 0xbb4c
je 0x46e8
movb $0x0, 0x6adc(%rip)      # 0xb1c4
cmpb $0x0, 0x6ad5(%rip)      # 0xb1c4
jne 0x42fa
movl -0x2c(%rbp), %ebx
subl 0x7472(%rip), %ebx      # 0xbb70
callq 0x29b7
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq