// File: /workspace/github_c_makefile_star2_O2/USArmyResearchLab[P]ARL_OpenSHMEM/test/broadcast64.c
// Function: main
int main (void)
{
	int i, elements;
	static long pSyncA[SHMEM_BCAST_SYNC_SIZE];
	static long pSyncB[SHMEM_BCAST_SYNC_SIZE];
	for (i = 0; i < SHMEM_BCAST_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();

	long long* source = (long long*)shmem_malloc(NELEMENT * sizeof (*source));
	long long* target = (long long*)shmem_malloc(NELEMENT * sizeof (*target));

	if (me == 0) {
		printf("# SHMEM Broadcast64 times for NPES = %d\n" \
			"# Bytes\tLatency (nanoseconds)\n", npes);
	}

	for (elements = 1; elements <= NELEMENT; elements <<= 1)
	{
		// reset values for each iteration
		for (i = 0; i < NELEMENT; i++) {
			source[i] = i + 1;
			target[i] = -90;
		}
		shmem_barrier_all();
		ctimer_start();

		unsigned int t = ctimer();
		for (i = 0; i < NLOOP; i += 2) {
			shmem_broadcast64 (target, source, elements, 0, 0, 0, npes, pSyncA);
			shmem_broadcast64 (target, source, elements, 0, 0, 0, npes, pSyncB);
		}
		t -= ctimer();

		if (me == 0) {
			unsigned int bytes = elements * sizeof(*source);
			unsigned int nsec = ctimer_nsec(t / NLOOP);
			printf("%5d %7u\n", bytes, nsec);
		}
		else {
			int err = 0;
			for (i = 0; i < elements; i++) if (target[i] != source[i]) err++;
			for (i = elements; 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
cmpq $0x40, %rax
je 0x1382
leaq 0x4df5(%rip), %rcx      # 0x6160
andq $0x0, (%rax,%rcx)
leaq 0x4e29(%rip), %rcx      # 0x61a0
andq $0x0, (%rax,%rcx)
addq $0x8, %rax
jmp 0x135e
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
callq 0x1608
leaq 0x4da1(%rip), %rax      # 0x6140
movl (%rax), %ebx
leaq 0x4d9c(%rip), %rax      # 0x6144
movl (%rax), %r15d
movl $0x2000, %edi           # imm = 0x2000
callq 0x1c04
movq %rax, %r14
movl $0x2000, %edi           # imm = 0x2000
callq 0x1c04
movq %rax, %r12
movl %ebx, -0x2c(%rbp)
testl %ebx, %ebx
jne 0x13dd
leaq 0x2c4d(%rip), %rdi      # 0x4020
movl %r15d, %esi
xorl %eax, %eax
callq 0x10f0
pushq $0x1
popq %r13
cmpl $0x400, %r13d           # imm = 0x400
ja 0x15bc
pushq $0x1
popq %rax
cmpq $0x401, %rax            # imm = 0x401
je 0x140c
movq %rax, -0x8(%r14,%rax,8)
movq $-0x5a, -0x8(%r12,%rax,8)
incq %rax
jmp 0x13f1
callq 0x15e4
xorl %ebx, %ebx
leaq 0x4dc6(%rip), %rdi      # 0x61e0
xorl %esi, %esi
callq 0x1120
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x1120
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq 0x4da5(%rip), %rax      # 0x61e0
cvtsi2sd %rax, %xmm1
subq 0x4da1(%rip), %rcx      # 0x61e8
cvtsi2sd %rcx, %xmm0
mulsd 0x2bb4(%rip), %xmm0     # 0x4008
mulsd 0x2bb4(%rip), %xmm1     # 0x4010
addsd %xmm0, %xmm1
movapd %xmm1, -0x60(%rbp)
movq %r13, -0x38(%rbp)
movl %r13d, %r13d
cmpl $0x9, %ebx
ja 0x14ba
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
leaq 0x4cd7(%rip), %rax      # 0x6160
pushq %rax
pushq %r15
callq 0x2e8c
popq %rax
popq %rcx
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
leaq 0x4cf5(%rip), %rax      # 0x61a0
pushq %rax
pushq %r15
callq 0x2e8c
popq %rax
popq %rcx
addl $0x2, %ebx
jmp 0x146c
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x1120
cmpl $0x0, -0x2c(%rbp)
je 0x151c
xorl %eax, %eax
xorl %edx, %edx
cmpq %rax, %r13
je 0x14f8
movq (%r12,%rax,8), %rcx
xorl %esi, %esi
cmpq (%r14,%rax,8), %rcx
setne %sil
addl %esi, %edx
incq %rax
jmp 0x14cf
xorl %eax, %eax
cmpq $-0x5a, (%r12,%r13,8)
setne %al
addl %eax, %edx
incq %r13
cmpq $0x400, %r13            # imm = 0x400
jne 0x14e9
testl %edx, %edx
movq -0x38(%rbp), %r13
je 0x15b4
leaq 0x2b5c(%rip), %rdi      # 0x4070
movl -0x2c(%rbp), %esi
jmp 0x15ad
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rdx
movapd -0x60(%rbp), %xmm1
cvttsd2si %xmm1, %rcx
movsd 0x2ae2(%rip), %xmm2     # 0x4018
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rsi
movq %rcx, %rdi
sarq $0x3f, %rdi
andl %esi, %edi
orl %edi, %ecx
subq 0x4c8f(%rip), %rax      # 0x61e0
cvtsi2sd %rax, %xmm0
subq 0x4c8b(%rip), %rdx      # 0x61e8
cvtsi2sd %rdx, %xmm1
mulsd 0x2a9e(%rip), %xmm1     # 0x4008
mulsd 0x2a9e(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd %xmm2, %xmm0
cvttsd2si %xmm0, %rsi
andl %edx, %esi
orl %esi, %eax
subl %ecx, %eax
movq -0x38(%rbp), %r13
leal (,%r13,8), %esi
xorl %edx, %edx
pushq $0xa
popq %rcx
divl %ecx
leaq 0x2abc(%rip), %rdi      # 0x4067
movl %eax, %edx
xorl %eax, %eax
callq 0x10f0
addl %r13d, %r13d
jmp 0x13e1
movq %r12, %rdi
callq 0x15f0
movq %r14, %rdi
callq 0x15f0
callq 0x1c01
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop