// File: /workspace/github_cpp_makefile_star2_O3/kaityo256[P]lj_simd/force_aos.cpp
// Function: force_sorted_z_avx2_swp()
void
force_sorted_z_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 *)(&z[i][X]));
    v4df vpi = _mm256_load_pd((double *)(&z[i][PX]));
    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 *)(&z[j_1][X]));
    v4df vqj_2 = _mm256_load_pd((double *)(&z[j_2][X]));
    v4df vqj_3 = _mm256_load_pd((double *)(&z[j_3][X]));
    v4df vqj_4 = _mm256_load_pd((double *)(&z[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 *)(&z[j_1_b][X]));
      vqj_2 = _mm256_load_pd((double *)(&z[j_2_b][X]));
      vqj_3 = _mm256_load_pd((double *)(&z[j_3_b][X]));
      vqj_4 = _mm256_load_pd((double *)(&z[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;
      mask = vcl2 - 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);

      vpi += vdq_1 * vdf_1;
      vpi += vdq_4 * vdf_4;
      vpi += vdq_2 * vdf_2;
      vpi += vdq_3 * vdf_3;
      vpj_1 = _mm256_load_pd((double *)(&z[j_1][PX]));
      vpj_2 = _mm256_load_pd((double *)(&z[j_2][PX]));
      vpj_3 = _mm256_load_pd((double *)(&z[j_3][PX]));
      vpj_4 = _mm256_load_pd((double *)(&z[j_4][PX]));


      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 *)(&z[j_1][PX]), vpj_1);
      _mm256_store_pd((double *)(&z[j_2][PX]), vpj_2);
      _mm256_store_pd((double *)(&z[j_3][PX]), vpj_3);
      _mm256_store_pd((double *)(&z[j_4][PX]), 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);
      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 *)(&z[j_1][PX]));
    vpj_2 = _mm256_load_pd((double *)(&z[j_2][PX]));
    vpj_3 = _mm256_load_pd((double *)(&z[j_3][PX]));
    vpj_4 = _mm256_load_pd((double *)(&z[j_4][PX]));

    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 *)(&z[j_1][PX]), vpj_1);
    _mm256_store_pd((double *)(&z[j_2][PX]), vpj_2);
    _mm256_store_pd((double *)(&z[j_3][PX]), vpj_3);
    _mm256_store_pd((double *)(&z[j_4][PX]), vpj_4);

    _mm256_store_pd((double *)(&z[i][PX]), vpi);

    for (int k = (np / 4) * 4; k < np; k++) {
      const int j = sorted_list[kp + k];
      double dx = z[j][X] - z[i][X];
      double dy = z[j][Y] - z[i][Y];
      double dz = z[j][Z] - z[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;
      z[i][PX] += df * dx;
      z[i][PY] += df * dy;
      z[i][PZ] += df * dz;
      z[j][PX] -= df * dx;
      z[j][PY] -= df * dy;
      z[j][PZ] -= df * dz;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movslq 0x325dd86(%rip), %rax   # 0x3261bc0
movq %rax, -0x30(%rsp)
testq %rax, %rax
jle 0x433c
vbroadcastsd 0x11f7(%rip), %ymm0 # 0x5048
vbroadcastsd 0x11f6(%rip), %ymm1 # 0x5050
vbroadcastsd 0x11dd(%rip), %ymm2 # 0x5040
vmovsd 0x11bd(%rip), %xmm4     # 0x5028
vmovsd 0x11bd(%rip), %xmm5     # 0x5030
vmovsd 0x11bd(%rip), %xmm6     # 0x5038
vmovsd 0x11bd(%rip), %xmm7     # 0x5040
leaq 0x19f3d36(%rip), %rdx   # 0x19f7bc0
leaq 0x90f893f(%rip), %r8    # 0x90fc7d0
vxorpd %xmm3, %xmm3, %xmm3
vxorpd %xmm8, %xmm8, %xmm8
xorl %edi, %edi
leaq 0x8f71f2d(%rip), %rax   # 0x8f75dd0
movq %rdi, %r12
shlq $0x6, %r12
movslq (%rax,%rdi,4), %r11
vmovapd (%r12,%rdx), %ymm9
movl (%r8,%r11,4), %ebp
movl 0x4(%r8,%r11,4), %r9d
movl 0x8(%r8,%r11,4), %r10d
movl 0xc(%r8,%r11,4), %ecx
movslq %ebp, %rbx
movslq %r9d, %r14
movslq %r10d, %r15
movslq %ecx, %r13
movq %rbx, %rax
movq %r14, %rsi
shlq $0x6, %rax
shlq $0x6, %rsi
vmovapd (%rsi,%rdx), %ymm12
vmovapd (%rax,%rdx), %ymm10
movq %r15, %rax
movq %r13, %rsi
shlq $0x6, %rax
shlq $0x6, %rsi
vmovapd (%rax,%rdx), %ymm13
vmovapd (%rsi,%rdx), %ymm14
leaq 0x325dcc6(%rip), %rax   # 0x3261bd0
movslq (%rax,%rdi,4), %rax
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, %xmm14, %ymm12, %ymm17
vinsertf32x4 $0x1, %xmm13, %ymm11, %ymm18
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, %rax
jl 0x3f9c
vmulpd %ymm17, %ymm17, %ymm15
vmulpd %ymm15, %ymm10, %ymm15
vsubpd %ymm10, %ymm2, %ymm10
vdivpd %ymm15, %ymm16, %ymm15
vblendvpd %ymm10, %ymm3, %ymm15, %ymm15
vmovapd 0x20(%r12,%rdx), %ymm10
leal 0x3(%rax), %esi
testq %rax, %rax
movq %rdi, -0x10(%rsp)
movq %r12, -0x28(%rsp)
movq %rax, -0x20(%rsp)
movq %r11, -0x18(%rsp)
cmovnsl %eax, %esi
andl $-0x4, %esi
movl %esi, -0x3c(%rsp)
cmpq $0x8, %rax
jl 0x4178
leaq (%r8,%r11,4), %r11
movl $0x4, %r8d
movl %esi, %eax
movq %rax, -0x8(%rsp)
vbroadcastsd %xmm15, %ymm18
movl (%r11,%r8,4), %eax
movl 0x4(%r11,%r8,4), %edi
vpermpd $0x55, %ymm15, %ymm19   # ymm19 = ymm15[1,1,1,1]
vpermpd $0xaa, %ymm15, %ymm22   # ymm22 = ymm15[2,2,2,2]
vpermpd $0xff, %ymm15, %ymm15   # ymm15 = ymm15[3,3,3,3]
movl 0x8(%r11,%r8,4), %esi
movl 0xc(%r11,%r8,4), %r13d
movslq %ebp, %rbp
movslq %r9d, %r9
movslq %r10d, %r10
movslq %ecx, %rcx
addq $0x4, %r8
shlq $0x6, %rbp
shlq $0x6, %r9
shlq $0x6, %r10
shlq $0x6, %rcx
vfmadd231pd %ymm18, %ymm11, %ymm10 # ymm10 = (ymm11 * ymm18) + ymm10
vfnmadd213pd 0x20(%rbp,%rdx), %ymm11, %ymm18 # ymm18 = -(ymm11 * ymm18) + mem
movslq %eax, %r14
movslq %r13d, %rbx
vfmadd231pd %ymm15, %ymm14, %ymm10 # ymm10 = (ymm14 * ymm15) + ymm10
movq %r14, -0x38(%rsp)
shlq $0x6, %r14
vfnmadd213pd 0x20(%rcx,%rdx), %ymm14, %ymm15 # ymm15 = -(ymm14 * ymm15) + mem
vmovapd (%r14,%rdx), %ymm16
movslq %edi, %r14
movq %r14, %r15
shlq $0x6, %r15
vmovapd (%r15,%rdx), %ymm17
movslq %esi, %r15
vfmadd231pd %ymm19, %ymm12, %ymm10 # ymm10 = (ymm12 * ymm19) + ymm10
vfnmadd213pd 0x20(%r9,%rdx), %ymm12, %ymm19 # ymm19 = -(ymm12 * ymm19) + mem
movq %r15, %r12
shlq $0x6, %r12
vmovapd (%r12,%rdx), %ymm20
movq %rbx, %r12
shlq $0x6, %r12
vmovapd (%r12,%rdx), %ymm21
vfmadd231pd %ymm22, %ymm13, %ymm10 # ymm10 = (ymm13 * ymm22) + ymm10
vfnmadd213pd 0x20(%r10,%rdx), %ymm13, %ymm22 # ymm22 = -(ymm13 * ymm22) + mem
vmovapd %ymm18, 0x20(%rbp,%rdx)
movl %eax, %ebp
vsubpd %ymm9, %ymm17, %ymm18
vsubpd %ymm9, %ymm20, %ymm17
vmovapd %ymm19, 0x20(%r9,%rdx)
vsubpd %ymm9, %ymm16, %ymm19
vsubpd %ymm9, %ymm21, %ymm16
movl %edi, %r9d
vinsertf32x4 $0x1, %xmm16, %ymm18, %ymm14
vunpcklpd %ymm18, %ymm19, %ymm11 # ymm11 = ymm19[0],ymm18[0],ymm19[2],ymm18[2]
vunpcklpd %ymm16, %ymm17, %ymm12 # ymm12 = ymm17[0],ymm16[0],ymm17[2],ymm16[2]
vmovapd %ymm22, 0x20(%r10,%rdx)
vmovapd %ymm15, 0x20(%rcx,%rdx)
vinsertf32x4 $0x1, %xmm17, %ymm19, %ymm15
vinsertf128 $0x1, %xmm12, %ymm11, %ymm13
vperm2f128 $0x31, %ymm12, %ymm11, %ymm11 # ymm11 = ymm11[2,3],ymm12[2,3]
movl %esi, %r10d
movl %r13d, %ecx
vunpckhpd %ymm14, %ymm15, %ymm14 # ymm14 = ymm15[1],ymm14[1],ymm15[3],ymm14[3]
vmulpd %ymm14, %ymm14, %ymm12
vmovapd %ymm0, %ymm14
vfmadd231pd %ymm13, %ymm13, %ymm12 # ymm12 = (ymm13 * ymm13) + ymm12
vfmadd231pd %ymm11, %ymm11, %ymm12 # ymm12 = (ymm11 * ymm11) + ymm12
vmulpd %ymm12, %ymm12, %ymm11
vsubpd %ymm12, %ymm2, %ymm13
vmulpd %ymm11, %ymm12, %ymm11
vfmadd213pd %ymm1, %ymm11, %ymm14 # ymm14 = (ymm11 * ymm14) + ymm1
vmulpd %ymm11, %ymm11, %ymm11
vmulpd %ymm11, %ymm12, %ymm11
vmovapd %ymm18, %ymm12
vdivpd %ymm11, %ymm14, %ymm11
vmovapd %ymm16, %ymm14
vblendvpd %ymm13, %ymm3, %ymm11, %ymm15
vmovapd %ymm19, %ymm11
vmovapd %ymm17, %ymm13
cmpq -0x8(%rsp), %r8
jb 0x3fe2
jmp 0x4198
movq %rbx, -0x38(%rsp)
vmovapd %ymm14, %ymm16
vmovapd %ymm13, %ymm17
vmovapd %ymm12, %ymm18
vmovapd %ymm11, %ymm19
movq %r13, %rbx
movq -0x28(%rsp), %rcx
vbroadcastsd %xmm15, %ymm12
vpermpd $0x55, %ymm15, %ymm13   # ymm13 = ymm15[1,1,1,1]
shlq $0x6, %r14
shlq $0x6, %r15
shlq $0x6, %rbx
vpermpd $0xaa, %ymm15, %ymm14   # ymm14 = ymm15[2,2,2,2]
vpermpd $0xff, %ymm15, %ymm15   # ymm15 = ymm15[3,3,3,3]
movq -0x20(%rsp), %r9
movq -0x18(%rsp), %rdi
leaq 0x90f85ff(%rip), %r8    # 0x90fc7d0
vmovapd 0x20(%r14,%rdx), %ymm21
vmovapd 0x20(%r15,%rdx), %ymm22
vmovapd 0x20(%rbx,%rdx), %ymm23
vfmadd231pd %ymm12, %ymm19, %ymm10 # ymm10 = (ymm19 * ymm12) + ymm10
leaq (%rdx,%rcx), %rax
vmovsd 0x10(%rcx,%rdx), %xmm11
movq -0x38(%rsp), %rcx
vfmadd231pd %ymm13, %ymm18, %ymm10 # ymm10 = (ymm18 * ymm13) + ymm10
vfnmadd231pd %ymm13, %ymm18, %ymm21 # ymm21 = -(ymm18 * ymm13) + ymm21
vfnmadd231pd %ymm14, %ymm17, %ymm22 # ymm22 = -(ymm17 * ymm14) + ymm22
vfnmadd231pd %ymm15, %ymm16, %ymm23 # ymm23 = -(ymm16 * ymm15) + ymm23
shlq $0x6, %rcx
vfmadd231pd %ymm14, %ymm17, %ymm10 # ymm10 = (ymm17 * ymm14) + ymm10
vmovapd 0x20(%rcx,%rdx), %ymm20
vfmadd231pd %ymm15, %ymm16, %ymm10 # ymm10 = (ymm16 * ymm15) + ymm10
vfnmadd231pd %ymm12, %ymm19, %ymm20 # ymm20 = -(ymm19 * ymm12) + ymm20
vmovapd %ymm20, 0x20(%rcx,%rdx)
movl -0x3c(%rsp), %ecx
vmovapd %ymm21, 0x20(%r14,%rdx)
vmovapd %ymm22, 0x20(%r15,%rdx)
vmovapd %ymm23, 0x20(%rbx,%rdx)
vmovapd %ymm10, 0x20(%rax)
cmpl %r9d, %ecx
jge 0x4329
movslq %ecx, %rcx
addq %rcx, %rdi
subq %rcx, %r9
xorl %ecx, %ecx
shlq $0x2, %rdi
leaq (%rdi,%rcx,4), %rsi
vmovapd %xmm4, %xmm15
incq %rcx
movslq (%r8,%rsi), %rsi
shlq $0x6, %rsi
vmovapd (%rsi,%rdx), %xmm12
vmovsd 0x10(%rsi,%rdx), %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 0x20(%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, 0x20(%rax)
vmovsd 0x30(%rax), %xmm15
vfmadd231sd %xmm10, %xmm14, %xmm15 # xmm15 = (xmm14 * xmm10) + xmm15
vmovsd %xmm15, 0x30(%rax)
vfnmadd213pd 0x20(%rsi,%rdx), %xmm13, %xmm12 # xmm12 = -(xmm13 * xmm12) + mem
vmovapd %xmm12, 0x20(%rsi,%rdx)
vfnmadd213sd 0x30(%rsi,%rdx), %xmm10, %xmm14 # xmm14 = -(xmm10 * xmm14) + mem
vmovsd %xmm14, 0x30(%rsi,%rdx)
cmpq %rcx, %r9
jne 0x4275
movq -0x10(%rsp), %rdi
incq %rdi
cmpq -0x30(%rsp), %rdi
jne 0x3e9c
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq