// File: /workspace/github_c_makefile_star2_O0/USArmyResearchLab[P]ARL_OpenSHMEM/test/fcollect64.c
// Function: main
int main (void)
{
	int i, j, nelement;
	static long pSyncA[SHMEM_COLLECT_SYNC_SIZE];
	static long pSyncB[SHMEM_COLLECT_SYNC_SIZE];
	for (i = 0; i < SHMEM_COLLECT_SYNC_SIZE; i++) {
		pSyncA[i] = SHMEM_SYNC_VALUE;
		pSyncB[i] = SHMEM_SYNC_VALUE;
	}

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

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

	for (i = 0; i < NELEMENT; i++) {
		source[i] = (i + 1) * 10 + me;
	}

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

	for (nelement = 1; nelement <= NELEMENT; nelement <<= 1)
	{
		for (i = 0; i < nelement * npes; i++) {
			target[i] = -90;
		}
		shmem_barrier_all();
		ctimer_start();

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

		if (me == 0) {
			int bytes = nelement * sizeof(*source);
			unsigned int nsec = ctimer_nsec(t / NLOOP);
			printf("%5d %7u\n", bytes, nsec);
		}
		int err = 0;
		for (j = 0; j < npes; j++) {
			for (i = 0; i < nelement; i++) {
				if (target[j*nelement + i] != ((i + 1) * 10 + 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
subq $0x70, %rsp
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
cmpq $0x8, %rax
jae 0x13a1
movslq -0x38(%rbp), %rcx
leaq 0x5de5(%rip), %rax      # 0x7160
movq $0x0, (%rax,%rcx,8)
movslq -0x38(%rbp), %rcx
leaq 0x5e12(%rip), %rax      # 0x71a0
movq $0x0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1366
callq 0x1760
leaq 0x5d8b(%rip), %rax      # 0x7138
movl (%rax), %eax
movl %eax, -0x44(%rbp)
leaq 0x5d83(%rip), %rax      # 0x713c
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movl $0x400, %edi            # imm = 0x400
callq 0x2100
movq %rax, -0x50(%rbp)
movslq -0x48(%rbp), %rdi
shlq $0xa, %rdi
callq 0x2100
movq %rax, -0x58(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x80, -0x38(%rbp)
jge 0x1413
movl -0x38(%rbp), %eax
addl $0x1, %eax
imull $0xa, %eax, %eax
addl -0x44(%rbp), %eax
movslq %eax, %rdx
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x13e4
cmpl $0x0, -0x44(%rbp)
jne 0x142a
movl -0x48(%rbp), %esi
leaq 0x3bfd(%rip), %rdi      # 0x5020
movb $0x0, %al
callq 0x10f0
movl $0x1, -0x40(%rbp)
cmpl $0x80, -0x40(%rbp)
jg 0x16c7
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0x40(%rbp), %ecx
imull -0x48(%rbp), %ecx
cmpl %ecx, %eax
jge 0x146e
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq $-0x5a, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1445
callq 0x1720
callq 0x16f0
xorl %eax, %eax
movl %eax, %esi
leaq -0x18(%rbp), %rdi
callq 0x1120
movq 0x5d54(%rip), %rdx      # 0x71e0
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
subq %rdx, %rcx
cvtsi2sd %rcx, %xmm0
movq 0x5d45(%rip), %rcx      # 0x71e8
subq %rcx, %rax
cvtsi2sd %rax, %xmm1
movsd 0x3b55(%rip), %xmm2     # 0x5008
mulsd %xmm2, %xmm1
movsd 0x3b51(%rip), %xmm2     # 0x5010
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x3b3a(%rip), %xmm1     # 0x5018
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x8(%rbp)
movq $-0x1, %rax
subq -0x8(%rbp), %rax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0xa, -0x38(%rbp)
jge 0x1563
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movslq -0x40(%rbp), %rdx
movl -0x48(%rbp), %r9d
xorl %r8d, %r8d
leaq 0x5c3a(%rip), %rax      # 0x7160
movl %r8d, %ecx
movq %rax, (%rsp)
callq 0x4300
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movslq -0x40(%rbp), %rdx
movl -0x48(%rbp), %r9d
xorl %r8d, %r8d
leaq 0x5c54(%rip), %rax      # 0x71a0
movl %r8d, %ecx
movq %rax, (%rsp)
callq 0x4300
movl -0x38(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x38(%rbp)
jmp 0x1506
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x1120
movq 0x5c69(%rip), %rdx      # 0x71e0
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
subq %rdx, %rcx
cvtsi2sd %rcx, %xmm0
movq 0x5c5a(%rip), %rcx      # 0x71e8
subq %rcx, %rax
cvtsi2sd %rax, %xmm1
movsd 0x3a6a(%rip), %xmm2     # 0x5008
mulsd %xmm2, %xmm1
movsd 0x3a66(%rip), %xmm2     # 0x5010
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x3a4f(%rip), %xmm1     # 0x5018
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x20(%rbp)
movq $-0x1, %rcx
subq -0x20(%rbp), %rcx
movl -0x5c(%rbp), %eax
subq %rcx, %rax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x162d
movslq -0x40(%rbp), %rax
shlq $0x3, %rax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %eax
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %eax
movl %eax, %edi
callq 0x1710
movl %eax, -0x64(%rbp)
movl -0x60(%rbp), %esi
movl -0x64(%rbp), %edx
leaq 0x3a40(%rip), %rdi      # 0x5066
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x68(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x169e
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1691
movq -0x58(%rbp), %rax
movl -0x3c(%rbp), %ecx
imull -0x40(%rbp), %ecx
addl -0x38(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
imull $0xa, %ecx, %ecx
addl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x1684
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1686
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x164a
jmp 0x1693
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x163b
cmpl $0x0, -0x68(%rbp)
je 0x16b8
movl -0x44(%rbp), %esi
movl -0x68(%rbp), %edx
leaq 0x39be(%rip), %rdi      # 0x506f
movb $0x0, %al
callq 0x10f0
jmp 0x16ba
movl -0x40(%rbp), %eax
shll %eax
movl %eax, -0x40(%rbp)
jmp 0x1431
movq -0x58(%rbp), %rdi
callq 0x1730
movq -0x50(%rbp), %rdi
callq 0x1730
callq 0x20f0
xorl %eax, %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)