// File: /workspace/github_cpp_makefile_star2_O1/xiangzejun[P]Optimizing_Implementations_of_Linear_Layers/reduce.cpp
// Function: reduce(std::vector<std::bitset<32ul>, std::allocator<std::bitset<32ul>>>)
vector<xpair> reduce(vector<ROW> m)
{

	vector<ROW> tmp_m(m);

	vector<xpair> seq = strgy3(m);
	int l = reduce_step(seq);


	int gap = l;
	int start = 0;

	thread_data data[THREAD_NUM];
	bool flag = true;
	while(flag)
	{
		for(int j = 0; j < THREAD_NUM; j++)
		{
			data[j].seq = seq;
			data[j].gap = gap;
			data[j].start = start;
			if((gap != 3) || (start != l - gap))
			{
				if(start == l - gap)
				{
					gap--;
					start = 0;
				}
				else
				{
					start++;
				}
			}
			else
			{
				flag = false;
			}
		}
		int rc;
		pthread_t threads[THREAD_NUM];
		pthread_attr_t attr;
		void* status;
		pthread_attr_init(&attr);
		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
		for(int j = 0; j < THREAD_NUM; j++)
		{

			rc = pthread_create(&threads[j], NULL, reduce_thread, (void *)(data + j));
			if(rc)
			{
				cout << "Error: unable to create thread!" << endl;
				exit(-1);
			}
		}
		// pthread_attr_destroy(&attr);
		for(int j = 0; j < THREAD_NUM; j++)
		{
			rc = pthread_join(threads[j], &status);
			if(rc)
			{
				cout << "Error: unable to join, " << rc << endl;
				exit(-1);
			}
		}
		for(int j = 0; j < THREAD_NUM; j++)
		{
			if(data[j].len < l)
			{
				seq = data[j].seq;
				l = data[j].len;
				gap = l;
				start = 0;
			}
		}
		// cout << "gap = " << gap << endl;
	}
	return seq;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2ea0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3d17
movq %rbx, %rdi
callq 0x61ca
movl %eax, %ebp
xorl %eax, %eax
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsp,%rax)
movq $0x0, 0x40(%rsp,%rax)
addq $0x28, %rax
cmpq $0xa0, %rax
jne 0x68e5
xorl %r15d, %r15d
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl %ebp, %r12d
leal -0x3(%r12), %r13d
xorl %r14d, %r14d
leaq (%rsp,%r14), %rdi
addq $0x30, %rdi
movq %rbx, %rsi
callq 0x6be6
movl %ebp, 0x48(%rsp,%r14)
movl %r15d, 0x4c(%rsp,%r14)
cmpl $0x3, %ebp
jne 0x6946
cmpl %r13d, %r15d
jne 0x6946
movl $0x0, 0xc(%rsp)
movl $0x3, %ebp
jmp 0x695a
movl %r12d, %eax
subl %ebp, %eax
cmpl %eax, %r15d
jne 0x6957
decl %ebp
xorl %r15d, %r15d
jmp 0x695a
incl %r15d
addq $0x28, %r14
cmpq $0xa0, %r14
jne 0x6913
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
callq 0x21b0
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
xorl %r14d, %r14d
leaq 0x30(%rsp), %r13
leaq (%rsp,%r14), %rdi
addq $0xd0, %rdi
xorl %esi, %esi
leaq -0x1f9(%rip), %rdx      # 0x67a4
movq %r13, %rcx
callq 0x2290
testl %eax, %eax
jne 0x6a74
addq $0x28, %r13
addq $0x8, %r14
cmpq $0x20, %r14
jne 0x6989
xorl %r14d, %r14d
movq 0xd0(%rsp,%r14,8), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2130
movl %eax, %r13d
testl %eax, %eax
jne 0x6a9a
incq %r14
cmpq $0x4, %r14
jne 0x69be
xorl %r14d, %r14d
cmpl %r12d, 0x50(%rsp,%r14)
jge 0x6a09
leaq (%rsp,%r14), %rsi
addq $0x30, %rsi
movq %rbx, %rdi
callq 0x6be6
movl 0x50(%rsp,%r14), %r12d
xorl %r15d, %r15d
movl %r12d, %ebp
addq $0x28, %r14
cmpq $0xa0, %r14
jne 0x69e7
testb $0x1, 0xc(%rsp)
jne 0x690b
movl $0x78, %r14d
movq 0x30(%rsp,%r14), %rdi
testq %rdi, %rdi
je 0x6a3e
movq 0x40(%rsp,%r14), %rsi
subq %rdi, %rsi
callq 0x2170
addq $-0x28, %r14
cmpq $-0x28, %r14
jne 0x6a27
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6a5f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x355d(%rip), %rdi      # 0x9fd8
leaq 0x8ba(%rip), %rsi       # 0x733c
movl $0x1f, %edx
callq 0x2180
movq 0x3545(%rip), %rdi      # 0x9fd8
callq 0x2090
jmp 0x6ac9
movq 0x3537(%rip), %rdi      # 0x9fd8
leaq 0x8b4(%rip), %rsi       # 0x735c
movl $0x17, %edx
callq 0x2180
movq 0x351f(%rip), %rdi      # 0x9fd8
movl %r13d, %esi
callq 0x2260
movq %rax, %rdi
callq 0x2090
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21a0
movq %rax, %r14
jmp 0x6b0f
movq %rax, %r14
jmp 0x6b23
jmp 0x6ae5
jmp 0x6ae5
jmp 0x6ae5
jmp 0x6ae5
movq %rax, %r14
movl $0x78, %r15d
movq 0x30(%rsp,%r15), %rdi
testq %rdi, %rdi
je 0x6b05
movq 0x40(%rsp,%r15), %rsi
subq %rdi, %rsi
callq 0x2170
addq $-0x28, %r15
cmpq $-0x28, %r15
jne 0x6aee
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x6b23
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6b3a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %r14, %rdi
callq 0x2270