// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
cmpq $0xa, %rax
jae 0x1391
movslq -0x38(%rbp), %rcx
leaq 0x5e12(%rip), %rax      # 0x7190
movq $0x0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1369
callq 0x17d0
leaq 0x5d9b(%rip), %rax      # 0x7138
movl (%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x5d93(%rip), %rax      # 0x713c
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jl 0x13ca
movl -0x44(%rbp), %ecx
movl -0x48(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x48(%rbp)
movl $0x2000, %esi           # imm = 0x2000
movq %rsi, %rdi
callq 0x1740
movq %rax, -0x50(%rbp)
movl $0x2000, %esi           # imm = 0x2000
movq %rsi, %rdi
callq 0x1740
movq %rax, -0x58(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x2000, -0x38(%rbp)    # imm = 0x2000
jge 0x141f
movl -0x38(%rbp), %eax
addl $0x1, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x13f3
cmpl $0x0, -0x40(%rbp)
jne 0x1433
leaq 0x3bf4(%rip), %rdi      # 0x5020
movb $0x0, %al
callq 0x10f0
movl $0x1, -0x3c(%rbp)
cmpl $0x2000, -0x3c(%rbp)    # imm = 0x2000
jg 0x16e8
movl $0x0, -0x38(%rbp)
cmpl $0x2000, -0x38(%rbp)    # imm = 0x2000
jge 0x146e
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb $-0x1, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x144e
callq 0x1790
callq 0x1710
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, 0x5c5e(%rip)      # 0x7160
movl $0x0, -0x38(%rbp)
cmpl $0x2710, -0x38(%rbp)    # imm = 0x2710
jge 0x1531
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movslq -0x3c(%rbp), %rdx
movl -0x48(%rbp), %ecx
callq 0x4530
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1509
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x1120
movq 0x5c9b(%rip), %rdx      # 0x71e0
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
subq %rdx, %rcx
cvtsi2sd %rcx, %xmm0
movq 0x5c8c(%rip), %rcx      # 0x71e8
subq %rcx, %rax
cvtsi2sd %rax, %xmm1
movsd 0x3a9c(%rip), %xmm2     # 0x5008
mulsd %xmm2, %xmm1
movsd 0x3a98(%rip), %xmm2     # 0x5010
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x3a81(%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 0x5ba5(%rip), %eax      # 0x7160
subq %rcx, %rax
movl %eax, 0x5b9c(%rip)      # 0x7160
movl -0x44(%rbp), %r9d
leaq 0x5b95(%rip), %rdi      # 0x7164
leaq 0x5b8a(%rip), %rsi      # 0x7160
movl $0x1, %edx
xorl %r8d, %r8d
leaq 0x5b8b(%rip), %r10      # 0x7170
leaq 0x5ba4(%rip), %rax      # 0x7190
movl %r8d, %ecx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x4340
cmpl $0x0, -0x40(%rbp)
jne 0x163f
movslq -0x3c(%rbp), %rax
shlq $0x0, %rax
movl %eax, -0x5c(%rbp)
movl 0x5b50(%rip), %eax      # 0x7164
imull $0x2710, -0x44(%rbp), %ecx # imm = 0x2710
xorl %edx, %edx
divl %ecx
movl %eax, %eax
movl %eax, %edi
callq 0x1730
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %esi
movl -0x60(%rbp), %edx
leaq 0x3a36(%rip), %rdi      # 0x506e
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x64(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x1687
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x50(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x167a
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x167c
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x164d
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x2000, -0x38(%rbp)    # imm = 0x2000
jge 0x16bf
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xff, %eax
je 0x16b2
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x16b4
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x168d
cmpl $0x0, -0x64(%rbp)
je 0x16d9
movl -0x40(%rbp), %esi
movl -0x64(%rbp), %edx
leaq 0x39a5(%rip), %rdi      # 0x5077
movb $0x0, %al
callq 0x10f0
jmp 0x16db
movl -0x3c(%rbp), %eax
shll %eax
movl %eax, -0x3c(%rbp)
jmp 0x143a
movq -0x58(%rbp), %rdi
callq 0x17a0
movq -0x50(%rbp), %rdi
callq 0x17a0
callq 0x2160
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)