// File: /workspace/github_c_makefile_star2_O3/USArmyResearchLab[P]ARL_OpenSHMEM/test/alltoall64.c
// Function: main
int main (void)
{
	int i, j, nelement;

	shmem_init();
	int me = shmem_my_pe();
	int npes = shmem_n_pes();

	static long pSyncA[SHMEM_ALLTOALL_SYNC_SIZE];
	static long pSyncB[SHMEM_ALLTOALL_SYNC_SIZE];
	for (i = 0; i < SHMEM_ALLTOALL_SYNC_SIZE; i++) {
		pSyncA[i] = SHMEM_SYNC_VALUE;
		pSyncB[i] = SHMEM_SYNC_VALUE;
	}

	long long* source 
		= (long long*)shmem_malloc(NELEMENT * npes * sizeof (*source));

	long long* target 
		= (long long*)shmem_malloc(NELEMENT * npes * sizeof (*target));

	for (i = 0; i < NELEMENT * npes; i++) {
		source[i] = me;
		target[i] = -90;
	}

	if (me == 0) {
		printf("# SHMEM AlltoAll64 times for NPES = %d\n" 
			"# Bytes\tLatency (nanoseconds)\n", npes); fflush(stdout);
	}

	for (nelement = 1; nelement <= NELEMENT; nelement <<= 1)
	{
		shmem_barrier_all();
		ctimer_start();

		unsigned int t = ctimer();
		for (i = 0; i < NLOOP; i += 2) {
			shmem_alltoall64 (target, source, nelement, 0, 0, npes, pSyncA);
			shmem_alltoall64 (target, source, nelement, 0, 0, npes, pSyncB);
		}
		t -= ctimer();

		if (me == 0) {
			unsigned int bytes = nelement * sizeof(*source);
			unsigned int nsec = ctimer_nsec(t / NLOOP);
			printf("%5d %7u\n", bytes, nsec);
		}
		unsigned int err = 0;
		for (j = 0; j < npes; j++) {
			for (i = 0; i < nelement; i++) {
				if (target[j*nelement + i] != j) err++;
			}
		}
		if (err) printf("# %d: %d ERRORS\n", me, err);
	}

	shmem_free(target);
	shmem_free(source);

	shmem_finalize();

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
callq 0x16dc
leaq 0x4d4f(%rip), %rax      # 0x6148
movslq (%rax), %rbx
leaq 0x4d49(%rip), %rax      # 0x614c
movslq (%rax), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, 0x4d5e(%rip)     # 0x6170
movapd %xmm0, 0x4d66(%rip)     # 0x6180
movapd %xmm0, 0x4d6e(%rip)     # 0x6190
movapd %xmm0, 0x4d76(%rip)     # 0x61a0
movapd %xmm0, 0x4d7e(%rip)     # 0x61b0
movapd %xmm0, 0x4d86(%rip)     # 0x61c0
movapd %xmm0, 0x4d8e(%rip)     # 0x61d0
movapd %xmm0, 0x4d96(%rip)     # 0x61e0
movq %r14, %r12
shlq $0x9, %r12
movq %r12, %rdi
callq 0x1ce0
movq %rax, %r15
movq %r12, %rdi
callq 0x1ce0
testq %r14, %r14
jle 0x1487
movl %r14d, %ecx
shll $0x6, %ecx
movl %ecx, %edx
xorl %ecx, %ecx
movq %rbx, (%r15,%rcx,8)
movq $-0x5a, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rdx
jne 0x1473
movq %rax, -0x30(%rbp)
movq %r15, -0x38(%rbp)
testl %ebx, %ebx
jne 0x14b3
leaq 0x2b86(%rip), %rdi      # 0x4020
movl %r14d, %esi
xorl %eax, %eax
callq 0x10f0
movq 0x4b2d(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
callq 0x11c0
movl $0x1, %r13d
movq %rbx, -0x50(%rbp)
movq -0x38(%rbp), %r12
movq -0x30(%rbp), %r15
callq 0x16b8
leaq 0x4d1f(%rip), %rdi      # 0x61f0
xorl %esi, %esi
callq 0x1120
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x1120
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq 0x4cfe(%rip), %rax      # 0x61f0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
subq 0x4cf7(%rip), %rcx      # 0x61f8
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x2af7(%rip), %xmm0     # 0x4008
mulsd 0x2af7(%rip), %xmm1     # 0x4010
addsd %xmm0, %xmm1
movapd %xmm1, -0x70(%rbp)
movq %r13, -0x58(%rbp)
movslq %r13d, %r13
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
leaq 0x4c3b(%rip), %rax      # 0x6170
movq %rax, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl %r14d, %r9d
callq 0x30e0
leaq 0x4c5a(%rip), %rax      # 0x61b0
movq %rax, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl %r14d, %r9d
callq 0x30e0
addl $0x2, %ebx
cmpl $0x8, %ebx
jb 0x152e
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x1120
movq -0x50(%rbp), %rbx
testl %ebx, %ebx
movq -0x58(%rbp), %r13
jne 0x1631
movq -0x48(%rbp), %rcx
movapd -0x70(%rbp), %xmm1
cvttsd2si %xmm1, %rax
movq -0x40(%rbp), %rdx
movsd 0x2a6b(%rip), %xmm2     # 0x4018
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rsi
movq %rax, %rdi
sarq $0x3f, %rdi
subq 0x4c2c(%rip), %rcx      # 0x61f0
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
subq 0x4c25(%rip), %rdx      # 0x61f8
andl %esi, %edi
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
mulsd 0x2a23(%rip), %xmm1     # 0x4008
mulsd 0x2a23(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
orl %edi, %eax
movq %rdx, %rcx
sarq $0x3f, %rcx
subsd %xmm2, %xmm0
cvttsd2si %xmm0, %rsi
andl %ecx, %esi
orl %esi, %edx
subl %eax, %edx
leal (,%r13,8), %esi
movl $0xcccccccd, %eax       # imm = 0xCCCCCCCD
imulq %rax, %rdx
shrq $0x23, %rdx
leaq 0x2a3c(%rip), %rdi      # 0x4066
xorl %eax, %eax
callq 0x10f0
testl %r14d, %r14d
jle 0x1681
movl %r13d, %eax
leaq (,%rax,8), %rcx
xorl %esi, %esi
movq -0x30(%rbp), %rdi
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpq %rsi, (%rdi,%r8,8)
setne %r9b
addl %r9d, %edx
incq %r8
cmpq %r8, %rax
jne 0x164c
incq %rsi
addq %rcx, %rdi
cmpq %r14, %rsi
jne 0x1649
testl %edx, %edx
je 0x1681
leaq 0x29f7(%rip), %rdi      # 0x406f
movl %ebx, %esi
xorl %eax, %eax
callq 0x10f0
addl %r13d, %r13d
cmpl $0x41, %r13d
jl 0x14c5
movq -0x30(%rbp), %rdi
callq 0x16c4
movq -0x38(%rbp), %rdi
callq 0x16c4
callq 0x1cdd
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop