// File: /workspace/github_c_makefile_star2_O2/USArmyResearchLab[P]ARL_OpenSHMEM/test/put_nb_dual.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;

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

	if (me == 0) {
		printf("# SHMEM Non-Blocking PutMem, Dual-Issue Performance\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 = 2; nelement <= NELEMENT; nelement <<= 1)
	{
		// reset values for each iteration
		for (i = 0; i < NELEMENT; i++) {
			target[i] = -90;
		}
		shmem_barrier_all();
		ctimer_start();

		t = ctimer();
		unsigned int n2 = nelement >> 1;
		for (i = 0; i < NLOOP; i++) {
			shmem_putmem_nbi(target, source, n2, nxtpe);
			shmem_putmem_nbi(target + n2, source + n2, n2, nxtpe);
		}

		shmem_quiet();

		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] != -90) 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:
xorl %eax, %eax
leaq 0x5e2b(%rip), %rcx      # 0x71a0
cmpq $0x50, %rax
je 0x1386
andq $0x0, (%rax,%rcx)
addq $0x8, %rax
jmp 0x1375
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
callq 0x16ac
leaq 0x5da5(%rip), %rax      # 0x7148
movl (%rax), %ecx
leaq 0x5da0(%rip), %rax      # 0x714c
movl (%rax), %ebx
movq %rcx, -0x38(%rbp)
leal 0x1(%rcx), %eax
xorl %r14d, %r14d
movl %eax, -0x30(%rbp)
cmpl %ebx, %eax
movl %ebx, -0x2c(%rbp)
cmovll %r14d, %ebx
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x1654
movq %rax, %r15
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x1654
movq %rax, %r12
cmpq $0x2000, %r14           # imm = 0x2000
je 0x13fe
leaq 0x1(%r14), %rax
movb %al, (%r15,%r14)
movq %rax, %r14
jmp 0x13e8
cmpl $0x0, -0x38(%rbp)
jne 0x1410
leaq 0x2c49(%rip), %rdi      # 0x4054
callq 0x1080
subl %ebx, -0x30(%rbp)
imull $0x2710, -0x2c(%rbp), %eax # imm = 0x2710
movl %eax, -0x3c(%rbp)
pushq $0x2
popq %rbx
leaq -0x60(%rbp), %r14
movq %r15, -0x50(%rbp)
movq %r12, -0x48(%rbp)
movl -0x30(%rbp), %r13d
cmpl $0x2000, %ebx           # imm = 0x2000
ja 0x162b
xorl %eax, %eax
cmpq $0x2000, %rax           # imm = 0x2000
je 0x1450
movb $-0x5a, (%r12,%rax)
incq %rax
jmp 0x143e
callq 0x1688
leaq 0x5d94(%rip), %rdi      # 0x71f0
xorl %esi, %esi
callq 0x1130
movq %r14, %rdi
xorl %esi, %esi
callq 0x1130
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rcx
subq 0x5d74(%rip), %rax      # 0x71f0
cvtsi2sd %rax, %xmm0
subq 0x5d70(%rip), %rcx      # 0x71f8
cvtsi2sd %rcx, %xmm1
mulsd 0x2b73(%rip), %xmm1     # 0x4008
mulsd 0x2b73(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2b63(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
notl %eax
movl %eax, 0x5caa(%rip)      # 0x7170
movl %ebx, -0x40(%rbp)
shrl %ebx
leaq (%r12,%rbx), %r14
addq %rbx, %r15
movl $0x2710, %r12d          # imm = 0x2710
subl $0x1, %r12d
jb 0x1504
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %rbx, %rdx
movl %r13d, %ecx
callq 0x30c4
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl %r13d, %ecx
callq 0x30c4
jmp 0x14d8
callq 0x1cec
leaq -0x60(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x1130
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rcx
subq 0x5cca(%rip), %rax      # 0x71f0
cvtsi2sd %rax, %xmm0
subq 0x5cc6(%rip), %rcx      # 0x71f8
cvtsi2sd %rcx, %xmm1
mulsd 0x2ac9(%rip), %xmm1     # 0x4008
mulsd 0x2ac9(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2ab9(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
movl 0x5c02(%rip), %ecx      # 0x7170
addl %ecx, %eax
incl %eax
movl %eax, 0x5bf8(%rip)      # 0x7170
leaq 0x5bf5(%rip), %rdi      # 0x7174
leaq 0x5bea(%rip), %rsi      # 0x7170
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl -0x2c(%rbp), %r9d
leaq 0x5c07(%rip), %rax      # 0x71a0
pushq %rax
leaq 0x5bdf(%rip), %rax      # 0x7180
pushq %rax
callq 0x2f18
popq %rax
popq %rcx
cmpl $0x0, -0x38(%rbp)
movl -0x40(%rbp), %ebx
jne 0x15cf
movl 0x5bbc(%rip), %eax      # 0x7174
xorl %edx, %edx
divl -0x3c(%rbp)
leaq 0x2a5c(%rip), %rdi      # 0x4020
movl %ebx, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x1100
movl %ebx, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r12
cmpq %rcx, %rax
je 0x1606
movb (%r12,%rcx), %sil
xorl %edi, %edi
cmpb (%r15,%rcx), %sil
setne %dil
addl %edi, %edx
incq %rcx
jmp 0x15dd
xorl %ecx, %ecx
cmpb $-0x5a, (%r12,%rax)
setne %cl
addl %ecx, %edx
incq %rax
cmpq $0x1fff, %rax           # imm = 0x1FFF
jbe 0x15f7
testl %edx, %edx
je 0x1624
leaq 0x2a10(%rip), %rdi      # 0x4029
movq -0x38(%rbp), %rsi
xorl %eax, %eax
callq 0x1100
addl %ebx, %ebx
jmp 0x1430
movq %r12, %rdi
callq 0x1694
movq %r15, %rdi
callq 0x1694
callq 0x1ca5
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)