// File: /workspace/github_c_makefile_star2_O3/USArmyResearchLab[P]ARL_OpenSHMEM/src/autogen/shmem_int_sum_to_all.c
// Function: shmem_int_sum_to_all
void shmem_int_sum_to_all( int* dst, const int* src, int nreduce,
	int pe_start, int log_pe_stride, int pe_size, int* pwork, long* psync)
{
	debug("shmem_x_op_to_all begin");

	int pe_size_stride = pe_size << log_pe_stride;
	int pe_step = 0x1 << log_pe_stride;
	int pe_end = pe_size_stride + pe_start;
	int nreduced2p1 = (nreduce >> 1) + 1;

	int nwrk = (nreduced2p1 > (int)SHMEM_REDUCE_MIN_WRKDATA_SIZE) ?
		 nreduced2p1 : (int)SHMEM_REDUCE_MIN_WRKDATA_SIZE;

	int i, j, r;

	for (i = 0; i < nreduce; i++) {
		dst[i] = src[i];
	}

	int to = __shmem.my_pe;

	for(r = 1; r < pe_size; r++) {

		to += pe_step;
		if (to >= pe_end) to -= pe_size_stride;

		int* remote_work = (int*)shmem_ptr((void*)pwork, to);

		for(i = 0; i < nreduce; i += nwrk) {

			int nrem = nreduce - i;
			nrem = (nrem > nwrk) ? nwrk : nrem;

			for(j = 0; j < nrem; j++) {
				remote_work[j] = src[i+j];
			}

			shmem_barrier(pe_start, log_pe_stride, pe_size, psync);

			for(j = 0; j < nrem; j++) {
				dst[i+j] = __sum(dst[i+j],pwork[j]);
			}

			shmem_barrier(pe_start, log_pe_stride, pe_size, psync);

		}
	}

	debug("shmem_x_op_to_all end");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x10(%rsp)
movl %r9d, 0x4(%rsp)
movl %r9d, %eax
movl %r8d, %ecx
shll %cl, %eax
movq %rax, 0x28(%rsp)
movl $0x1, %eax
movl %r8d, 0xc(%rsp)
shll %cl, %eax
movl %eax, 0x1c(%rsp)
movl %edx, %ecx
sarl %ecx
cmpl $0x8, %ecx
movl $0x7, %eax
cmovgel %ecx, %eax
movl %edx, 0x8(%rsp)
testl %edx, %edx
jle 0x3182
movl 0x8(%rsp), %ecx
xorl %edx, %edx
movl (%rsi,%rdx,4), %r8d
movl %r8d, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x3172
movq %rdi, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
cmpl $0x2, 0x4(%rsp)
jl 0x32f5
movq 0x90(%rsp), %r13
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rdx
addl %edx, %ecx
movl %ecx, 0x18(%rsp)
leal 0x1(%rax), %r12d
leaq 0x3046(%rip), %rcx      # 0x6200
movl 0x4(%rcx), %esi
movslq 0x8(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movl %eax, %eax
leaq 0x4(,%rax,4), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %eax
movq %r12, 0x50(%rsp)
movl %eax, 0x20(%rsp)
addl 0x1c(%rsp), %esi
cmpl 0x18(%rsp), %esi
movq 0x28(%rsp), %rax
movl $0x0, %ecx
cmovll %ecx, %eax
subl %eax, %esi
movq %r13, %rdi
movl %esi, 0x24(%rsp)
callq 0x1d38
cmpl $0x0, 0x8(%rsp)
jle 0x32e1
movq %rax, %r15
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rbx
xorl %ebp, %ebp
movq 0x48(%rsp), %r13
subq %rbp, %r13
cmpl %r12d, %r13d
movl %r12d, %eax
cmovll %r13d, %eax
testq %r13, %r13
jle 0x3288
movslq %eax, %r12
xorl %eax, %eax
movl (%rbx,%rax,4), %ecx
movl %ecx, (%r15,%rax,4)
incq %rax
cmpq %r12, %rax
jl 0x323d
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %esi
movl 0x4(%rsp), %edx
movq 0x98(%rsp), %rcx
callq 0x332c
testq %r13, %r13
movq 0x90(%rsp), %r13
jle 0x32aa
xorl %eax, %eax
movl (%r13,%rax,4), %ecx
addl %ecx, (%r14,%rax,4)
incq %rax
cmpq %r12, %rax
jl 0x3275
jmp 0x32aa
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %esi
movl 0x4(%rsp), %edx
movq 0x98(%rsp), %rcx
callq 0x332c
movq 0x90(%rsp), %r13
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %esi
movl 0x4(%rsp), %edx
movq 0x98(%rsp), %rcx
callq 0x332c
movq 0x50(%rsp), %r12
addq %r12, %rbp
movq 0x40(%rsp), %rax
addq %rax, %rbx
addq %rax, %r14
cmpl 0x8(%rsp), %ebp
jl 0x3221
movl 0x20(%rsp), %eax
incl %eax
cmpl 0x4(%rsp), %eax
movl 0x24(%rsp), %esi
jne 0x31e0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq