// File: xiangzejun[P]Optimizing_Implementations_of_Linear_Layers/reduce.cpp
// Function: reduce0(std::vector<xpair, std::allocator<xpair>>&, int**)
bool reduce0(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].src)
				continue;
			for(int k = j + 1; k < s; k++)
			{
				if((table[k][j + 1] == 0) && (table[j][k-1] == 0))
					break;
				if(seq[k].dst != seq[i].dst)
				{
					if (seq[k].dst != seq[j].dst)
						continue;
					else
					{
						if(seq[k].src != seq[i].dst)
							continue;
					}
				}
				else
				{
					if(seq[k].src != seq[j].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 = seq[k];
				tmp2.src = seq[i].src;
				tmp2.dst = seq[k].src;
				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:
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, 0x1a8(%rsp)
movq %rsi, 0x1a0(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x3280
movl %eax, 0x19c(%rsp)
movl $0x0, 0x194(%rsp)
movl 0x194(%rsp), %eax
cmpl 0x19c(%rsp), %eax
jge 0x9e15
movl 0x194(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x190(%rsp)
movl 0x190(%rsp), %eax
cmpl 0x19c(%rsp), %eax
jge 0x9dfd
movq 0x1a0(%rsp), %rax
movslq 0x194(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x190(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x9652
movq 0x1a0(%rsp), %rax
movslq 0x190(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x194(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x9652
jmp 0x9dfd
movq 0x1a8(%rsp), %rdi
movslq 0x194(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x54(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x190(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x54(%rsp), %eax
cmpl (%rcx), %eax
je 0x9692
jmp 0x9de7
movl 0x190(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18c(%rsp)
movl 0x18c(%rsp), %eax
cmpl 0x19c(%rsp), %eax
jge 0x9de5
movq 0x1a0(%rsp), %rax
movslq 0x18c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x190(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x970a
movq 0x1a0(%rsp), %rax
movslq 0x190(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x18c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x970a
jmp 0x9de5
movq 0x1a8(%rsp), %rdi
movslq 0x18c(%rsp), %rsi
callq 0x3430
movl 0x4(%rax), %eax
movl %eax, 0x50(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x194(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x50(%rsp), %eax
cmpl 0x4(%rcx), %eax
je 0x97d2
movq 0x1a8(%rsp), %rdi
movslq 0x18c(%rsp), %rsi
callq 0x3430
movl 0x4(%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x190(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x4c(%rsp), %eax
cmpl 0x4(%rcx), %eax
je 0x978d
jmp 0x9dcf
movq 0x1a8(%rsp), %rdi
movslq 0x18c(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x48(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x194(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x48(%rsp), %eax
cmpl 0x4(%rcx), %eax
je 0x97ce
jmp 0x9dcf
jmp 0x97d0
jmp 0x9815
movq 0x1a8(%rsp), %rdi
movslq 0x18c(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x44(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x190(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x44(%rsp), %eax
cmpl 0x4(%rcx), %eax
je 0x9813
jmp 0x9dcf
jmp 0x9815
movq 0x1a0(%rsp), %rax
movslq 0x194(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x190(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x9879
movq 0x1a0(%rsp), %rax
movslq 0x18c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x190(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x9879
movl 0x190(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x198(%rsp)
jmp 0x9b2c
movq 0x1a0(%rsp), %rax
movslq 0x190(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x194(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movb $0x0, 0x16f(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x43(%rsp)
je 0x9990
movq 0x1a0(%rsp), %rax
movslq 0x18c(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movl 0x190(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rdx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,4)
movb %al, 0x43(%rsp)
je 0x9990
movq 0x1a8(%rsp), %rsi
leaq 0x170(%rsp), %rdi
callq 0x3120
movb $0x1, 0x16f(%rsp)
movl 0x190(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x38(%rsp)
movl 0x194(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x18c(%rsp), %rsi
callq 0x3430
movl 0x38(%rsp), %esi
movl 0x3c(%rsp), %edx
movq (%rax), %rcx
movq %rcx, 0x160(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x168(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x150(%rsp)
movl 0x168(%rsp), %eax
movl %eax, 0x158(%rsp)
movq 0x150(%rsp), %rcx
leaq 0x170(%rsp), %rdi
movzbl 0x158(%rsp), %r8d
callq 0x9390
movb %al, 0x43(%rsp)
movb 0x43(%rsp), %al
movb %al, 0x37(%rsp)
testb $0x1, 0x16f(%rsp)
jne 0x99a4
jmp 0x99b1
leaq 0x170(%rsp), %rdi
callq 0x3220
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x99bb
jmp 0x99ce
movl 0x194(%rsp), %eax
movl %eax, 0x198(%rsp)
jmp 0x9b2a
movq 0x1a0(%rsp), %rax
movslq 0x194(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x190(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movb $0x0, 0x137(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x36(%rsp)
je 0x9ae5
movq 0x1a0(%rsp), %rax
movslq 0x190(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movl 0x18c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rdx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,4)
movb %al, 0x36(%rsp)
je 0x9ae5
movq 0x1a8(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0x3120
movb $0x1, 0x137(%rsp)
movl 0x190(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl 0x18c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x30(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x194(%rsp), %rsi
callq 0x3430
movl 0x2c(%rsp), %esi
movl 0x30(%rsp), %edx
movq (%rax), %rcx
movq %rcx, 0x128(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x130(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x118(%rsp)
movl 0x130(%rsp), %eax
movl %eax, 0x120(%rsp)
movq 0x118(%rsp), %rcx
leaq 0x138(%rsp), %rdi
movzbl 0x120(%rsp), %r8d
callq 0x9390
movb %al, 0x36(%rsp)
movb 0x36(%rsp), %al
movb %al, 0x2b(%rsp)
testb $0x1, 0x137(%rsp)
jne 0x9af9
jmp 0x9b06
leaq 0x138(%rsp), %rdi
callq 0x3220
movb 0x2b(%rsp), %al
testb $0x1, %al
jne 0x9b10
jmp 0x9b23
movl 0x18c(%rsp), %eax
subl $0x2, %eax
movl %eax, 0x198(%rsp)
jmp 0x9b28
jmp 0x9dcf
jmp 0x9b2a
jmp 0x9b2c
movq 0x1a8(%rsp), %rdi
movslq 0x18c(%rsp), %rsi
callq 0x3430
movq (%rax), %rcx
movq %rcx, 0x10c(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x114(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x194(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x100(%rsp)
movq 0x1a8(%rsp), %rdi
movslq 0x18c(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x104(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, (%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x6080
movq %rax, 0xe8(%rsp)
movslq 0x18c(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x6e80
movq %rax, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x6040
movq (%rsp), %rdi
movq 0xf8(%rsp), %rsi
callq 0xc830
movq %rax, 0xe0(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x6080
movq %rax, 0xc8(%rsp)
movslq 0x190(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x6e80
movq %rax, 0xd0(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x6040
movq 0x8(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0xc830
movq %rax, 0xc0(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x6080
movq %rax, 0xa8(%rsp)
movslq 0x194(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x6e80
movq %rax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x6040
movq 0x10(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0xc830
movq %rax, 0xa0(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x6080
movq %rax, 0x88(%rsp)
movslq 0x198(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x6e80
movq %rax, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x6040
movq 0x18(%rsp), %rdi
movq 0x98(%rsp), %rsi
leaq 0x10c(%rsp), %rdx
callq 0xc8a0
movq %rax, 0x80(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x6080
movq %rax, 0x60(%rsp)
movslq 0x198(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x6e80
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
movl $0x1, %esi
callq 0x6e80
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x6040
movq 0x20(%rsp), %rdi
movq 0x78(%rsp), %rsi
leaq 0x100(%rsp), %rdx
callq 0xc8a0
movq %rax, 0x58(%rsp)
movb $0x1, 0x1b7(%rsp)
jmp 0x9e1d
movl 0x18c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18c(%rsp)
jmp 0x96a3
jmp 0x9de7
movl 0x190(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x190(%rsp)
jmp 0x95eb
jmp 0x9dff
movl 0x194(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x194(%rsp)
jmp 0x95c6
movb $0x0, 0x1b7(%rsp)
movb 0x1b7(%rsp), %al
andb $0x1, %al
addq $0x1b8, %rsp            # imm = 0x1B8
retq
nop