// File: xiangzejun[P]Optimizing_Implementations_of_Linear_Layers/strategy.cpp
// Function: select_oper(std::vector<std::bitset<32ul>, std::allocator<std::bitset<32ul>>>, std::vector<xpair, std::allocator<xpair>>&, int, int)
int select_oper(vector<ROW> m, vector<xpair> &max_seq, int no_reduced, int opr_type)
{
	int no_before = 0;
	int no_after = 0;
	xpair new_ele;

	for (int i = 0; i < m.size(); i++)
	{
		vector<ROW> tmp_m(m);
		for (int j = 0; j < m.size(); j++)
		{
			if (i != j)
			{
				no_before = tmp_m[j].count();
				tmp_m[j] ^= tmp_m[i];
				no_after = tmp_m[j].count();
				if((no_before - no_after) > 0)
				{
					if (no_reduced < (no_before - no_after))
					{
						no_reduced = no_before - no_after;
						max_seq.clear();
						new_ele.src = i;
						new_ele.dst = j;
						if(opr_type == 0)
						{
							new_ele.flag = false;
						}
						else if(opr_type == 1)
						{
							new_ele.flag = true;
						}
						max_seq.push_back(new_ele);
					}

					else if (no_reduced == (no_before - no_after))
					{
						new_ele.src = i;
						new_ele.dst = j;
						if(opr_type == 0)
						{
							new_ele.flag = false;
						}
						else if(opr_type == 1)
						{
							new_ele.flag = true;
						}
						max_seq.push_back(new_ele);
					}
				}
			}
		}
	}
    return no_reduced;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x20(%rsp)
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl %edx, 0x74(%rsp)
movl %ecx, 0x70(%rsp)
movl $0x0, 0x6c(%rsp)
movl $0x0, 0x68(%rsp)
movl $0x0, 0x58(%rsp)
movq 0x20(%rsp), %rdi
movslq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
callq 0x32a0
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x5ce2
movq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x2fc0
movl $0x0, 0x3c(%rsp)
movq 0x20(%rsp), %rdi
movslq 0x3c(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0x32a0
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x5cc8
movl 0x58(%rsp), %eax
cmpl 0x3c(%rsp), %eax
je 0x5cb6
movslq 0x3c(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x33d0
movq %rax, %rdi
callq 0x60b0
movl %eax, 0x6c(%rsp)
movslq 0x58(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x33d0
movq %rax, 0x8(%rsp)
movslq 0x3c(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x33d0
movq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x3450
movslq 0x3c(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x33d0
movq %rax, %rdi
callq 0x60b0
movl %eax, 0x68(%rsp)
movl 0x6c(%rsp), %eax
subl 0x68(%rsp), %eax
cmpl $0x0, %eax
jle 0x5cb4
movl 0x74(%rsp), %eax
movl 0x6c(%rsp), %ecx
subl 0x68(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5c61
movl 0x6c(%rsp), %eax
subl 0x68(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x78(%rsp), %rdi
callq 0x5e60
movl 0x58(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x60(%rsp)
cmpl $0x0, 0x70(%rsp)
jne 0x5c23
movb $0x0, 0x64(%rsp)
jmp 0x5c31
cmpl $0x1, 0x70(%rsp)
jne 0x5c2f
movb $0x1, 0x64(%rsp)
jmp 0x5c31
movq 0x78(%rsp), %rdi
leaq 0x5c(%rsp), %rsi
callq 0x5de0
jmp 0x5c42
jmp 0x5cb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x30c0
jmp 0x5cee
movl 0x74(%rsp), %eax
movl 0x6c(%rsp), %ecx
subl 0x68(%rsp), %ecx
cmpl %ecx, %eax
jne 0x5cb0
movl 0x58(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x60(%rsp)
cmpl $0x0, 0x70(%rsp)
jne 0x5c8f
movb $0x0, 0x64(%rsp)
jmp 0x5c9d
cmpl $0x1, 0x70(%rsp)
jne 0x5c9b
movb $0x1, 0x64(%rsp)
jmp 0x5c9d
movq 0x78(%rsp), %rdi
leaq 0x5c(%rsp), %rsi
callq 0x5de0
jmp 0x5cae
jmp 0x5cb0
jmp 0x5cb2
jmp 0x5cb4
jmp 0x5cb6
jmp 0x5cb8
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x5b35
leaq 0x40(%rsp), %rdi
callq 0x30c0
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x5af9
movl 0x74(%rsp), %eax
addq $0x88, %rsp
retq
movq 0x30(%rsp), %rdi
callq 0x22a0
nopl (%rax,%rax)