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

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

	if (me == 0) {
		printf("# SHMEM Put32 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] = -90;
		}
		shmem_barrier_all();
		ctimer_start();

		t = ctimer();

		for (i = 0; i < NLOOP; i++) {
			shmem_put32(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] != -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 0x1684
leaq 0x5da5(%rip), %rax      # 0x7148
movl (%rax), %ecx
leaq 0x5da0(%rip), %rax      # 0x714c
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 0x162c
movq %rax, %r12
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x162c
movq %rax, %r13
cmpq $0x800, %r14            # imm = 0x800
je 0x13fd
leaq 0x1(%r14), %rax
movl %eax, (%r12,%r14,4)
movq %rax, %r14
jmp 0x13e7
cmpl $0x0, -0x38(%rbp)
jne 0x140f
leaq 0x2c4a(%rip), %rdi      # 0x4054
callq 0x1080
subl %ebx, %r15d
imull $0xa, -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
pushq $0x1
popq %rax
leaq -0x58(%rbp), %rbx
movl %eax, %r14d
cmpl $0x800, %r14d           # imm = 0x800
ja 0x1606
xorl %eax, %eax
cmpq $0x800, %rax            # imm = 0x800
je 0x1448
movl $0xffffffa6, (%r13,%rax,4) # imm = 0xFFFFFFA6
incq %rax
jmp 0x1432
callq 0x1660
leaq 0x5d9c(%rip), %rdi      # 0x71f0
xorl %esi, %esi
callq 0x1130
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1130
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq 0x5d7c(%rip), %rax      # 0x71f0
cvtsi2sd %rax, %xmm0
subq 0x5d78(%rip), %rcx      # 0x71f8
cvtsi2sd %rcx, %xmm1
mulsd 0x2b7b(%rip), %xmm1     # 0x4008
mulsd 0x2b7b(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2b6b(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
notl %eax
movl %eax, 0x5cb2(%rip)      # 0x7170
movq %r14, -0x48(%rbp)
movl %r14d, %r14d
pushq $0xa
popq %rbx
subl $0x1, %ebx
jb 0x14e0
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x309c
jmp 0x14c8
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1130
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq 0x5cf3(%rip), %rax      # 0x71f0
cvtsi2sd %rax, %xmm0
subq 0x5cef(%rip), %rcx      # 0x71f8
cvtsi2sd %rcx, %xmm1
mulsd 0x2af2(%rip), %xmm1     # 0x4008
mulsd 0x2af2(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2ae2(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
movl 0x5c2b(%rip), %ecx      # 0x7170
addl %ecx, %eax
incl %eax
movl %eax, 0x5c21(%rip)      # 0x7170
leaq 0x5c1e(%rip), %rdi      # 0x7174
leaq 0x5c13(%rip), %rsi      # 0x7170
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl -0x2c(%rbp), %r9d
leaq 0x5c30(%rip), %rax      # 0x71a0
pushq %rax
leaq 0x5c08(%rip), %rax      # 0x7180
pushq %rax
callq 0x2ef0
popq %rax
popq %rcx
cmpl $0x0, -0x38(%rbp)
jne 0x15ac
movq -0x48(%rbp), %rax
leal (,%rax,4), %esi
movl 0x5bdd(%rip), %eax      # 0x7174
xorl %edx, %edx
divl -0x3c(%rbp)
leaq 0x2a7d(%rip), %rdi      # 0x4020
movl %eax, %edx
xorl %eax, %eax
callq 0x1100
xorl %eax, %eax
xorl %edx, %edx
cmpq %rax, %r14
je 0x15db
movl (%r13,%rax,4), %ecx
xorl %esi, %esi
cmpl (%r12,%rax,4), %ecx
setne %sil
addl %esi, %edx
incq %rax
jmp 0x15b0
xorl %eax, %eax
cmpl $-0x5a, (%r13,%r14,4)
setne %al
addl %eax, %edx
incq %r14
cmpq $0x7ff, %r14            # imm = 0x7FF
jbe 0x15cb
testl %edx, %edx
je 0x15fa
leaq 0x2a3a(%rip), %rdi      # 0x4029
movq -0x38(%rbp), %rsi
xorl %eax, %eax
callq 0x1100
movq -0x48(%rbp), %r14
addl %r14d, %r14d
jmp 0x1423
movq %r13, %rdi
callq 0x166c
movq %r12, %rdi
callq 0x166c
callq 0x1c7d
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq