// File: /workspace/github_c_makefile_star2_O0/USArmyResearchLab[P]ARL_OpenSHMEM/src/autogen/shmem_collect32.c
// Function: shmem_collect32
void shmem_collect32(void *dest, const void *source, size_t nelems, 
	int pe_start, int log_pe_stride, int pe_size, long* psync)
{
	int pe = __shmem.my_pe;
	int pe_step = 0x1 << log_pe_stride;
	int pe_end = pe_start + pe_step * (pe_size - 1);
	int my_offset = 0;
	int inelems = (int)nelems;

	/* We know the value here is 0 and we can use it and reset it before
	 * it is needed in the barrier */

	volatile long* offset = psync + SHMEM_COLLECT_SYNC_SIZE - 1;

	int* neighbor_offset = (int*)shmem_ptr((void*)offset, pe + pe_step);

	if (__builtin_expect((pe == pe_start),0)) {

		*neighbor_offset = my_offset + inelems;

	} else {

		/// spin until neighbor sets offset 
		while (!(my_offset = *offset));

		*offset = SHMEM_SYNC_VALUE;

		if (__builtin_expect((pe != pe_end),1))
			*neighbor_offset = my_offset + inelems;
	}

	int i, j;
	for (i = pe_start; i <= pe_end; i += pe_step) {
		int32_t* dst = (int32_t*)shmem_ptr((void*)dest, i) + my_offset;
		for (j = 0; j < inelems; j++) dst[j] = ((int32_t*)source)[j];
	}

	shmem_barrier(pe_start, log_pe_stride, pe_size, psync);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
leaq 0x2ed6(%rip), %rax      # 0x71e0
movl 0x4(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x2c(%rbp), %ecx
movl -0x24(%rbp), %edx
subl $0x1, %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
movl %eax, -0x38(%rbp)
movq 0x10(%rbp), %rax
addq $0x40, %rax
addq $-0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl -0x28(%rbp), %esi
addl -0x2c(%rbp), %esi
callq 0x2110
movq %rax, -0x48(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x4386
movl -0x34(%rbp), %ecx
addl -0x38(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
jmp 0x43d1
jmp 0x4388
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x43a0
jmp 0x43a2
jmp 0x4388
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x43cf
movl -0x34(%rbp), %ecx
addl -0x38(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
jmp 0x43d1
movl -0x1c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x4437
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x2110
movslq -0x34(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x442a
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x58(%rbp), %rax
movslq -0x50(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x4401
jmp 0x442c
movl -0x2c(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x43d7
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movq 0x10(%rbp), %rcx
callq 0x4450
addq $0x60, %rsp
popq %rbp
retq
nop