// File: /workspace/github_cpp_makefile_star2_O2/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
andl $0x0, 0x6ed3(%rip)      # 0xab38
andl $0x0, 0x6ed0(%rip)      # 0xab3c
andl $0x0, 0x6ecd(%rip)      # 0xab40
andl $0x0, 0x6eca(%rip)      # 0xab44
andl $0x0, 0x6ec7(%rip)      # 0xab48
andl $0x0, 0x6ec4(%rip)      # 0xab4c
andl $0x0, 0x6ec1(%rip)      # 0xab50
andl $0x0, 0x6ebe(%rip)      # 0xab54
andl $0x0, 0x6ebb(%rip)      # 0xab58
andl $0x0, 0x6eb8(%rip)      # 0xab5c
andl $0x0, 0x6eb5(%rip)      # 0xab60
movl %edi, -0x2c(%rbp)
andl $0x0, 0x6eaf(%rip)      # 0xab64
movb $0x1, 0x64e0(%rip)      # 0xa19c
andl $0x0, 0x6ea5(%rip)      # 0xab68
xorl %eax, %eax
andl $0x0, 0x6ea0(%rip)      # 0xab6c
movb %al, 0x6ea2(%rip)       # 0xab74
andl $0x0, 0x6e97(%rip)      # 0xab70
movb %al, 0x6e96(%rip)       # 0xab75
movb $0x1, %al
leaq 0x6e68(%rip), %r15      # 0xab50
leaq 0x6eb9(%rip), %r12      # 0xaba8
leaq 0x6e2e(%rip), %r13      # 0xab24
testb $0x1, %al
je 0x403b
leaq 0x6f3b(%rip), %r14      # 0xac40
cmpq 0x6f44(%rip), %r14      # 0xac50
je 0x3fbd
xorl %eax, %eax
movb %al, 0x6e5a(%rip)       # 0xab74
movb %al, 0x6e55(%rip)       # 0xab75
movl %eax, 0x6e12(%rip)      # 0xab38
movslq %eax, %rbx
movq %r14, %rdi
callq 0x21e0
movq 0x28(%rax), %rcx
movq 0x30(%rax), %rax
subq %rcx, %rax
sarq $0x2, %rax
cmpq %rbx, %rax
jbe 0x3f9b
movl (%rcx,%rbx,4), %eax
movl %eax, 0x6dfe(%rip)      # 0xab50
movq %r14, %rdi
callq 0x21e0
movl 0x20(%rax), %eax
movl %eax, 0x6de1(%rip)      # 0xab44
movq %r12, %rdi
movq %r15, %rsi
callq 0x4fa0
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x3e0f
movq %r12, %rdi
movq %r15, %rsi
callq 0x4fa0
movq (%rax), %rax
movl 0x4(%rax), %eax
movl %eax, 0x6dc2(%rip)      # 0xab54
movq %r12, %rdi
movq %r15, %rsi
callq 0x4fa0
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x6db0(%rip)      # 0xab58
movl 0x6da6(%rip), %ecx      # 0xab54
cvtsi2ss %eax, %xmm0
cmpl $0x1, %ecx
jne 0x3de2
movss 0x6d39(%rip), %xmm1     # 0xaaf8
movaps %xmm1, %xmm2
subss %xmm0, %xmm2
addss 0x6d2e(%rip), %xmm1     # 0xaafc
divss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm0
ucomisd 0x322a(%rip), %xmm0     # 0x7008
jb 0x3e0f
jmp 0x3e1c
movss 0x6d12(%rip), %xmm1     # 0xaafc
movaps %xmm1, %xmm2
subss %xmm0, %xmm2
addss 0x6cff(%rip), %xmm1     # 0xaaf8
divss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm0
ucomisd 0x31ff(%rip), %xmm0     # 0x7008
jae 0x3ec1
movl 0x6d23(%rip), %eax      # 0xab38
incl %eax
jmp 0x3d20
movl 0x6d2e(%rip), %ecx      # 0xab50
movl %ecx, 0x6cfc(%rip)      # 0xab24
pushq $0x1
popq %rbx
movl %ebx, 0x6cfb(%rip)      # 0xab2c
movl %eax, 0x6cf1(%rip)      # 0xab28
movq %r12, %rdi
movq %r13, %rsi
callq 0x4fa0
movq (%rax), %rax
orl $-0x1, 0x4(%rax)
movq %r12, %rdi
movq %r13, %rsi
callq 0x4fa0
movq (%rax), %rax
movl %ebx, 0x8(%rax)
movss 0x6c96(%rip), %xmm0     # 0xaaf8
cvtsi2ssl 0x6cbe(%rip), %xmm1 # 0xab28
subss %xmm1, %xmm0
movss %xmm0, 0x6c82(%rip)     # 0xaaf8
addss 0x6c7e(%rip), %xmm1     # 0xaafc
movss %xmm1, 0x6c76(%rip)     # 0xaafc
leaq 0x6e23(%rip), %rdi      # 0xacb0
movq %r13, %rsi
callq 0x505c
movl 0x6ca9(%rip), %eax      # 0xab44
addl 0x6cab(%rip), %eax      # 0xab4c
movl %eax, 0x6ca5(%rip)      # 0xab4c
movl 0x6cc3(%rip), %ecx      # 0xab70
incl %ecx
movl %ecx, 0x6cbb(%rip)      # 0xab70
leaq 0x6cb8(%rip), %rdx      # 0xab74
jmp 0x3f64
movl 0x6c89(%rip), %edx      # 0xab50
movl %edx, 0x6c57(%rip)      # 0xab24
movl %ecx, 0x6c59(%rip)      # 0xab2c
movl %eax, 0x6c4f(%rip)      # 0xab28
movq %r12, %rdi
movq %r13, %rsi
callq 0x4fa0
movq (%rax), %rax
pushq $0x1
popq %rbx
movl %ebx, 0x4(%rax)
movq %r12, %rdi
movq %r13, %rsi
callq 0x4fa0
movq (%rax), %rax
movl %ebx, 0x8(%rax)
cvtsi2ssl 0x6c22(%rip), %xmm0 # 0xab28
movss 0x6bea(%rip), %xmm1     # 0xaaf8
addss %xmm0, %xmm1
movss %xmm1, 0x6bde(%rip)     # 0xaaf8
movss 0x6bda(%rip), %xmm1     # 0xaafc
subss %xmm0, %xmm1
movss %xmm1, 0x6bce(%rip)     # 0xaafc
leaq 0x6d7b(%rip), %rdi      # 0xacb0
movq %r13, %rsi
callq 0x505c
movl 0x6c01(%rip), %eax      # 0xab44
addl 0x6c03(%rip), %eax      # 0xab4c
movl %eax, 0x6bfd(%rip)      # 0xab4c
movl 0x6c1b(%rip), %ecx      # 0xab70
incl %ecx
movl %ecx, 0x6c13(%rip)      # 0xab70
leaq 0x6c11(%rip), %rdx      # 0xab75
cmpl %eax, 0x6bde(%rip)      # 0xab48
jge 0x3f98
movl %eax, 0x6bd6(%rip)      # 0xab48
movl %ecx, 0x6bf4(%rip)      # 0xab6c
movss 0x6b78(%rip), %xmm0     # 0xaaf8
movss %xmm0, 0x6b78(%rip)     # 0xab00
movss 0x6b6c(%rip), %xmm0     # 0xaafc
movss %xmm0, 0x6b6c(%rip)     # 0xab04
movb $0x1, (%rdx)
cmpb $0x0, 0x6bd2(%rip)      # 0xab74
jne 0x3fbd
cmpb $0x0, 0x6bca(%rip)      # 0xab75
jne 0x3fbd
movq %r14, %rdi
callq 0x21e0
movq %rax, %r14
jmp 0x3d05
callq 0x3a8b
callq 0x2cdb
cmpq $0x0, 0x6c91(%rip)      # 0xac60
je 0x402d
movq 0x6c78(%rip), %rsi      # 0xac50
addq $0x20, %rsi
leaq 0x6c55(%rip), %rbx      # 0xac38
movq %rbx, %rdi
callq 0x4fa0
movq %rax, %r14
movq 0x6c5b(%rip), %rsi      # 0xac50
addq $0x20, %rsi
movq %rbx, %rdi
callq 0x4fa0
movq 0x8(%rax), %rdx
subq (%rax), %rdx
movq (%r14), %rsi
movl 0x6b3f(%rip), %ecx      # 0xab50
movb 0x6185(%rip), %al       # 0xa19c
cmpl %ecx, -0x4(%rsi,%rdx)
jne 0x3cf6
cmpl 0x6afd(%rip), %ecx      # 0xab24
je 0x3cf6
movb $0x0, 0x6168(%rip)      # 0xa19c
xorl %eax, %eax
jmp 0x3cf6
movl -0x2c(%rbp), %ebx
subl 0x6b04(%rip), %ebx      # 0xab48
callq 0x290b
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq