// File: /workspace/github_cpp_makefile_star2_O2/xiangzejun[P]Optimizing_Implementations_of_Linear_Layers/reduce.cpp
// Function: reduce1(std::vector<xpair, std::allocator<xpair>>&, int**)
bool reduce1(vector<xpair> &seq, int** table)
{
	int s = seq.size();
	int index;

	for(int i = 0; i < s; i++)
	{
		for(int j = i + 1; j < s; j++)
		{
			if((table[i][j - 1] == 0) && (table[j][i + 1] == 0))
				break;
			if((seq[i].src != seq[j].dst) && (seq[i].dst != seq[j].dst))
				continue;
			for(int k = j + 1; k < s; k++)
			{
				if((table[k][j + 1] == 0) && (table[j][k-1] == 0))
					break;
				if(seq[k].src != seq[j].src)
					continue;
				else
				{
					if(seq[j].dst == seq[i].dst)
					{
						if(seq[k].dst != seq[i].src)
							continue;
					}
					if(seq[j].dst == seq[i].src)
					{
						if(seq[k].dst != seq[i].dst)
							continue;
					}
				}
				if((table[i][j - 1]) && table[k][j + 1])
					index = j - 1;//fixpoint = j;
				else if(table[j][i + 1] && table[k][j + 1] && exchange_set(seq, j - 1, i + 1, seq[k]))
					index = i; //fixpoint = i;
				else if(table[i][j - 1] && table[j][k - 1] && exchange_set(seq, j + 1, k - 1, seq[i]))
					index = k - 2; //fixpoint = k;
				else
					continue;
				xpair tmp1, tmp2;
				tmp1.src = seq[j].src;
				tmp1.dst = seq[i].src;
				tmp2 = seq[i];
				seq.erase(seq.begin() + k);
				seq.erase(seq.begin() + j);
				seq.erase(seq.begin() + i);
				seq.insert(seq.begin() + index, tmp1);
				seq.insert(seq.begin() + index + 1, tmp2);
				return true;
			}
		}
	}
	return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %r13
movq 0x8(%rdi), %rax
subq (%rdi), %rax
pushq $0xc
popq %rcx
cqto
idivq %rcx
movslq %eax, %r8
xorl %r9d, %r9d
testl %r8d, %r8d
movl $0x0, %eax
cmovgl %r8d, %eax
pushq $0x2
popq %rcx
movl %ecx, 0x8(%rsp)
pushq $0x1
popq %rcx
movq %rdi, 0x28(%rsp)
movq %r8, 0x30(%rsp)
movq %rsi, 0x40(%rsp)
movq %rax, 0x60(%rsp)
cmpq %rax, %r9
je 0x4af0
movslq %ecx, %r14
leaq 0x1(%r9), %rax
movq %rax, 0x10(%rsp)
imulq $0xc, %r9, %r11
movq %rcx, 0x68(%rsp)
movq %rcx, 0x48(%rsp)
movl 0x8(%rsp), %edx
movq %r9, 0x18(%rsp)
movq %r11, 0x20(%rsp)
cmpq %r8, %r14
jge 0x4a18
movq (%rsi,%r9,8), %rax
cmpl $0x0, -0x4(%rax,%r14,4)
jne 0x480d
movq (%rsi,%r14,8), %rax
movq 0x10(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x4a18
movq (%r13), %rax
imulq $0xc, %r14, %r12
movl 0x4(%rax,%r12), %ecx
cmpl %ecx, (%rax,%r11)
je 0x482c
addq %r11, %rax
cmpl %ecx, 0x4(%rax)
jne 0x49ff
movl %edx, 0xc(%rsp)
movslq %edx, %rax
imulq $0xc, %rax, %rbp
leaq -0x4(,%rax,4), %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x58(%rsp)
leaq (%rsi,%rax,8), %rax
movq %rax, 0x70(%rsp)
leaq -0x1(%r14), %rbx
leaq 0x1(%r14), %rax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
movq 0x58(%rsp), %rax
addq %r15, %rax
cmpq %r8, %rax
jge 0x49f9
movq 0x70(%rsp), %rax
movq (%rax,%r15,8), %rax
movl 0x4(%rax,%r14,4), %eax
testl %eax, %eax
jne 0x4899
movq (%rsi,%r14,8), %rcx
addq 0x50(%rsp), %rcx
cmpl $0x0, (%rcx,%r15,4)
je 0x49f9
movq (%r13), %rcx
movl (%rcx,%rbp), %edx
cmpl (%rcx,%r12), %edx
jne 0x496b
leaq (%rcx,%r12), %rdx
movl 0x4(%rdx), %r10d
movl (%rcx,%r11), %edi
movl 0x4(%rcx,%r11), %edx
cmpl %edx, %r10d
jne 0x48ca
cmpl %edi, 0x4(%rcx,%rbp)
jne 0x496b
cmpl %edi, %r10d
jne 0x48d9
cmpl %edx, 0x4(%rcx,%rbp)
jne 0x496b
movq (%rsi,%r9,8), %rcx
cmpl $0x0, -0x4(%rcx,%r14,4)
je 0x4977
testl %eax, %eax
jne 0x4a33
movq (%rsi,%r14,8), %rax
addq 0x50(%rsp), %rax
cmpl $0x0, (%rax,%r15,4)
je 0x496b
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x2a34
movq (%r13), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx), %rcx
movq 0x48(%rsp), %rax
leal (%rax,%r15), %edx
leaq 0x88(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x4353
movl %eax, %r13d
leaq 0x88(%rsp), %rdi
callq 0x2c54
movq 0x20(%rsp), %r11
movq 0x40(%rsp), %rsi
movq 0x18(%rsp), %r9
movq 0x30(%rsp), %r8
testb %r13b, %r13b
movq 0x28(%rsp), %r13
jne 0x4a38
addq $0xc, %rbp
incq %r15
jmp 0x4862
testl %eax, %eax
je 0x496b
movq (%rsi,%r14,8), %rax
movq 0x10(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x496b
leaq 0xa0(%rsp), %rdi
movq %r13, %rsi
callq 0x2a34
movq (%r13), %rax
movq (%rax,%rbp), %rcx
leaq 0xa0(%rsp), %rdi
movl %ebx, %esi
movq 0x10(%rsp), %rdx
callq 0x4353
movl %eax, %r13d
leaq 0xa0(%rsp), %rdi
callq 0x2c54
testb %r13b, %r13b
jne 0x4a47
movq 0x18(%rsp), %r9
movq 0x40(%rsp), %rsi
movq (%rsi,%r9,8), %rax
cmpl $0x0, -0x4(%rax,%r14,4)
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %r8
movq 0x20(%rsp), %r11
jne 0x48f1
jmp 0x496b
movl 0xc(%rsp), %edx
jmp 0x4a07
incq %r14
movq %r14, 0x38(%rsp)
incl %edx
incq 0x48(%rsp)
movq 0x38(%rsp), %r14
jmp 0x47e5
incl 0x8(%rsp)
movq 0x68(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %r9
movq 0x60(%rsp), %rax
jmp 0x47b4
movq %rbx, %r14
jmp 0x4a56
movq 0x58(%rsp), %rax
leaq (%rax,%r15), %r14
addq $-0x2, %r14
jmp 0x4a56
movq 0x18(%rsp), %r14
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %r11
movq (%r13), %rax
movl (%rax,%r12), %ecx
movq %r13, %r15
leaq 0xbc(%rsp), %r13
movl %ecx, (%r13)
movl (%rax,%r11), %ecx
movl %ecx, 0x4(%r13)
movq (%rax,%r11), %rcx
leaq 0x78(%rsp), %rdx
movq %rcx, (%rdx)
movl 0x8(%rax,%r11), %ecx
movl %ecx, 0x8(%rdx)
addq %rax, %rbp
movq %r15, %rdi
movq %rbp, %rsi
movq %r11, %rbx
callq 0x5760
addq (%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5760
addq (%r15), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x5760
movslq %r14d, %rax
imulq $0xc, %rax, %rbx
movq (%r15), %rsi
addq %rbx, %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x579a
movq (%r15), %rax
leaq (%rax,%rbx), %rsi
addq $0xc, %rsi
movq %r15, %rdi
leaq 0x78(%rsp), %rdx
callq 0x579a
movq 0x30(%rsp), %r8
movq 0x18(%rsp), %r9
cmpq %r8, %r9
setl %al
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq