// File: /workspace/github_c_makefile_star2_O0/USArmyResearchLab[P]ARL_OpenSHMEM/src/autogen/shmem_broadcast64.c
// Function: shmem_broadcast64
void shmem_broadcast64( void* dest, const void* source, size_t nelems, 
	int pe_root, int pe_start, int log_pe_stride, int pe_size, long* psync)
{
	if (pe_size == 1) return;

	int pe = __shmem.my_pe;

	int pe_root_stride = pe_root << log_pe_stride;

	int64_t* psrc = (int64_t*)dest;

	int pex = pe - pe_start - pe_root_stride;

	int pe_size_stride = pe_size << log_pe_stride;

	if (pex < 0) pex += pe_size_stride;

	if (pex == 0) psrc = (int64_t*)source;

	int pe_end = pe_size_stride + pe_start;

	int maskx = pe_size_stride - 1;

	maskx |= (maskx >> 1);

	maskx |= (maskx >> 2); /* up to 16 PEs */
	maskx |= (maskx >> 4); /* up to 1024 PEs */
	/*maskx |= (maskx >> 8);*/ /* up to 65536 PEs */

	maskx += 1; /* the next largest power of 2 of the largest PE number */

	maskx >>= 1;

	int mask2 = pex & -pex; /* least significant 1 bit */

	if (pex==0) mask2 = maskx;

	int mask1 = (mask2 << 1) - 1;

	__shmem.lock_receive_finished = 0;

	debug("broadcast calling barrier");

	shmem_barrier(pe_start, log_pe_stride, pe_size, psync);

	do {
		if ((pex & mask1) == 0) {

			int pe_to = (pex | mask2) + pe_start + pe_root_stride;

			if (pe_to >= pe_end) pe_to -= pe_size_stride;

			long* remote_lock_receive_finished 
				= (long*)shmem_ptr((void*)&__shmem.lock_receive_finished, pe_to);

			int64_t* remote_dest = (int64_t*)shmem_ptr((void*)dest, pe_to);

			shmemx_memcpy((void*)remote_dest, (void*)psrc, nelems*sizeof(int64_t));

			/// clear lock_receive_finished on receiving PE 
			*remote_lock_receive_finished = 1;
//			__set_spin_lock(remote_lock_receive_finished);

		} else {
			while (!__shmem.lock_receive_finished);
			__shmem.lock_receive_finished = 0;
//			__clear_spin_lock(&__shmem.lock_receive_finished);
		}
		mask1 >>= 1;
		mask2 >>= 1;

	} while (mask1 >> log_pe_stride);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
cmpl $0x1, 0x10(%rbp)
jne 0x4331
jmp 0x44e1
leaq 0x2eb8(%rip), %rax      # 0x71f0
movl 0x4(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movl -0x24(%rbp), %ecx
shll %cl, %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x28(%rbp), %eax
subl -0x20(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl 0x10(%rbp), %eax
movl -0x24(%rbp), %ecx
shll %cl, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x4377
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x4385
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x40(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
sarl %eax
orl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
sarl $0x2, %eax
orl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
sarl $0x4, %eax
orl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
sarl %eax
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
xorl %ecx, %ecx
subl -0x3c(%rbp), %ecx
andl %ecx, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x43e4
movl -0x48(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
shll %eax
subl $0x1, %eax
movl %eax, -0x50(%rbp)
leaq 0x2dfa(%rip), %rax      # 0x71f0
movq $0x0, 0x80(%rax)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
movl 0x10(%rbp), %edx
movq 0x18(%rbp), %rcx
callq 0x44f0
movl -0x3c(%rbp), %eax
andl -0x50(%rbp), %eax
cmpl $0x0, %eax
jne 0x448d
movl -0x3c(%rbp), %eax
orl -0x4c(%rbp), %eax
addl -0x20(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x44(%rbp), %eax
jl 0x4440
movl -0x40(%rbp), %ecx
movl -0x54(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %esi
leaq 0x2da6(%rip), %rdi      # 0x71f0
addq $0x10, %rdi
addq $0x70, %rdi
callq 0x2130
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x2130
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rdx
shlq $0x3, %rdx
callq 0x45f0
movq -0x60(%rbp), %rax
movq $0x1, (%rax)
jmp 0x44c0
jmp 0x448f
leaq 0x2d5a(%rip), %rax      # 0x71f0
movq 0x80(%rax), %rax
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x44ac
jmp 0x44ae
jmp 0x448f
leaq 0x2d3b(%rip), %rax      # 0x71f0
movq $0x0, 0x80(%rax)
movl -0x50(%rbp), %eax
sarl %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
sarl %eax
movl %eax, -0x4c(%rbp)
movl -0x50(%rbp), %eax
movl -0x24(%rbp), %ecx
sarl %cl, %eax
cmpl $0x0, %eax
jne 0x4413
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)