// File: 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:
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, 0x1b8(%rsp)
movq %rsi, 0x1b0(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x3280
movl %eax, 0x1ac(%rsp)
movl $0x0, 0x1a4(%rsp)
movl 0x1a4(%rsp), %eax
cmpl 0x1ac(%rsp), %eax
jge 0xa738
movl 0x1a4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a0(%rsp)
movl 0x1a0(%rsp), %eax
cmpl 0x1ac(%rsp), %eax
jge 0xa720
movq 0x1b0(%rsp), %rax
movslq 0x1a4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1a0(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x9ef2
movq 0x1b0(%rsp), %rax
movslq 0x1a0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1a4(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x9ef2
jmp 0xa720
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x64(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a0(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x64(%rsp), %eax
cmpl 0x4(%rcx), %eax
je 0x9f70
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movl 0x4(%rax), %eax
movl %eax, 0x60(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a0(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x60(%rsp), %eax
cmpl 0x4(%rcx), %eax
je 0x9f70
jmp 0xa70a
movl 0x1a0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
movl 0x19c(%rsp), %eax
cmpl 0x1ac(%rsp), %eax
jge 0xa708
movq 0x1b0(%rsp), %rax
movslq 0x19c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1a0(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x9fe8
movq 0x1b0(%rsp), %rax
movslq 0x1a0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x19c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x9fe8
jmp 0xa708
movq 0x1b8(%rsp), %rdi
movslq 0x19c(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x5c(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a0(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x5c(%rsp), %eax
cmpl (%rcx), %eax
je 0xa028
jmp 0xa6f2
movq 0x1b8(%rsp), %rdi
movslq 0x1a0(%rsp), %rsi
callq 0x3430
movl 0x4(%rax), %eax
movl %eax, 0x58(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x58(%rsp), %eax
cmpl 0x4(%rcx), %eax
jne 0xa0a8
movq 0x1b8(%rsp), %rdi
movslq 0x19c(%rsp), %rsi
callq 0x3430
movl 0x4(%rax), %eax
movl %eax, 0x54(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x54(%rsp), %eax
cmpl (%rcx), %eax
je 0xa0a6
jmp 0xa6f2
jmp 0xa0a8
movq 0x1b8(%rsp), %rdi
movslq 0x1a0(%rsp), %rsi
callq 0x3430
movl 0x4(%rax), %eax
movl %eax, 0x50(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x50(%rsp), %eax
cmpl (%rcx), %eax
jne 0xa128
movq 0x1b8(%rsp), %rdi
movslq 0x19c(%rsp), %rsi
callq 0x3430
movl 0x4(%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movq %rax, %rcx
movl 0x4c(%rsp), %eax
cmpl 0x4(%rcx), %eax
je 0xa126
jmp 0xa6f2
jmp 0xa128
jmp 0xa12a
movq 0x1b0(%rsp), %rax
movslq 0x1a4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1a0(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0xa18e
movq 0x1b0(%rsp), %rax
movslq 0x19c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1a0(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0xa18e
movl 0x1a0(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x1a8(%rsp)
jmp 0xa441
movq 0x1b0(%rsp), %rax
movslq 0x1a0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1a4(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movb $0x0, 0x17f(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x4b(%rsp)
je 0xa2a5
movq 0x1b0(%rsp), %rax
movslq 0x19c(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movl 0x1a0(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rdx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,4)
movb %al, 0x4b(%rsp)
je 0xa2a5
movq 0x1b8(%rsp), %rsi
leaq 0x180(%rsp), %rdi
callq 0x3120
movb $0x1, 0x17f(%rsp)
movl 0x1a0(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x40(%rsp)
movl 0x1a4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x19c(%rsp), %rsi
callq 0x3430
movl 0x40(%rsp), %esi
movl 0x44(%rsp), %edx
movq (%rax), %rcx
movq %rcx, 0x170(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x178(%rsp)
movq 0x170(%rsp), %rax
movq %rax, 0x160(%rsp)
movl 0x178(%rsp), %eax
movl %eax, 0x168(%rsp)
movq 0x160(%rsp), %rcx
leaq 0x180(%rsp), %rdi
movzbl 0x168(%rsp), %r8d
callq 0x9390
movb %al, 0x4b(%rsp)
movb 0x4b(%rsp), %al
movb %al, 0x3f(%rsp)
testb $0x1, 0x17f(%rsp)
jne 0xa2b9
jmp 0xa2c6
leaq 0x180(%rsp), %rdi
callq 0x3220
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0xa2d0
jmp 0xa2e3
movl 0x1a4(%rsp), %eax
movl %eax, 0x1a8(%rsp)
jmp 0xa43f
movq 0x1b0(%rsp), %rax
movslq 0x1a4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1a0(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movb $0x0, 0x147(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x3e(%rsp)
je 0xa3fa
movq 0x1b0(%rsp), %rax
movslq 0x1a0(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movl 0x19c(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rdx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,4)
movb %al, 0x3e(%rsp)
je 0xa3fa
movq 0x1b8(%rsp), %rsi
leaq 0x148(%rsp), %rdi
callq 0x3120
movb $0x1, 0x147(%rsp)
movl 0x1a0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
movl 0x19c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x38(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movl 0x34(%rsp), %esi
movl 0x38(%rsp), %edx
movq (%rax), %rcx
movq %rcx, 0x138(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x140(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x128(%rsp)
movl 0x140(%rsp), %eax
movl %eax, 0x130(%rsp)
movq 0x128(%rsp), %rcx
leaq 0x148(%rsp), %rdi
movzbl 0x130(%rsp), %r8d
callq 0x9390
movb %al, 0x3e(%rsp)
movb 0x3e(%rsp), %al
movb %al, 0x33(%rsp)
testb $0x1, 0x147(%rsp)
jne 0xa40e
jmp 0xa41b
leaq 0x148(%rsp), %rdi
callq 0x3220
movb 0x33(%rsp), %al
testb $0x1, %al
jne 0xa425
jmp 0xa438
movl 0x19c(%rsp), %eax
subl $0x2, %eax
movl %eax, 0x1a8(%rsp)
jmp 0xa43d
jmp 0xa6f2
jmp 0xa43f
jmp 0xa441
movq 0x1b8(%rsp), %rdi
movslq 0x1a0(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x11c(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movl (%rax), %eax
movl %eax, 0x120(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x1a4(%rsp), %rsi
callq 0x3430
movq (%rax), %rcx
movq %rcx, 0x110(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x118(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x6080
movq %rax, 0xf8(%rsp)
movslq 0x19c(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x6e80
movq %rax, 0x100(%rsp)
leaq 0x108(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x6040
movq 0x8(%rsp), %rdi
movq 0x108(%rsp), %rsi
callq 0xc830
movq %rax, 0xf0(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x6080
movq %rax, 0xd8(%rsp)
movslq 0x1a0(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x6e80
movq %rax, 0xe0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x6040
movq 0x10(%rsp), %rdi
movq 0xe8(%rsp), %rsi
callq 0xc830
movq %rax, 0xd0(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x6080
movq %rax, 0xb8(%rsp)
movslq 0x1a4(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x6e80
movq %rax, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x6040
movq 0x18(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0xc830
movq %rax, 0xb0(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x6080
movq %rax, 0x98(%rsp)
movslq 0x1a8(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x6e80
movq %rax, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x6040
movq 0x20(%rsp), %rdi
movq 0xa8(%rsp), %rsi
leaq 0x11c(%rsp), %rdx
callq 0xc8a0
movq %rax, 0x90(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x6080
movq %rax, 0x70(%rsp)
movslq 0x1a8(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x6e80
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x6e80
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x6040
movq 0x28(%rsp), %rdi
movq 0x88(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0xc8a0
movq %rax, 0x68(%rsp)
movb $0x1, 0x1c7(%rsp)
jmp 0xa740
movl 0x19c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
jmp 0x9f81
jmp 0xa70a
movl 0x1a0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a0(%rsp)
jmp 0x9e8b
jmp 0xa722
movl 0x1a4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a4(%rsp)
jmp 0x9e66
movb $0x0, 0x1c7(%rsp)
movb 0x1c7(%rsp), %al
andb $0x1, %al
addq $0x1c8, %rsp            # imm = 0x1C8
retq
nopw %cs:(%rax,%rax)