// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2a34
movq 0x8(%rbx), %rax
subq (%rbx), %rax
pushq $0xc
popq %rcx
cqto
idivq %rcx
xorl %r12d, %r12d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl %eax, %ecx
callq 0x4152
movq %rax, %r15
movq %rsp, %rdi
callq 0x2c54
leaq 0x1217(%rip), %r13      # 0x625c
leaq 0x60(%rsp), %r14
xorl %ebp, %ebp
cmpl $0x4, %ebp
je 0x51d3
movl %r12d, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43e5
testb %al, %al
jne 0x5113
incl %ebp
pushq $0x1
popq %rax
movl %eax, %r12d
jmp 0x504c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4b08
testb %al, %al
jne 0x518e
incl %ebp
pushq $0x3
popq %rax
movl %eax, %r12d
jmp 0x504c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4eb4
testb %al, %al
jne 0x5150
incl %ebp
xorl %r12d, %r12d
jmp 0x504c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4761
testb %al, %al
jne 0x50d2
incl %ebp
pushq $0x2
popq %rax
movl %eax, %r12d
jmp 0x504c
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2a34
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0xc
popq %rcx
idivq %rcx
leal 0x1(%rax), %edx
movq %r12, %rdi
movq %r15, %rsi
movl %eax, %ecx
callq 0x4152
movq %rax, %r15
movq %r12, %rdi
callq 0x2c54
pushq $0x1
jmp 0x51ca
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2a34
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0xc
popq %rcx
idivq %rcx
leal 0x1(%rax), %edx
movq %r14, %rdi
movq %r15, %rsi
movl %eax, %ecx
callq 0x4152
movq %rax, %r15
movq %r14, %rdi
callq 0x2c54
xorl %r12d, %r12d
jmp 0x504a
leaq 0x18(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2a34
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0xc
popq %rcx
idivq %rcx
leal 0x1(%rax), %edx
movq %r12, %rdi
movq %r15, %rsi
movl %eax, %ecx
callq 0x4152
movq %rax, %r15
movq %r12, %rdi
callq 0x2c54
pushq $0x3
jmp 0x51ca
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2a34
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0xc
popq %rcx
idivq %rcx
leal 0x1(%rax), %edx
movq %r12, %rdi
movq %r15, %rsi
movl %eax, %ecx
callq 0x4152
movq %rax, %r15
movq %r12, %rdi
callq 0x2c54
pushq $0x2
popq %rax
movl %eax, %r12d
jmp 0x504a
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0xc
popq %r14
idivq %r14
movq %r15, %rdi
movl %eax, %esi
callq 0x4314
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
idivq %r14
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x520a
movq %rax, %rbx
jmp 0x5219
jmp 0x5213
jmp 0x5213
movq %rax, %rbx
movq %r12, %r14
movq %r14, %rdi
callq 0x2c54
movq %rbx, %rdi
callq 0x2270