// File: /workspace/github_cpp_makefile_star2_O2/btbujiangjun[P]abcdl/include/utils/ParallelOperator.h
// Function: abcdl::utils::ParallelOperator<int>::parallel_reduce_mul2one(int*, unsigned long*, int const*, unsigned long, std::function<void (int*, int const&, unsigned long*, unsigned long)> const&) const
void parallel_reduce_mul2one(T* result_value,
                                 size_t* result_idx,
                                 const T* op1,
                         		 const size_t num_op1,
                         		 const std::function<void(T*, const T&, size_t*, const size_t)> &f) const{
        size_t block_size = get_block_size(num_op1);
        size_t num_thread = get_num_thread(num_op1, block_size);
        std::vector<std::thread> threads(num_thread);
		T* data = new T[num_thread];
		size_t* indices = new size_t[num_thread];

        for(size_t i = 0; i != num_thread; i++){
            threads[i] = std::thread(
                [&op1, &result_value, &result_idx, &data, &indices, i, &f](size_t start_idx, size_t end_idx){
					for(size_t ti = start_idx; ti != end_idx; ti++){
            			if(ti == start_idx){
							data[i] = op1[ti];
                            indices[i] = ti;
						}else{
    						f(&data[i], op1[ti], &indices[i], ti);
                        }
                    }
					f(result_value, data[i], result_idx, indices[i]);
                }, i * block_size, std::min(num_op1, (i + 1) * block_size)
            );
        }

        for(auto& thread : threads){
            thread.join();
        }
		delete[] data;
        delete[] indices;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, 0x20(%rsp)
movq %r8, %r15
movq %rdi, %r12
movq %rsi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq %r8, 0x18(%rsp)
movq %r8, %rsi
callq 0xa05a
movq %rax, %r14
cmpq %rax, 0x8(%r12)
jae 0xb020
movq (%r12), %r15
jmp 0xb033
movq %r15, %rax
xorl %edx, %edx
divq %r14
movq %rax, %r15
cmpq $0x1, %rdx
sbbq $-0x1, %r15
leaq 0x38(%rsp), %rdi
leaq 0x68(%rsp), %rdx
movq %r15, %rsi
callq 0xa09c
movq %r15, %rax
shrq $0x3e, %rax
leaq (,%r15,4), %rcx
xorl %edi, %edi
negq %rax
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x9030
movq %rax, 0x10(%rsp)
movq %r15, %rax
shrq $0x3d, %rax
leaq (,%r15,8), %rcx
xorl %edi, %edi
negq %rax
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x9030
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0xb14b
leaq 0x50(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x10(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x8(%rsp), %rax
movq %rax, 0x88(%rsp)
movq %rbp, 0x90(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x98(%rsp)
movq %rbx, 0x30(%rsp)
addq %r14, %rbx
cmpq 0x18(%rsp), %rbx
movq %rbx, 0x28(%rsp)
leaq 0x18(%rsp), %rcx
leaq 0x28(%rsp), %rax
cmovbq %rax, %rcx
movq %r12, %rdi
leaq 0x68(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0xb1be
movq 0x38(%rsp), %rdi
addq %r13, %rdi
movq %r12, %rsi
callq 0xa174
movq %r12, %rdi
callq 0xa18e
addq $0x8, %r13
incq %rbp
jmp 0xb09f
movq 0x38(%rsp), %rbx
movq 0x40(%rsp), %r14
cmpq %r14, %rbx
je 0xb168
movq %rbx, %rdi
callq 0x95b0
addq $0x8, %rbx
jmp 0xb155
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xb177
callq 0x9420
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xb186
callq 0x9420
leaq 0x38(%rsp), %rdi
callq 0xa19c
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb1a8
jmp 0xb1a8
jmp 0xb1a8
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xa19c
movq %rbx, %rdi
callq 0x95e0
nop