// File: /workspace/github_c_makefile_star2_O1/USArmyResearchLab[P]ARL_OpenSHMEM/test/fcollect32.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();

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

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

	if (me == 0) {
		printf("# SHMEM Fcollect32 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_fcollect32(target, source, nelement, 0, 0, npes, pSyncA);
			shmem_fcollect32(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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x4d87(%rip)     # 0x6190
movapd %xmm0, 0x4d6f(%rip)     # 0x6180
movapd %xmm0, 0x4d57(%rip)     # 0x6170
movapd %xmm0, 0x4d3f(%rip)     # 0x6160
movapd %xmm0, 0x4d77(%rip)     # 0x61a0
movapd %xmm0, 0x4d7f(%rip)     # 0x61b0
movapd %xmm0, 0x4d87(%rip)     # 0x61c0
movapd %xmm0, 0x4d8f(%rip)     # 0x61d0
callq 0x170c
leaq 0x4cf3(%rip), %rax      # 0x6140
movl (%rax), %ebx
leaq 0x4cee(%rip), %rax      # 0x6144
movslq (%rax), %r15
movl $0x400, %edi            # imm = 0x400
callq 0x1cd4
movq %rax, %r14
movq %r15, %rdi
shlq $0xa, %rdi
callq 0x1cd4
movq %rax, %r12
movq %rbx, -0x30(%rbp)
leal 0xa(%rbx), %eax
xorl %ecx, %ecx
movl %eax, (%r14,%rcx,4)
incq %rcx
addl $0xa, %eax
cmpq $0x100, %rcx            # imm = 0x100
jne 0x147e
movq %r14, -0x38(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x14ac
leaq 0x2b7e(%rip), %rdi      # 0x4020
movl %r15d, %esi
xorl %eax, %eax
callq 0x10f0
movl $0x1, %r13d
movq %r15, -0x40(%rbp)
movq -0x40(%rbp), %r14
movl %r13d, %eax
imull %r15d, %eax
testl %eax, %eax
jle 0x14d9
movl %eax, %eax
xorl %ecx, %ecx
movl $0xffffffa6, (%r12,%rcx,4) # imm = 0xFFFFFFA6
incq %rcx
cmpq %rcx, %rax
jne 0x14c9
callq 0x16e8
leaq 0x4cfb(%rip), %rdi      # 0x61e0
xorl %esi, %esi
callq 0x1120
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1120
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq 0x4cda(%rip), %rax      # 0x61e0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
subq 0x4cd3(%rip), %rcx      # 0x61e8
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x2ae3(%rip), %xmm0     # 0x4008
mulsd 0x2ae3(%rip), %xmm1     # 0x4010
addsd %xmm0, %xmm1
movapd %xmm1, -0x70(%rbp)
movq %r13, -0x58(%rbp)
movslq %r13d, %r13
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
movq -0x38(%rbp), %r15
leaq 0x4c13(%rip), %rax      # 0x6160
movq %rax, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl %r14d, %r9d
callq 0x3028
leaq 0x4c32(%rip), %rax      # 0x61a0
movq %rax, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl %r14d, %r9d
callq 0x3028
addl $0x2, %ebx
cmpl $0x8, %ebx
jb 0x1546
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1120
cmpl $0x0, -0x30(%rbp)
movq -0x58(%rbp), %r13
jne 0x1647
movq -0x50(%rbp), %rcx
movapd -0x70(%rbp), %xmm1
cvttsd2si %xmm1, %rax
movq -0x48(%rbp), %rdx
movsd 0x2a55(%rip), %xmm2     # 0x4018
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rsi
movq %rax, %rdi
sarq $0x3f, %rdi
subq 0x4c06(%rip), %rcx      # 0x61e0
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
subq 0x4bff(%rip), %rdx      # 0x61e8
andl %esi, %edi
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
mulsd 0x2a0d(%rip), %xmm1     # 0x4008
mulsd 0x2a0d(%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,4), %esi
movl $0xcccccccd, %eax       # imm = 0xCCCCCCCD
imulq %rax, %rdx
shrq $0x23, %rdx
leaq 0x2a26(%rip), %rdi      # 0x4066
xorl %eax, %eax
callq 0x10f0
movq -0x40(%rbp), %r15
testl %r15d, %r15d
jle 0x1697
movl %r13d, %eax
leaq (,%rax,4), %rcx
xorl %esi, %esi
movl $0xa, %edi
movq %r12, %r8
xorl %edx, %edx
movq %rdi, %r9
xorl %r10d, %r10d
movl (%r8,%r10,4), %r11d
incq %r10
xorl %ebx, %ebx
cmpq %r11, %r9
setne %bl
addl %ebx, %edx
addq $0xa, %r9
cmpq %r10, %rax
jne 0x166d
incq %rsi
addq %rcx, %r8
incq %rdi
cmpq %r15, %rsi
jne 0x1667
jmp 0x1699
xorl %edx, %edx
testl %edx, %edx
je 0x16af
leaq 0x29cb(%rip), %rdi      # 0x406f
movq -0x30(%rbp), %rsi
xorl %eax, %eax
callq 0x10f0
addl %r13d, %r13d
cmpl $0x101, %r13d           # imm = 0x101
jl 0x14ba
movq %r12, %rdi
callq 0x16f4
movq -0x38(%rbp), %rdi
callq 0x16f4
callq 0x1cd2
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop