// File: /workspace/github_c_makefile_star2_O3/USArmyResearchLab[P]ARL_OpenSHMEM/test/put.c
// Function: main
int main (void)
{
	int i, nelement;
	static unsigned int t, tsum;
	static int pWrk[SHMEM_REDUCE_MIN_WRKDATA_SIZE];
	static long pSync[SHMEM_REDUCE_SYNC_SIZE];
	for (i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) {
		pSync[i] = SHMEM_SYNC_VALUE;
	}

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

	int nxtpe = me + 1;
	if (nxtpe >= npes) nxtpe -= npes;

	unsigned char* source = (unsigned char*)shmem_align(NELEMENT * sizeof(unsigned char), 0x2000);
	unsigned char* target = (unsigned char*)shmem_align(NELEMENT * sizeof(unsigned char), 0x2000);
	for (i = 0; i < NELEMENT; i++) {
		source[i] = (unsigned char)((i + 1) & 0xff);
	}

	if (me == 0) {
		printf("# SHMEM PutMem times for variable message size\n" \
			"# Bytes\tLatency (nanoseconds)\n");
	}

	/* For int put we take average of all the times realized by a pair of PEs,
	thus reducing effects of physical location of PEs */
	for (nelement = 1; nelement <= NELEMENT; nelement <<= 1)
	{
		// reset values for each iteration
		for (i = 0; i < NELEMENT; i++) {
			target[i] = 0xff;
		}
		shmem_barrier_all();
		ctimer_start();

		t = ctimer();

		for (i = 0; i < NLOOP; i++) {
			shmem_putmem(target, source, nelement, nxtpe);
		}

		t -= ctimer();

		shmem_int_sum_to_all(&tsum, &t, 1, 0, 0, npes, pWrk, pSync);

		if (me == 0) {
			int bytes = nelement * sizeof(*source);
			unsigned int nsec = ctimer_nsec(tsum / (npes * NLOOP));
			printf("%6d %7u\n", bytes, nsec);
		}

		int err = 0;
		for (i = 0; i < nelement; i++) if (target[i] != source[i]) err++;
		for (i = nelement; i < NELEMENT; i++) if (target[i] != 0xff) err++;
		if (err) printf("# %d: ERROR: %d incorrect value(s) copied\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 $0x28, %rsp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x4de7(%rip)     # 0x61e0
movapd %xmm0, 0x4dcf(%rip)     # 0x61d0
movapd %xmm0, 0x4db7(%rip)     # 0x61c0
movapd %xmm0, 0x4d9f(%rip)     # 0x61b0
movapd %xmm0, 0x4d87(%rip)     # 0x61a0
callq 0x170c
leaq 0x4d23(%rip), %rax      # 0x6148
movl (%rax), %ecx
leaq 0x4d1e(%rip), %rax      # 0x614c
movl (%rax), %ebx
movq %rcx, -0x38(%rbp)
leal 0x1(%rcx), %r15d
xorl %r14d, %r14d
cmpl %ebx, %r15d
movl %ebx, -0x2c(%rbp)
cmovll %r14d, %ebx
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x16b0
movq %rax, %r12
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x16b0
movq %rax, %r13
leaq 0x1(%r14), %rax
movb %al, (%r12,%r14)
movq %rax, %r14
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x1469
cmpl $0x0, -0x38(%rbp)
jne 0x148e
leaq 0x2bcb(%rip), %rdi      # 0x4054
callq 0x1080
subl %ebx, %r15d
imull $0x2710, -0x2c(%rbp), %eax # imm = 0x2710
movl %eax, -0x3c(%rbp)
movl $0x1, %r14d
movl $0x2000, %edx           # imm = 0x2000
movq %r13, %rdi
movl $0xff, %esi
callq 0x1140
callq 0x16e8
leaq 0x4d31(%rip), %rdi      # 0x61f0
xorl %esi, %esi
callq 0x1130
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1130
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq 0x4d10(%rip), %rax      # 0x61f0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq 0x4d09(%rip), %rcx      # 0x61f8
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x2b09(%rip), %xmm1     # 0x4008
mulsd 0x2b09(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2af9(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
notl %eax
movl %eax, 0x4c40(%rip)      # 0x6170
movl %r14d, -0x40(%rbp)
movslq %r14d, %rbx
movl $0x2710, %r14d          # imm = 0x2710
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl %r15d, %ecx
callq 0x32dc
decl %r14d
jne 0x153d
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1130
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq 0x4c83(%rip), %rax      # 0x61f0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq 0x4c7c(%rip), %rcx      # 0x61f8
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x2a7c(%rip), %xmm1     # 0x4008
mulsd 0x2a7c(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2a6c(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
movl 0x4bb5(%rip), %ecx      # 0x6170
addl %ecx, %eax
incl %eax
movl %eax, 0x4bab(%rip)      # 0x6170
leaq 0x4ba8(%rip), %rdi      # 0x6174
leaq 0x4b9d(%rip), %rsi      # 0x6170
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl -0x2c(%rbp), %r9d
leaq 0x4bb8(%rip), %rax      # 0x61a0
pushq %rax
leaq 0x4b90(%rip), %rax      # 0x6180
pushq %rax
callq 0x30f8
addq $0x10, %rsp
cmpl $0x0, -0x38(%rbp)
movl -0x40(%rbp), %r14d
jne 0x1622
movl 0x4b6a(%rip), %eax      # 0x6174
xorl %edx, %edx
divl -0x3c(%rbp)
leaq 0x2a0a(%rip), %rdi      # 0x4020
movl %r14d, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x1100
movl %r14d, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movb (%r13,%rcx), %sil
xorl %edi, %edi
cmpb (%r12,%rcx), %sil
setne %dil
addl %edi, %edx
incq %rcx
cmpq %rcx, %rax
jne 0x1629
cmpl $0x1fff, %r14d          # imm = 0x1FFF
ja 0x1664
xorl %eax, %eax
cmpb $-0x1, (%r13,%rbx)
setne %al
addl %eax, %edx
incq %rbx
cmpq $0x2000, %rbx           # imm = 0x2000
jne 0x164b
testl %edx, %edx
je 0x167a
leaq 0x29ba(%rip), %rdi      # 0x4029
movq -0x38(%rbp), %rsi
xorl %eax, %eax
callq 0x1100
addl %r14d, %r14d
cmpl $0x2001, %r14d          # imm = 0x2001
jl 0x14a1
movq %r13, %rdi
callq 0x16f4
movq %r12, %rdi
callq 0x16f4
callq 0x1d0d
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq