// File: xiangzejun[P]Optimizing_Implementations_of_Linear_Layers/reduce.cpp
// Function: reduce_step(std::vector<xpair, std::allocator<xpair>>&)
int reduce_step(vector<xpair> &seq)
{
	int** tab = NULL;
	tab = get_table(seq, tab, 0, seq.size());
	int i = 0;
	int NUM = 4;
	int counter = 0;
	while(counter != NUM)
	{
		switch(i)
		{
			case 0:
			{
				if(reduce0(seq, tab))
				{
					// cout << "activate case 0"<<endl;
					tab = get_table(seq, tab, seq.size() + 1, seq.size());
					// i = 0;
					counter = 0;
				}
				else
				{
					i = (i + 1) % NUM;
					counter++;
				}
				break;
			}
			case 1:
			{
				if(reduce1(seq, tab))
				{
					// cout << "activate case 1" << endl;
					tab = get_table(seq, tab, seq.size() + 1, seq.size());
					// i = 1;
					counter = 0;
				}
				else
				{
					i = (i + 1) % NUM;
					counter++;
				}
				break;
			}
			case 2:
			{
				if(reduce2(seq, tab))
				{
					// cout << "activate case 2" <<endl;
					tab = get_table(seq, tab, seq.size() + 1, seq.size());
					counter = 0;
				}
				else
				{
					i = (i + 1) % NUM;
					counter++;
				}
				break;
			}
			case 3:
			{

				if(reduce3(seq, tab))
				{
					// cout << "activate case 3" << endl;
					tab = get_table(seq, tab, seq.size() + 1, seq.size());
					counter = 0;
				}
				else
				{
					// cout << "case 3" << endl;
					i = (i + 1) % NUM;
					counter++;
				}
			}
		}

	}
	delete_table(tab, seq.size());
	return seq.size();
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x140(%rsp)
movq $0x0, 0x138(%rsp)
movq 0x140(%rsp), %rsi
leaq 0x120(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x3120
movq 0x138(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %rsi
movl %eax, %ecx
xorl %edx, %edx
callq 0x8ef0
movq %rax, 0xa0(%rsp)
jmp 0xb668
movq 0xa0(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x3220
movl $0x0, 0x110(%rsp)
movl $0x4, 0x10c(%rsp)
movl $0x0, 0x108(%rsp)
movl 0x108(%rsp), %eax
cmpl 0x10c(%rsp), %eax
je 0xbb0a
movl 0x110(%rsp), %eax
movq %rax, 0x88(%rsp)
subq $0x3, %rax
ja 0xbb05
movq 0x88(%rsp), %rax
leaq 0x2b32(%rip), %rcx      # 0xe214
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x3220
jmp 0xbb43
movq 0x140(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0x9590
testb $0x1, %al
jne 0xb72f
jmp 0xb7e5
movq 0x140(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x3120
movq 0x138(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
incl %eax
movl %eax, 0x7c(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0x7c(%rsp), %edx
movl %eax, %ecx
callq 0x8ef0
movq %rax, 0x80(%rsp)
jmp 0xb795
movq 0x80(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x3220
movl $0x0, 0x108(%rsp)
jmp 0xb80f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x3220
jmp 0xbb43
movl 0x110(%rsp), %eax
addl $0x1, %eax
cltd
idivl 0x10c(%rsp)
movl %edx, 0x110(%rsp)
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0xbb05
movq 0x140(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0x9e30
testb $0x1, %al
jne 0xb832
jmp 0xb8e2
movq 0x140(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x3120
movq 0x138(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
incl %eax
movl %eax, 0x5c(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl 0x5c(%rsp), %edx
movl %eax, %ecx
callq 0x8ef0
movq %rax, 0x60(%rsp)
jmp 0xb895
movq 0x60(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x3220
movl $0x0, 0x108(%rsp)
jmp 0xb90c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x3220
jmp 0xbb43
movl 0x110(%rsp), %eax
addl $0x1, %eax
cltd
idivl 0x10c(%rsp)
movl %edx, 0x110(%rsp)
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0xbb05
movq 0x140(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0xa760
testb $0x1, %al
jne 0xb92f
jmp 0xb9df
movq 0x140(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x3120
movq 0x138(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
incl %eax
movl %eax, 0x3c(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl 0x3c(%rsp), %edx
movl %eax, %ecx
callq 0x8ef0
movq %rax, 0x40(%rsp)
jmp 0xb992
movq 0x40(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x3220
movl $0x0, 0x108(%rsp)
jmp 0xba09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x3220
jmp 0xbb43
movl 0x110(%rsp), %eax
addl $0x1, %eax
cltd
idivl 0x10c(%rsp)
movl %edx, 0x110(%rsp)
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0xbb05
movq 0x140(%rsp), %rdi
movq 0x138(%rsp), %rsi
callq 0xb110
testb $0x1, %al
jne 0xba2c
jmp 0xbad9
movq 0x140(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x3120
movq 0x138(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
incl %eax
movl %eax, 0x1c(%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x1c(%rsp), %edx
movl %eax, %ecx
callq 0x8ef0
movq %rax, 0x20(%rsp)
jmp 0xba8f
movq 0x20(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x3220
movl $0x0, 0x108(%rsp)
jmp 0xbb03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x3220
jmp 0xbb43
movl 0x110(%rsp), %eax
addl $0x1, %eax
cltd
idivl 0x10c(%rsp)
movl %edx, 0x110(%rsp)
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0xbb05
jmp 0xb6a6
movq 0x138(%rsp), %rax
movq %rax, (%rsp)
movq 0x140(%rsp), %rdi
callq 0x3280
movq (%rsp), %rdi
movl %eax, %esi
callq 0x9310
movq 0x140(%rsp), %rdi
callq 0x3280
addq $0x148, %rsp            # imm = 0x148
retq
movq 0x118(%rsp), %rdi
callq 0x22a0