// File: /workspace/github_c_makefile_star2_O3/baileywjohnson[P]mpi-matrix-mult/MyMPI.c
// Function: read_col_striped_matrix
void read_col_striped_matrix (
      char         *s,       /* IN - File name */
      void      ***subs,     /* OUT - 2-D array */
      void       **storage,  /* OUT - Array elements */
      MPI_Datatype dtype,    /* IN - Element type */
      int         *m,        /* OUT - Rows */
      int         *n,        /* OUT - Cols */
      MPI_Comm     comm)     /* IN - Communicator */
{
   void      *buffer;        /* File buffer */
   int        datum_size;    /* Size of matrix element */
   int        i; // WMJ , j;
   int        id;            /* Process rank */
   FILE      *infileptr;     /* Input file ptr */
   int        local_cols;    /* Cols on this process */
   void     **lptr;          /* Pointer into 'subs' */
   void      *rptr;          /* Pointer into 'storage' */
   int        p;             /* Number of processes */
   int       *send_count;    /* Each proc's count */
   int       *send_disp;     /* Each proc's displacement */

   MPI_Comm_size (comm, &p);
   MPI_Comm_rank (comm, &id);
   datum_size = get_size (dtype);

   /* Process p-1 opens file, gets number of rows and
      cols, and broadcasts this info to other procs. */

   if (id == (p-1)) {
      infileptr = fopen (s, "r");
      if (infileptr == NULL) *m = 0;
      else {
         fread (m, sizeof(int), 1, infileptr);
         fread (n, sizeof(int), 1, infileptr);
      }
   }
   MPI_Bcast (m, 1, MPI_INT, p-1, comm);

   if (!(*m)) MPI_Abort (comm, OPEN_FILE_ERROR);

   MPI_Bcast (n, 1, MPI_INT, p-1, comm);

   local_cols = BLOCK_SIZE(id,p,*n);

   /* Dynamically allocate two-dimensional matrix 'subs' */

   *storage = my_malloc (id, *m * local_cols * datum_size);
   *subs = (void **) my_malloc (id, *m * PTR_SIZE);
   lptr = (void *) *subs;
   rptr = (void *) *storage;
   for (i = 0; i < *m; i++) {
      *(lptr++) = (void *) rptr;
      rptr += local_cols * datum_size;
   }

   /* Process p-1 reads in the matrix one row at a time and
      distributes each row among the MPI processes. */

   if (id == (p-1))
      buffer = my_malloc (id, *n * datum_size);
   create_mixed_xfer_arrays (id,p,*n,&send_count,&send_disp);
   for (i = 0; i < *m; i++) {
      if (id == (p-1))
         fread (buffer, datum_size, *n, infileptr);
      MPI_Scatterv (buffer, send_count, send_disp, dtype,
         (*storage)+i*local_cols*datum_size, local_cols,
         dtype, p-1, comm);
   }
   free (send_count);
   free (send_disp);
   if (id == (p-1)) free (buffer);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x20(%rsp)
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, 0x28(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
movq 0x90(%rsp), %r13
leaq 0xc(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x1100
leaq 0x10(%rsp), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x1170
movq %r15, 0x40(%rsp)
movq %r15, %rdi
callq 0x1b80
movl %eax, %r13d
movl (%r14), %eax
decl %eax
cmpl %eax, (%r12)
movq %rbp, %r12
jne 0x22d1
leaq 0x1ef5(%rip), %rsi      # 0x4172
movq %rbx, %rdi
callq 0x10c0
testq %rax, %rax
je 0x22c0
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rax, %rbx
movq %rax, %rcx
callq 0x1160
movl $0x4, %esi
movl $0x1, %edx
movq 0x20(%rsp), %rdi
movq %rbx, 0x38(%rsp)
movq %rbx, %rcx
callq 0x1160
jmp 0x22d1
movl $0x0, (%r12)
movq $0x0, 0x38(%rsp)
movl 0xc(%rsp), %ecx
decl %ecx
movq 0x3cca(%rip), %rdx      # 0x5fa8
movq %r12, %rdi
movl $0x1, %esi
movq 0x90(%rsp), %rbx
movq %rbx, %r8
callq 0x1180
cmpl $0x0, (%r12)
jne 0x230a
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x1120
movl 0xc(%rsp), %ecx
decl %ecx
movq 0x3c91(%rip), %rdx      # 0x5fa8
movq 0x20(%rsp), %r14
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %r8
callq 0x1180
movl 0x10(%rsp), %edi
leal 0x1(%rdi), %eax
movl (%r14), %ecx
imull %ecx, %eax
movl 0xc(%rsp), %esi
cltd
idivl %esi
movl %eax, %r8d
imull %edi, %ecx
movl %ecx, %eax
cltd
idivl %esi
subl %eax, %r8d
movl %r8d, 0x34(%rsp)
imull %r13d, %r8d
movl (%r12), %esi
movl %r8d, 0x14(%rsp)
imull %r8d, %esi
callq 0x1bf2
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
movl 0x10(%rsp), %edi
movl (%r12), %esi
shll $0x3, %esi
callq 0x1bf2
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movl (%r12), %ecx
testl %ecx, %ecx
jle 0x23ae
movq 0x28(%rsp), %rdx
movq (%rdx), %rdx
movslq 0x14(%rsp), %rsi
xorl %edi, %edi
movq %rdx, (%rax,%rdi,8)
addq %rsi, %rdx
incq %rdi
cmpl %edi, %ecx
jne 0x23a0
movl 0x10(%rsp), %edi
movl 0xc(%rsp), %esi
leal -0x1(%rsi), %eax
cmpl %eax, %edi
jne 0x23d6
movl (%r14), %esi
imull %r13d, %esi
callq 0x1bf2
movq %rax, %rbp
movl 0x10(%rsp), %edi
movl 0xc(%rsp), %esi
jmp 0x23d6
movl (%r14), %edx
leaq 0x50(%rsp), %rbx
leaq 0x48(%rsp), %r14
movq %rbx, %rcx
movq %r14, %r8
callq 0x1c72
movq %r12, %r15
cmpl $0x0, (%r12)
movq (%rbx), %r12
movq (%r14), %rbx
jle 0x2483
movslq %r13d, %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
movl 0xc(%rsp), %eax
decl %eax
cmpl %eax, 0x10(%rsp)
jne 0x243c
movq 0x20(%rsp), %rax
movslq (%rax), %rdx
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq 0x38(%rsp), %rcx
callq 0x1160
movl 0xc(%rsp), %eax
decl %eax
movslq %r14d, %r14
movq 0x28(%rsp), %rcx
movq (%rcx), %r8
addq %r14, %r8
subq $0x8, %rsp
movq %rbp, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq 0x48(%rsp), %rcx
movl 0x3c(%rsp), %r9d
pushq 0x98(%rsp)
pushq %rax
pushq %rcx
callq 0x10e0
addq $0x20, %rsp
incq %r13
movslq (%r15), %rax
addl 0x14(%rsp), %r14d
cmpq %rax, %r13
jl 0x2410
movq %r12, %rdi
callq 0x10f0
movq %rbx, %rdi
callq 0x10f0
movl 0xc(%rsp), %eax
decl %eax
cmpl %eax, 0x10(%rsp)
jne 0x24a7
movq %rbp, %rdi
callq 0x10f0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq