// File: /workspace/github_cpp_makefile_star2_O3/kaityo256[P]lj_simd/force_aos.cpp
// Function: force_avx2_swp()
void
force_avx2_swp(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][X]));
    v4df vpi = _mm256_load_pd((double *)(&p[i][X]));
    const int np = number_of_partners[i];
    const int kp = pointer[i];
    int k = 0;
    // --- 8< ---
    int j_1 = sorted_list[kp + k];
    int j_2 = sorted_list[kp + k + 1];
    int j_3 = sorted_list[kp + k + 2];
    int j_4 = sorted_list[kp + k + 3];
    v4df vqj_1 = _mm256_load_pd((double *)(&q[j_1][X]));
    v4df vqj_2 = _mm256_load_pd((double *)(&q[j_2][X]));
    v4df vqj_3 = _mm256_load_pd((double *)(&q[j_3][X]));
    v4df vqj_4 = _mm256_load_pd((double *)(&q[j_4][X]));

    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);

    if (np < 4) {
      vdf =  _mm256_setzero_pd();
    }

    v4df vdf_1, vdf_2, vdf_3, vdf_4;
    v4df vpj_1, vpj_2, vpj_3, vpj_4;
    for (k = 4; k < (np / 4) * 4; k += 4) {
      // --- 8< ---
      const int j_1_b = sorted_list[kp + k];
      const int j_2_b = sorted_list[kp + k + 1];
      const int j_3_b = sorted_list[kp + k + 2];
      const int j_4_b = sorted_list[kp + k + 3];
      vqj_1 = _mm256_load_pd((double *)(&q[j_1_b][X]));
      vqj_2 = _mm256_load_pd((double *)(&q[j_2_b][X]));
      vqj_3 = _mm256_load_pd((double *)(&q[j_3_b][X]));
      vqj_4 = _mm256_load_pd((double *)(&q[j_4_b][X]));
      v4df vdq_1_b = (vqj_1 - vqi);
      v4df vdq_2_b = (vqj_2 - vqi);
      v4df vdq_3_b = (vqj_3 - vqi);
      v4df vdq_4_b = (vqj_4 - vqi);
      tmp0 = _mm256_unpacklo_pd(vdq_1_b, vdq_2_b);
      tmp1 = _mm256_unpackhi_pd(vdq_1_b, vdq_2_b);
      tmp2 = _mm256_unpacklo_pd(vdq_3_b, vdq_4_b);
      tmp3 = _mm256_unpackhi_pd(vdq_3_b, vdq_4_b);
      vdx = _mm256_permute2f128_pd(tmp0, tmp2, 0x20);
      vdy = _mm256_permute2f128_pd(tmp1, tmp3, 0x20);
      vdz = _mm256_permute2f128_pd(tmp0, tmp2, 0x31);
      v4df vr2 = vdx * vdx + vdy * vdy + vdz * vdz;
      vr6 = vr2 * vr2 * vr2;

      // --- 8< ---
      vdf_1 = _mm256_permute4x64_pd(vdf, 0);
      vdf_2 = _mm256_permute4x64_pd(vdf, 85);
      vdf_3 = _mm256_permute4x64_pd(vdf, 170);
      vdf_4 = _mm256_permute4x64_pd(vdf, 255);

      vpj_1 = _mm256_load_pd((double *)(&p[j_1][X]));
      vpj_2 = _mm256_load_pd((double *)(&p[j_2][X]));
      vpj_3 = _mm256_load_pd((double *)(&p[j_3][X]));
      vpj_4 = _mm256_load_pd((double *)(&p[j_4][X]));

      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_4 * vdf_4;
      vpi += vdq_2 * vdf_2;
      vpi += vdq_3 * vdf_3;

      _mm256_store_pd((double *)(&p[j_1][X]), vpj_1);
      _mm256_store_pd((double *)(&p[j_2][X]), vpj_2);
      _mm256_store_pd((double *)(&p[j_3][X]), vpj_3);
      _mm256_store_pd((double *)(&p[j_4][X]), vpj_4);

      // --- 8< ---
      j_1 = j_1_b;
      j_2 = j_2_b;
      j_3 = j_3_b;
      j_4 = j_4_b;
      vdq_1 = vdq_1_b;
      vdq_2 = vdq_2_b;
      vdq_3 = vdq_3_b;
      vdq_4 = vdq_4_b;
      vdf = (vc24 * vr6 - vc48) / (vr6 * vr6 * vr2);
      mask = vcl2 - vr2;
      vdf = _mm256_blendv_pd(vdf, vzero, mask);
    }
    // --- 8< ---
    vdf_1 = _mm256_permute4x64_pd(vdf, 0);
    vdf_2 = _mm256_permute4x64_pd(vdf, 85);
    vdf_3 = _mm256_permute4x64_pd(vdf, 170);
    vdf_4 = _mm256_permute4x64_pd(vdf, 255);

    vpj_1 = _mm256_load_pd((double *)(&p[j_1][X]));
    vpj_2 = _mm256_load_pd((double *)(&p[j_2][X]));
    vpj_3 = _mm256_load_pd((double *)(&p[j_3][X]));
    vpj_4 = _mm256_load_pd((double *)(&p[j_4][X]));

    vpi += vdq_1 * vdf_1;
    vpi += vdq_2 * vdf_2;
    vpi += vdq_3 * vdf_3;
    vpi += vdq_4 * vdf_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;

    _mm256_store_pd((double *)(&p[j_1][X]), vpj_1);
    _mm256_store_pd((double *)(&p[j_2][X]), vpj_2);
    _mm256_store_pd((double *)(&p[j_3][X]), vpj_3);
    _mm256_store_pd((double *)(&p[j_4][X]), vpj_4);

    _mm256_store_pd((double *)(&p[i][X]), 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 0x325e5b4(%rip), %rax   # 0x3261bc0
movq %rax, -0x30(%rsp)
testq %rax, %rax
jle 0x3b2f
vbroadcastsd 0x1a25(%rip), %ymm0 # 0x5048
vbroadcastsd 0x1a24(%rip), %ymm1 # 0x5050
vbroadcastsd 0x1a0b(%rip), %ymm2 # 0x5040
vmovsd 0x19eb(%rip), %xmm4     # 0x5028
vmovsd 0x19eb(%rip), %xmm5     # 0x5030
vmovsd 0x19eb(%rip), %xmm6     # 0x5038
vmovsd 0x19eb(%rip), %xmm7     # 0x5040
leaq 0x18a534(%rip), %r13    # 0x18db90
leaq 0xdbf52d(%rip), %r14    # 0xdc2b90
leaq 0x90f9166(%rip), %r10   # 0x90fc7d0
vxorpd %xmm3, %xmm3, %xmm3
vxorpd %xmm8, %xmm8, %xmm8
xorl %r8d, %r8d
leaq 0x8f72753(%rip), %rax   # 0x8f75dd0
movq %r8, %rbx
shlq $0x5, %rbx
movslq (%rax,%r8,4), %r11
vmovapd (%rbx,%r13), %ymm9
movl (%r10,%r11,4), %ebp
movl 0x4(%r10,%r11,4), %r9d
movl 0x8(%r10,%r11,4), %ecx
movl 0xc(%r10,%r11,4), %eax
movslq %ebp, %rsi
movslq %r9d, %r15
movslq %ecx, %r12
movq %rsi, %rdx
shlq $0x5, %rdx
movq %r15, %rdi
shlq $0x5, %rdi
movq %r12, -0x40(%rsp)
vmovapd (%rdx,%r13), %ymm10
movq %r12, %rdx
movslq %eax, %r12
vmovapd (%rdi,%r13), %ymm12
shlq $0x5, %rdx
movq %r12, %rdi
shlq $0x5, %rdi
vmovapd (%rdx,%r13), %ymm13
leaq 0x325e4e9(%rip), %rdx   # 0x3261bd0
vmovapd (%rdi,%r13), %ymm14
movslq (%rdx,%r8,4), %rdx
vsubpd %ymm9, %ymm10, %ymm11
vsubpd %ymm9, %ymm12, %ymm12
vsubpd %ymm9, %ymm13, %ymm13
vsubpd %ymm9, %ymm14, %ymm14
vunpcklpd %ymm12, %ymm11, %ymm10 # ymm10 = ymm11[0],ymm12[0],ymm11[2],ymm12[2]
vinsertf32x4 $0x1, %xmm13, %ymm11, %ymm18
vinsertf32x4 $0x1, %xmm14, %ymm12, %ymm17
vunpcklpd %ymm14, %ymm13, %ymm15 # ymm15 = ymm13[0],ymm14[0],ymm13[2],ymm14[2]
vinsertf32x4 $0x1, %xmm15, %ymm10, %ymm16
vperm2f128 $0x31, %ymm15, %ymm10, %ymm15 # ymm15 = ymm10[2,3],ymm15[2,3]
vunpckhpd %ymm17, %ymm18, %ymm17 # ymm17 = ymm18[1],ymm17[1],ymm18[3],ymm17[3]
vmulpd %ymm17, %ymm17, %ymm10
vfmadd231pd %ymm16, %ymm16, %ymm10 # ymm10 = (ymm16 * ymm16) + ymm10
vmovapd %ymm0, %ymm16
vfmadd231pd %ymm15, %ymm15, %ymm10 # ymm10 = (ymm15 * ymm15) + ymm10
vmulpd %ymm10, %ymm10, %ymm15
vmulpd %ymm15, %ymm10, %ymm17
vxorpd %xmm15, %xmm15, %xmm15
vfmadd213pd %ymm1, %ymm17, %ymm16 # ymm16 = (ymm17 * ymm16) + ymm1
cmpq $0x4, %rdx
jl 0x377f
vmulpd %ymm17, %ymm17, %ymm15
vmulpd %ymm15, %ymm10, %ymm15
vsubpd %ymm10, %ymm2, %ymm10
vdivpd %ymm15, %ymm16, %ymm15
vblendvpd %ymm10, %ymm3, %ymm15, %ymm15
vmovapd (%rbx,%r14), %ymm10
leal 0x3(%rdx), %edi
testq %rdx, %rdx
movq %r8, -0x10(%rsp)
movq %rbx, -0x28(%rsp)
movq %rdx, -0x20(%rsp)
movq %r11, -0x18(%rsp)
cmovnsl %edx, %edi
andl $-0x4, %edi
movl %edi, -0x38(%rsp)
cmpq $0x8, %rdx
jl 0x398f
leaq (%r10,%r11,4), %r8
movl $0x4, %ebx
movl %edi, %edx
movq %rdx, -0x8(%rsp)
movl (%r8,%rbx,4), %edx
movl 0x4(%r8,%rbx,4), %r11d
movl 0x8(%r8,%rbx,4), %edi
movl 0xc(%r8,%rbx,4), %esi
movslq %ebp, %rbp
movslq %r9d, %r9
movslq %ecx, %rcx
cltq
vbroadcastsd %xmm15, %ymm22
vpermpd $0x55, %ymm15, %ymm25   # ymm25 = ymm15[1,1,1,1]
vpermpd $0xaa, %ymm15, %ymm26   # ymm26 = ymm15[2,2,2,2]
vpermpd $0xff, %ymm15, %ymm15   # ymm15 = ymm15[3,3,3,3]
addq $0x4, %rbx
shlq $0x5, %rbp
shlq $0x5, %r9
shlq $0x5, %rcx
shlq $0x5, %rax
vfmadd231pd %ymm22, %ymm11, %ymm10 # ymm10 = (ymm11 * ymm22) + ymm10
movslq %edx, %r10
movl %edx, -0x40(%rsp)
movslq %r11d, %rdx
movl %edi, -0x34(%rsp)
movq %r10, %r15
shlq $0x5, %r15
movq %rdx, %r12
shlq $0x5, %r12
vfmadd231pd %ymm15, %ymm14, %ymm10 # ymm10 = (ymm14 * ymm15) + ymm10
vmovapd (%r15,%r13), %ymm16
movq %r14, %r15
vmovapd (%rbp,%r15), %ymm18
vmovapd (%r9,%r15), %ymm19
vmovapd (%r12,%r13), %ymm17
movslq %edi, %r12
movq %r13, %r14
movslq %esi, %rdi
vmovapd (%rcx,%r15), %ymm23
vmovapd (%rax,%r15), %ymm24
movq %r12, %r13
shlq $0x5, %r13
vmovapd (%r13,%r14), %ymm20
movq %rdi, %r13
shlq $0x5, %r13
vmovapd (%r13,%r14), %ymm21
vfmadd231pd %ymm25, %ymm12, %ymm10 # ymm10 = (ymm12 * ymm25) + ymm10
movq %r14, %r13
movq %r15, %r14
vfmadd231pd %ymm26, %ymm13, %ymm10 # ymm10 = (ymm13 * ymm26) + ymm10
vfnmadd231pd %ymm22, %ymm11, %ymm18 # ymm18 = -(ymm11 * ymm22) + ymm18
vfnmadd231pd %ymm25, %ymm12, %ymm19 # ymm19 = -(ymm12 * ymm25) + ymm19
vfnmadd231pd %ymm26, %ymm13, %ymm23 # ymm23 = -(ymm13 * ymm26) + ymm23
vfnmadd231pd %ymm15, %ymm14, %ymm24 # ymm24 = -(ymm14 * ymm15) + ymm24
vmovapd %ymm0, %ymm11
vmovapd %ymm18, (%rbp,%r15)
vmovapd %ymm19, (%r9,%r15)
vsubpd %ymm9, %ymm16, %ymm19
vsubpd %ymm9, %ymm17, %ymm18
vsubpd %ymm9, %ymm20, %ymm17
vsubpd %ymm9, %ymm21, %ymm16
vmovapd %ymm23, (%rcx,%r15)
vmovapd %ymm24, (%rax,%r15)
movl -0x40(%rsp), %ebp
movl -0x34(%rsp), %ecx
movl %r11d, %r9d
movl %esi, %eax
vinsertf32x4 $0x1, %xmm16, %ymm18, %ymm24
vinsertf32x4 $0x1, %xmm17, %ymm19, %ymm27
vunpcklpd %ymm18, %ymm19, %ymm20 # ymm20 = ymm19[0],ymm18[0],ymm19[2],ymm18[2]
vunpcklpd %ymm16, %ymm17, %ymm21 # ymm21 = ymm17[0],ymm16[0],ymm17[2],ymm16[2]
vmovapd %ymm17, %ymm13
vmovapd %ymm16, %ymm14
vinsertf32x4 $0x1, %xmm21, %ymm20, %ymm23
vshuff64x2 $0x3, %ymm21, %ymm20, %ymm20 # ymm20 = ymm20[2,3],ymm21[2,3]
vunpckhpd %ymm24, %ymm27, %ymm24 # ymm24 = ymm27[1],ymm24[1],ymm27[3],ymm24[3]
vmulpd %ymm24, %ymm24, %ymm21
vfmadd231pd %ymm23, %ymm23, %ymm21 # ymm21 = (ymm23 * ymm23) + ymm21
vfmadd231pd %ymm20, %ymm20, %ymm21 # ymm21 = (ymm20 * ymm20) + ymm21
vmulpd %ymm21, %ymm21, %ymm20
vmulpd %ymm20, %ymm21, %ymm20
vmulpd %ymm20, %ymm20, %ymm12
vfmadd213pd %ymm1, %ymm20, %ymm11 # ymm11 = (ymm20 * ymm11) + ymm1
vmulpd %ymm12, %ymm21, %ymm12
vdivpd %ymm12, %ymm11, %ymm11
vsubpd %ymm21, %ymm2, %ymm12
vblendvpd %ymm12, %ymm3, %ymm11, %ymm15
vmovapd %ymm19, %ymm11
vmovapd %ymm18, %ymm12
cmpq -0x8(%rsp), %rbx
jb 0x37c3
jmp 0x39b5
movq %r12, %rdi
movq -0x40(%rsp), %r12
vmovapd %ymm14, %ymm16
vmovapd %ymm13, %ymm17
vmovapd %ymm12, %ymm18
vmovapd %ymm11, %ymm19
movq %rsi, %r10
movq %r15, %rdx
vbroadcastsd %xmm15, %ymm12
vpermpd $0x55, %ymm15, %ymm13   # ymm13 = ymm15[1,1,1,1]
vpermpd $0xaa, %ymm15, %ymm14   # ymm14 = ymm15[2,2,2,2]
vpermpd $0xff, %ymm15, %ymm15   # ymm15 = ymm15[3,3,3,3]
shlq $0x5, %r10
shlq $0x5, %rdx
shlq $0x5, %r12
shlq $0x5, %rdi
movq -0x28(%rsp), %rcx
movq -0x18(%rsp), %rsi
vfmadd231pd %ymm12, %ymm19, %ymm10 # ymm10 = (ymm19 * ymm12) + ymm10
vfnmadd213pd (%r10,%r14), %ymm19, %ymm12 # ymm12 = -(ymm19 * ymm12) + mem
vmovsd 0x10(%rcx,%r13), %xmm11
leaq (%r14,%rcx), %rax
movl -0x38(%rsp), %ecx
vfmadd231pd %ymm13, %ymm18, %ymm10 # ymm10 = (ymm18 * ymm13) + ymm10
vfnmadd213pd (%rdx,%r14), %ymm18, %ymm13 # ymm13 = -(ymm18 * ymm13) + mem
vfmadd231pd %ymm14, %ymm17, %ymm10 # ymm10 = (ymm17 * ymm14) + ymm10
vfnmadd213pd (%r12,%r14), %ymm17, %ymm14 # ymm14 = -(ymm17 * ymm14) + mem
vfmadd231pd %ymm15, %ymm16, %ymm10 # ymm10 = (ymm16 * ymm15) + ymm10
vfnmadd213pd (%rdi,%r14), %ymm16, %ymm15 # ymm15 = -(ymm16 * ymm15) + mem
vmovapd %ymm12, (%r10,%r14)
leaq 0x90f8d9a(%rip), %r10   # 0x90fc7d0
vmovapd %ymm13, (%rdx,%r14)
vmovapd %ymm14, (%r12,%r14)
vmovapd %ymm15, (%rdi,%r14)
movq -0x20(%rsp), %rdi
vmovapd %ymm10, (%rax)
cmpl %edi, %ecx
jge 0x3b1c
movslq %ecx, %rcx
addq %rcx, %rsi
subq %rcx, %rdi
xorl %ecx, %ecx
shlq $0x2, %rsi
leaq (%rsi,%rcx,4), %rdx
vmovapd %xmm4, %xmm15
incq %rcx
movslq (%r10,%rdx), %rdx
shlq $0x5, %rdx
vmovapd (%rdx,%r13), %xmm12
vmovsd 0x10(%rdx,%r13), %xmm10
vsubpd %xmm9, %xmm12, %xmm12
vsubsd %xmm11, %xmm10, %xmm10
vmulpd %xmm12, %xmm12, %xmm13
vshufpd $0x1, %xmm13, %xmm13, %xmm13 # xmm13 = xmm13[1,0]
vfmadd231sd %xmm12, %xmm12, %xmm13 # xmm13 = (xmm12 * xmm12) + xmm13
vfmadd231sd %xmm10, %xmm10, %xmm13 # xmm13 = (xmm10 * xmm10) + xmm13
vmulsd %xmm13, %xmm13, %xmm14
vcmpgtsd %xmm7, %xmm13, %k1
vmulsd %xmm14, %xmm13, %xmm14
vmulsd %xmm14, %xmm14, %xmm16
vfmadd213sd %xmm5, %xmm14, %xmm15 # xmm15 = (xmm14 * xmm15) + xmm5
vmulsd %xmm16, %xmm13, %xmm14
vdivsd %xmm14, %xmm15, %xmm14
vmovapd (%rax), %xmm15
vmulsd %xmm6, %xmm14, %xmm14
vmovsd %xmm8, %xmm14, %xmm14 {%k1}
vmovddup %xmm14, %xmm13          # xmm13 = xmm14[0,0]
vfmadd231pd %xmm12, %xmm13, %xmm15 # xmm15 = (xmm13 * xmm12) + xmm15
vmovapd %xmm15, (%rax)
vmovsd 0x10(%rax), %xmm15
vfmadd231sd %xmm10, %xmm14, %xmm15 # xmm15 = (xmm14 * xmm10) + xmm15
vmovsd %xmm15, 0x10(%rax)
vfnmadd213pd (%rdx,%r14), %xmm13, %xmm12 # xmm12 = -(xmm13 * xmm12) + mem
vmovapd %xmm12, (%rdx,%r14)
vfnmadd213sd 0x10(%rdx,%r14), %xmm10, %xmm14 # xmm14 = -(xmm10 * xmm14) + mem
vmovsd %xmm14, 0x10(%rdx,%r14)
cmpq %rcx, %rdi
jne 0x3a68
movq -0x10(%rsp), %r8
incq %r8
cmpq -0x30(%rsp), %r8
jne 0x3676
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq