// File: /workspace/github_cpp_makefile_star2_O3/kaityo256[P]lj_simd/force_aos.cpp
// Function: force_avx2()
void
force_avx2(void) {
  const v4df vzero = _mm256_set1_pd(0.0);
  const v4df vcl2 = _mm256_set1_pd(CL2);
  const v4df vc24 = _mm256_set1_pd(24 * dt);
  const v4df vc48 = _mm256_set1_pd(48 * dt);
  const int pn = particle_number;
  for (int i = 0; i < pn; i++) {
    const v4df vqi = _mm256_load_pd((double *)(q + i));
    v4df vpi = _mm256_load_pd((double *)(p + i));
    const int np = number_of_partners[i];
    const int kp = pointer[i];
    for (int k = 0; k < (np / 4) * 4; k += 4) {
      const int j_1 = sorted_list[kp + k];
      const int j_2 = sorted_list[kp + k + 1];
      const int j_3 = sorted_list[kp + k + 2];
      const int j_4 = sorted_list[kp + k + 3];
      v4df vqj_1 = _mm256_load_pd((double *)(q + j_1));
      v4df vqj_2 = _mm256_load_pd((double *)(q + j_2));
      v4df vqj_3 = _mm256_load_pd((double *)(q + j_3));
      v4df vqj_4 = _mm256_load_pd((double *)(q + j_4));

      v4df vdq_1 = (vqj_1 - vqi);
      v4df vdq_2 = (vqj_2 - vqi);
      v4df vdq_3 = (vqj_3 - vqi);
      v4df vdq_4 = (vqj_4 - vqi);

      v4df tmp0 = _mm256_unpacklo_pd(vdq_1, vdq_2);
      v4df tmp1 = _mm256_unpackhi_pd(vdq_1, vdq_2);
      v4df tmp2 = _mm256_unpacklo_pd(vdq_3, vdq_4);
      v4df tmp3 = _mm256_unpackhi_pd(vdq_3, vdq_4);

      v4df vdx = _mm256_permute2f128_pd(tmp0, tmp2, 0x20);
      v4df vdy = _mm256_permute2f128_pd(tmp1, tmp3, 0x20);
      v4df vdz = _mm256_permute2f128_pd(tmp0, tmp2, 0x31);

      v4df vr2 = vdx * vdx + vdy * vdy + vdz * vdz;
      v4df vr6 = vr2 * vr2 * vr2;
      v4df vdf = (vc24 * vr6 - vc48) / (vr6 * vr6 * vr2);
      v4df mask = vcl2 - vr2;
      vdf = _mm256_blendv_pd(vdf, vzero, mask);

      v4df vdf_1 = _mm256_permute4x64_pd(vdf, 0);
      v4df vdf_2 = _mm256_permute4x64_pd(vdf, 85);
      v4df vdf_3 = _mm256_permute4x64_pd(vdf, 170);
      v4df vdf_4 = _mm256_permute4x64_pd(vdf, 255);

      v4df vpj_1 = _mm256_load_pd((double *)(p + j_1));
      v4df vpj_2 = _mm256_load_pd((double *)(p + j_2));
      v4df vpj_3 = _mm256_load_pd((double *)(p + j_3));
      v4df vpj_4 = _mm256_load_pd((double *)(p + j_4));

      vpj_1 -= vdq_1 * vdf_1;
      vpj_2 -= vdq_2 * vdf_2;
      vpj_3 -= vdq_3 * vdf_3;
      vpj_4 -= vdq_4 * vdf_4;

      vpi += vdq_1 * vdf_1;
      vpi += vdq_2 * vdf_2;
      vpi += vdq_3 * vdf_3;
      vpi += vdq_4 * vdf_4;

      _mm256_store_pd((double *)(p + j_1), vpj_1);
      _mm256_store_pd((double *)(p + j_2), vpj_2);
      _mm256_store_pd((double *)(p + j_3), vpj_3);
      _mm256_store_pd((double *)(p + j_4), vpj_4);
    }
    _mm256_store_pd((double *)(p + i), vpi);
    for (int k = (np / 4) * 4; k < np; k++) {
      const int j = sorted_list[kp + k];
      double dx = q[j][X] - q[i][X];
      double dy = q[j][Y] - q[i][Y];
      double dz = q[j][Z] - q[i][Z];
      double r2 = (dx * dx + dy * dy + dz * dz);
      double r6 = r2 * r2 * r2;
      double df = ((24.0 * r6 - 48.0) / (r6 * r6 * r2)) * dt;
      if (r2 > CL2) df = 0.0;
      p[i][X] += df * dx;
      p[i][Y] += df * dy;
      p[i][Z] += df * dz;
      p[j][X] -= df * dx;
      p[j][Y] -= df * dy;
      p[j][Z] -= df * dz;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movslq 0x325e8bf(%rip), %rax   # 0x3261bc0
movq %rax, -0x8(%rsp)
testq %rax, %rax
jle 0x35ed
vbroadcastsd 0x1d30(%rip), %ymm0 # 0x5048
vbroadcastsd 0x1d2e(%rip), %ymm20 # 0x5050
vbroadcastsd 0x1d15(%rip), %ymm2 # 0x5040
vmovsd 0x1cf5(%rip), %xmm4     # 0x5028
vmovsd 0x1cf5(%rip), %xmm5     # 0x5030
vmovsd 0x1cf5(%rip), %xmm6     # 0x5038
vmovsd 0x1cf5(%rip), %xmm7     # 0x5040
leaq 0x18a83e(%rip), %rdx    # 0x18db90
leaq 0xdbf837(%rip), %rsi    # 0xdc2b90
leaq 0x90f9470(%rip), %r9    # 0x90fc7d0
vxorpd %xmm3, %xmm3, %xmm3
vxorpd %xmm8, %xmm8, %xmm8
xorl %ecx, %ecx
movq %rcx, %r14
shlq $0x5, %r14
leaq 0x325e857(%rip), %rax   # 0x3261bd0
movslq (%rax,%rcx,4), %r10
vmovapd (%r14,%rdx), %ymm9
vmovapd (%r14,%rsi), %ymm10
leaq 0x8f72a40(%rip), %rax   # 0x8f75dd0
movslq (%rax,%rcx,4), %r11
leal 0x3(%r10), %ebx
testq %r10, %r10
cmovnsl %r10d, %ebx
andl $-0x4, %ebx
cmpq $0x4, %r10
jl 0x3506
leaq 0xc(%r9,%r11,4), %r12
movl %ebx, %r15d
xorl %r13d, %r13d
movslq -0xc(%r12,%r13,4), %rbp
movslq -0x8(%r12,%r13,4), %rdi
movslq -0x4(%r12,%r13,4), %r8
movslq (%r12,%r13,4), %rax
addq $0x4, %r13
shlq $0x5, %r8
shlq $0x5, %rax
shlq $0x5, %rbp
shlq $0x5, %rdi
vmovapd (%rbp,%rdx), %ymm11
vmovapd (%rdi,%rdx), %ymm12
vmovapd (%r8,%rdx), %ymm13
vmovapd (%rax,%rdx), %ymm14
vmovapd (%r8,%rsi), %ymm21
vmovapd (%rax,%rsi), %ymm22
vsubpd %ymm9, %ymm11, %ymm11
vsubpd %ymm9, %ymm12, %ymm12
vsubpd %ymm9, %ymm13, %ymm13
vsubpd %ymm9, %ymm14, %ymm14
vinsertf32x4 $0x1, %xmm14, %ymm12, %ymm18
vinsertf32x4 $0x1, %xmm13, %ymm11, %ymm19
vunpcklpd %ymm12, %ymm11, %ymm15 # ymm15 = ymm11[0],ymm12[0],ymm11[2],ymm12[2]
vunpcklpd %ymm14, %ymm13, %ymm16 # ymm16 = ymm13[0],ymm14[0],ymm13[2],ymm14[2]
vinsertf32x4 $0x1, %xmm16, %ymm15, %ymm17
vshuff64x2 $0x3, %ymm16, %ymm15, %ymm15 # ymm15 = ymm15[2,3],ymm16[2,3]
vunpckhpd %ymm18, %ymm19, %ymm18 # ymm18 = ymm19[1],ymm18[1],ymm19[3],ymm18[3]
vmovapd (%rdi,%rsi), %ymm19
vmulpd %ymm18, %ymm18, %ymm16
vmovapd (%rbp,%rsi), %ymm18
vfmadd231pd %ymm17, %ymm17, %ymm16 # ymm16 = (ymm17 * ymm17) + ymm16
vmovapd %ymm0, %ymm17
vfmadd231pd %ymm15, %ymm15, %ymm16 # ymm16 = (ymm15 * ymm15) + ymm16
vmulpd %ymm16, %ymm16, %ymm15
vsubpd %ymm16, %ymm2, %ymm1
vmulpd %ymm15, %ymm16, %ymm15
vfmadd213pd %ymm20, %ymm15, %ymm17 # ymm17 = (ymm15 * ymm17) + ymm20
vmulpd %ymm15, %ymm15, %ymm15
vmulpd %ymm15, %ymm16, %ymm15
vdivpd %ymm15, %ymm17, %ymm15
vblendvpd %ymm1, %ymm3, %ymm15, %ymm1
vbroadcastsd %xmm1, %ymm15
vpermpd $0x55, %ymm1, %ymm16    # ymm16 = ymm1[1,1,1,1]
vpermpd $0xaa, %ymm1, %ymm17    # ymm17 = ymm1[2,2,2,2]
vpermpd $0xff, %ymm1, %ymm1     # ymm1 = ymm1[3,3,3,3]
vfmadd231pd %ymm15, %ymm11, %ymm10 # ymm10 = (ymm11 * ymm15) + ymm10
vfnmadd231pd %ymm15, %ymm11, %ymm18 # ymm18 = -(ymm11 * ymm15) + ymm18
vfnmadd231pd %ymm16, %ymm12, %ymm19 # ymm19 = -(ymm12 * ymm16) + ymm19
vfnmadd231pd %ymm17, %ymm13, %ymm21 # ymm21 = -(ymm13 * ymm17) + ymm21
vfnmadd231pd %ymm1, %ymm14, %ymm22 # ymm22 = -(ymm14 * ymm1) + ymm22
vfmadd231pd %ymm16, %ymm12, %ymm10 # ymm10 = (ymm12 * ymm16) + ymm10
vmovapd %ymm18, (%rbp,%rsi)
vmovapd %ymm19, (%rdi,%rsi)
vmovapd %ymm21, (%r8,%rsi)
vmovapd %ymm22, (%rax,%rsi)
vfmadd231pd %ymm17, %ymm13, %ymm10 # ymm10 = (ymm13 * ymm17) + ymm10
vfmadd231pd %ymm1, %ymm14, %ymm10 # ymm10 = (ymm14 * ymm1) + ymm10
cmpq %r15, %r13
jb 0x33b7
vmovsd 0x10(%r14,%rdx), %xmm11
leaq (%rsi,%r14), %rax
vmovapd %ymm10, (%rax)
cmpl %r10d, %ebx
jge 0x35df
movslq %ebx, %rdi
addq %rdi, %r11
subq %rdi, %r10
xorl %edi, %edi
shlq $0x2, %r11
leaq (%r11,%rdi,4), %r8
vmovapd %xmm4, %xmm14
incq %rdi
movslq (%r9,%r8), %r8
shlq $0x5, %r8
vmovapd (%r8,%rdx), %xmm10
vmovsd 0x10(%r8,%rdx), %xmm1
vsubpd %xmm9, %xmm10, %xmm10
vsubsd %xmm11, %xmm1, %xmm1
vmulpd %xmm10, %xmm10, %xmm12
vshufpd $0x1, %xmm12, %xmm12, %xmm12 # xmm12 = xmm12[1,0]
vfmadd231sd %xmm10, %xmm10, %xmm12 # xmm12 = (xmm10 * xmm10) + xmm12
vfmadd231sd %xmm1, %xmm1, %xmm12 # xmm12 = (xmm1 * xmm1) + xmm12
vmulsd %xmm12, %xmm12, %xmm13
vcmpgtsd %xmm7, %xmm12, %k1
vmulsd %xmm13, %xmm12, %xmm13
vmulsd %xmm13, %xmm13, %xmm15
vfmadd213sd %xmm5, %xmm13, %xmm14 # xmm14 = (xmm13 * xmm14) + xmm5
vmulsd %xmm15, %xmm12, %xmm13
vdivsd %xmm13, %xmm14, %xmm13
vmovapd (%rax), %xmm14
vmulsd %xmm6, %xmm13, %xmm13
vmovsd %xmm8, %xmm13, %xmm13 {%k1}
vmovddup %xmm13, %xmm12          # xmm12 = xmm13[0,0]
vfmadd231pd %xmm10, %xmm12, %xmm14 # xmm14 = (xmm12 * xmm10) + xmm14
vmovapd %xmm14, (%rax)
vmovsd 0x10(%rax), %xmm14
vfmadd231sd %xmm1, %xmm13, %xmm14 # xmm14 = (xmm13 * xmm1) + xmm14
vmovsd %xmm14, 0x10(%rax)
vfnmadd213pd (%r8,%rsi), %xmm12, %xmm10 # xmm10 = -(xmm12 * xmm10) + mem
vmovapd %xmm10, (%r8,%rsi)
vfnmadd213sd 0x10(%r8,%rsi), %xmm1, %xmm13 # xmm13 = -(xmm1 * xmm13) + mem
vmovsd %xmm13, 0x10(%r8,%rsi)
cmpq %rdi, %r10
jne 0x352d
incq %rcx
cmpq -0x8(%rsp), %rcx
jne 0x336b
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq