// File: /workspace/github_cpp_makefile_star2_O3/Kingsford-Group[P]ghost2/include/Eigen/src/Core/products/GeneralMatrixMatrix.h
// Function: Eigen::internal::general_matrix_matrix_product<long, double, 0, false, double, 0, false, 0>::run(long, long, long, double const*, long, double const*, long, double*, long, double, Eigen::internal::level3_blocking<double, double>&, Eigen::internal::GemmParallelInfo<long>*)
static void run(Index rows, Index cols, Index depth,
  const LhsScalar* _lhs, Index lhsStride,
  const RhsScalar* _rhs, Index rhsStride,
  ResScalar* res, Index resStride,
  ResScalar alpha,
  level3_blocking<LhsScalar,RhsScalar>& blocking,
  GemmParallelInfo<Index>* info = 0)
{
  const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> lhs(_lhs,lhsStride);
  const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> rhs(_rhs,rhsStride);

  typedef gebp_traits<LhsScalar,RhsScalar> Traits;

  Index kc = blocking.kc();                   // cache block size along the K direction
  Index mc = (std::min)(rows,blocking.mc());  // cache block size along the M direction
  //Index nc = blocking.nc(); // cache block size along the N direction

  gemm_pack_lhs<LhsScalar, Index, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs;
  gemm_pack_rhs<RhsScalar, Index, Traits::nr, RhsStorageOrder> pack_rhs;
  gebp_kernel<LhsScalar, RhsScalar, Index, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp;

#ifdef EIGEN_HAS_OPENMP
  if(info)
  {
    // this is the parallel version!
    Index tid = omp_get_thread_num();
    Index threads = omp_get_num_threads();
    
    std::size_t sizeA = kc*mc;
    std::size_t sizeW = kc*Traits::WorkSpaceFactor;
    ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, 0);
    ei_declare_aligned_stack_constructed_variable(RhsScalar, w, sizeW, 0);
    
    RhsScalar* blockB = blocking.blockB();
    eigen_internal_assert(blockB!=0);

    // For each horizontal panel of the rhs, and corresponding vertical panel of the lhs...
    for(Index k=0; k<depth; k+=kc)
    {
      const Index actual_kc = (std::min)(k+kc,depth)-k; // => rows of B', and cols of the A'

      // In order to reduce the chance that a thread has to wait for the other,
      // let's start by packing A'.
      pack_lhs(blockA, &lhs(0,k), lhsStride, actual_kc, mc);

      // Pack B_k to B' in a parallel fashion:
      // each thread packs the sub block B_k,j to B'_j where j is the thread id.

      // However, before copying to B'_j, we have to make sure that no other thread is still using it,
      // i.e., we test that info[tid].users equals 0.
      // Then, we set info[tid].users to the number of threads to mark that all other threads are going to use it.
      while(info[tid].users!=0) {}
      info[tid].users += threads;

      pack_rhs(blockB+info[tid].rhs_start*actual_kc, &rhs(k,info[tid].rhs_start), rhsStride, actual_kc, info[tid].rhs_length);

      // Notify the other threads that the part B'_j is ready to go.
      info[tid].sync = k;

      // Computes C_i += A' * B' per B'_j
      for(Index shift=0; shift<threads; ++shift)
      {
        Index j = (tid+shift)%threads;

        // At this point we have to make sure that B'_j has been updated by the thread j,
        // we use testAndSetOrdered to mimic a volatile access.
        // However, no need to wait for the B' part which has been updated by the current thread!
        if(shift>0)
          while(info[j].sync!=k) {}

        gebp(res+info[j].rhs_start*resStride, resStride, blockA, blockB+info[j].rhs_start*actual_kc, mc, actual_kc, info[j].rhs_length, alpha, -1,-1,0,0, w);
      }

      // Then keep going as usual with the remaining A'
      for(Index i=mc; i<rows; i+=mc)
      {
        const Index actual_mc = (std::min)(i+mc,rows)-i;

        // pack A_i,k to A'
        pack_lhs(blockA, &lhs(i,k), lhsStride, actual_kc, actual_mc);

        // C_i += A' * B'
        gebp(res+i, resStride, blockA, blockB, actual_mc, actual_kc, cols, alpha, -1,-1,0,0, w);
      }

      // Release all the sub blocks B'_j of B' for the current thread,
      // i.e., we simply decrement the number of users by 1
      for(Index j=0; j<threads; ++j)
        #pragma omp atomic
        --(info[j].users);
    }
  }
  else
#endif // EIGEN_HAS_OPENMP
  {
    EIGEN_UNUSED_VARIABLE(info);

    // this is the sequential version!
    std::size_t sizeA = kc*mc;
    std::size_t sizeB = kc*cols;
    std::size_t sizeW = kc*Traits::WorkSpaceFactor;

    ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA());
    ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB());
    ei_declare_aligned_stack_constructed_variable(RhsScalar, blockW, sizeW, blocking.blockW());

    // For each horizontal panel of the rhs, and corresponding panel of the lhs...
    // (==GEMM_VAR1)
    for(Index k2=0; k2<depth; k2+=kc)
    {
      const Index actual_kc = (std::min)(k2+kc,depth)-k2;

      // OK, here we have selected one horizontal panel of rhs and one vertical panel of lhs.
      // => Pack rhs's panel into a sequential chunk of memory (L2 caching)
      // Note that this panel will be read as many times as the number of blocks in the lhs's
      // vertical panel which is, in practice, a very low number.
      pack_rhs(blockB, &rhs(k2,0), rhsStride, actual_kc, cols);

      // For each mc x kc block of the lhs's vertical panel...
      // (==GEPP_VAR1)
      for(Index i2=0; i2<rows; i2+=mc)
      {
        const Index actual_mc = (std::min)(i2+mc,rows)-i2;

        // We pack the lhs's block into a sequential chunk of memory (L1 caching)
        // Note that this block will be read a very high number of times, which is equal to the number of
        // micro vertical panel of the large rhs's panel (e.g., cols/4 times).
        pack_lhs(blockA, &lhs(i2,k2), lhsStride, actual_kc, actual_mc);

        // Everything is packed, we can now call the block * panel kernel:
        gebp(res+i2, resStride, blockA, blockB, actual_mc, actual_kc, cols, alpha, -1, -1, 0, 0, blockW);
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movsd %xmm0, -0xd8(%rbp)
movq %r9, -0xb8(%rbp)
movq %r8, -0xa0(%rbp)
movq %rdx, %r13
movq %rsi, -0x78(%rbp)
movq 0x28(%rbp), %rbx
movq 0x18(%rbx), %r14
movq 0x28(%rbx), %rdx
cmpq %rdi, %r14
movq %rdi, -0xe8(%rbp)
cmovgeq %rdi, %r14
movq %r14, -0x70(%rbp)
imulq %rdx, %r14
movq %r14, %rax
shrq $0x3d, %rax
jne 0x41059
movq %rcx, %r12
movq (%rbx), %rax
testq %rax, %rax
je 0x40cdd
movq %rax, -0x60(%rbp)
movq $0x0, -0x40(%rbp)
jmp 0x40d25
leaq (,%r14,8), %rdi
cmpq $0x9c4, %r14            # imm = 0x9C4
ja 0x40d09
movq %rsp, %rcx
addq $0xf, %rdi
andq $-0x10, %rdi
subq %rdi, %rcx
movq %rcx, %rsp
movq %rcx, -0x40(%rbp)
movq %rcx, -0x60(%rbp)
jmp 0x40d25
movq %rdx, %r15
callq 0xc750
movq %r15, %rdx
movq %rax, -0x60(%rbp)
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x41059
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
movq %rdx, %r15
imulq -0x78(%rbp), %r15
cmpq %rax, %r15
ja 0x41087
movq 0x8(%rbx), %rax
movq %rax, -0x50(%rbp)
testq %rax, %rax
je 0x40d57
movq $0x0, -0x38(%rbp)
jmp 0x40da1
leaq (,%r15,8), %rdi
cmpq $0x9c4, %r15            # imm = 0x9C4
ja 0x40d83
movq %rsp, %rcx
addq $0xf, %rdi
andq $-0x10, %rdi
subq %rdi, %rcx
movq %rcx, %rsp
movq %rcx, -0x38(%rbp)
movq %rcx, -0x50(%rbp)
jmp 0x40da1
movq %rdx, -0x58(%rbp)
callq 0xc750
movq -0x58(%rbp), %rdx
movq %rax, -0x50(%rbp)
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x410e3
movabsq $0x1c00000000000000, %rax # imm = 0x1C00000000000000
testq %rax, %rdx
jne 0x410b5
movq 0x10(%rbx), %rax
movq %rdx, %rdi
shlq $0x6, %rdi
movq %rax, -0x68(%rbp)
testq %rax, %rax
movq %r14, -0x98(%rbp)
movq %r15, -0x90(%rbp)
je 0x40ded
cmpq $0x4e21, %rdi           # imm = 0x4E21
setae %al
movl %eax, -0x2c(%rbp)
movq $0x0, -0x48(%rbp)
jmp 0x40e39
cmpq $0x4e20, %rdi           # imm = 0x4E20
ja 0x40e18
movq %rsp, %rcx
addq $0xf, %rdi
andq $-0x10, %rdi
subq %rdi, %rcx
movq %rcx, %rsp
movl $0x0, -0x2c(%rbp)
movq %rcx, -0x48(%rbp)
movq %rcx, -0x68(%rbp)
jmp 0x40e39
movq %rdx, %rbx
callq 0xc750
testq %rax, %rax
je 0x41111
movb $0x1, %cl
movl %ecx, -0x2c(%rbp)
movq %rax, -0x48(%rbp)
movq %rax, -0x68(%rbp)
movq %rbx, %rdx
testq %r13, %r13
jle 0x4100c
movq %rdx, %rax
imulq -0xa0(%rbp), %rax
shlq $0x3, %rax
movq %rax, -0xa8(%rbp)
movq -0x70(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0xd0(%rbp)
xorl %eax, %eax
xorps %xmm0, %xmm0
movq %r13, -0xb0(%rbp)
movq %rdx, -0x58(%rbp)
movq -0x60(%rbp), %r15
leaq (%rax,%rdx), %rcx
cmpq %r13, %rcx
movq %rcx, -0xc8(%rbp)
cmovlq %rcx, %r13
subq %rax, %r13
movq -0xb8(%rbp), %rcx
leaq (%rcx,%rax,8), %rdx
subq $0x10, %rsp
movups %xmm0, (%rsp)
leaq -0x2e(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq 0x10(%rbp), %rcx
movq %r13, -0xe0(%rbp)
movq %r13, %r8
movq -0x78(%rbp), %r9
callq 0x4119c
addq $0x10, %rsp
movq 0x18(%rbp), %rdx
xorl %r13d, %r13d
movq -0x70(%rbp), %r14
movq %r12, -0xc0(%rbp)
xorl %ecx, %ecx
movq -0xe8(%rbp), %rax
cmpq %r14, %rax
movq %r14, %rbx
cmovlq %rax, %rbx
cmpq %rax, %rcx
jge 0x40fe0
addq %r13, %rbx
subq $0x10, %rsp
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
leaq -0x2f(%rbp), %rdi
movq %rdx, -0xf0(%rbp)
movq %r15, %rsi
movq %r14, -0x80(%rbp)
movq %r12, %rdx
movq %rcx, -0x88(%rbp)
movq -0xa0(%rbp), %rcx
movq -0xe0(%rbp), %r14
movq %r14, %r8
movq %rbx, %r9
callq 0x412f6
movq -0xf0(%rbp), %rsi
movq -0x88(%rbp), %rcx
movq -0x80(%rbp), %rdx
addq $0x10, %rsp
movq -0x70(%rbp), %rax
addq %rax, %rcx
movq %rcx, -0x88(%rbp)
movq -0xd0(%rbp), %rcx
addq %rcx, %r12
addq %rax, %rdx
subq %rax, %r13
leaq (%rsi,%rcx), %rax
movq %rax, -0x80(%rbp)
subq $0x40, %rsp
movq -0x68(%rbp), %rax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsp)
movq $-0x1, %rax
movq %rax, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq -0x78(%rbp), %rax
movq %rax, 0x8(%rsp)
movq %r14, (%rsp)
leaq -0x2d(%rbp), %rdi
movq %rdx, %r14
movq 0x20(%rbp), %rdx
movq %r15, %rcx
movq -0x50(%rbp), %r8
movq %rbx, %r9
movsd -0xd8(%rbp), %xmm0
callq 0x41414
movq -0x88(%rbp), %rcx
addq $0x40, %rsp
movq -0x80(%rbp), %rdx
jmp 0x40ede
movq -0xc0(%rbp), %r12
addq -0xa8(%rbp), %r12
movq -0xb0(%rbp), %r13
movq -0xc8(%rbp), %rax
cmpq %r13, %rax
movq -0x58(%rbp), %rdx
xorps %xmm0, %xmm0
jl 0x40e7f
cmpb $0x0, -0x2c(%rbp)
je 0x4101b
movq -0x48(%rbp), %rdi
callq 0xc660
cmpq $0x9c5, -0x90(%rbp) # imm = 0x9C5
movq -0x98(%rbp), %rbx
jb 0x41038
movq -0x38(%rbp), %rdi
callq 0xc660
cmpq $0x9c5, %rbx            # imm = 0x9C5
jb 0x4104a
movq -0x40(%rbp), %rdi
callq 0xc660
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0xc260
movq 0x36f06(%rip), %rcx     # 0x77f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36f28(%rip), %rsi     # 0x77fa0
movq 0x36ec1(%rip), %rdx     # 0x77f40
movq %rax, %rdi
callq 0xc990
movl $0x8, %edi
callq 0xc260
movq 0x36ed8(%rip), %rcx     # 0x77f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36efa(%rip), %rsi     # 0x77fa0
movq 0x36e93(%rip), %rdx     # 0x77f40
movq %rax, %rdi
callq 0xc990
movl $0x8, %edi
callq 0xc260
movq 0x36eaa(%rip), %rcx     # 0x77f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36ecc(%rip), %rsi     # 0x77fa0
movq 0x36e65(%rip), %rdx     # 0x77f40
movq %rax, %rdi
callq 0xc990
movl $0x8, %edi
callq 0xc260
movq 0x36e7c(%rip), %rcx     # 0x77f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36e9e(%rip), %rsi     # 0x77fa0
movq 0x36e37(%rip), %rdx     # 0x77f40
movq %rax, %rdi
callq 0xc990
movl $0x8, %edi
callq 0xc260
movq 0x36e4e(%rip), %rcx     # 0x77f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36e70(%rip), %rsi     # 0x77fa0
movq 0x36e09(%rip), %rdx     # 0x77f40
movq %rax, %rdi
callq 0xc990
jmp 0x41143
jmp 0x41148
movq %rax, %rbx
jmp 0x4116f
movq %rax, %rbx
jmp 0x41181
jmp 0x4114f
movq %rax, %rbx
cmpb $0x0, -0x2c(%rbp)
movq -0x98(%rbp), %r14
movq -0x90(%rbp), %r15
movq -0x48(%rbp), %rdi
je 0x4116f
callq 0xc660
cmpq $0x9c5, %r15            # imm = 0x9C5
jb 0x41181
movq -0x38(%rbp), %rdi
callq 0xc660
cmpq $0x9c5, %r14            # imm = 0x9C5
jb 0x41193
movq -0x40(%rbp), %rdi
callq 0xc660
movq %rbx, %rdi
callq 0xc9c0
nop