// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, 0x30(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
movq 0x90(%rsp), %r13
leaq 0x8(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x1100
leaq 0xc(%rsp), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x1170
movq %r15, 0x40(%rsp)
movq %r15, %rdi
callq 0x1b5c
movl %eax, %r13d
movl (%r14), %eax
decl %eax
cmpl %eax, (%r12)
jne 0x224c
leaq 0x1f75(%rip), %rsi      # 0x4172
movq %rbx, %rdi
callq 0x10c0
testq %rax, %rax
je 0x223f
pushq $0x4
popq %rbx
pushq $0x1
popq %r14
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %r15
movq %rax, %rcx
callq 0x1160
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, 0x28(%rsp)
movq %r15, %rcx
callq 0x1160
jmp 0x224c
andl $0x0, (%rbp)
movq $0x0, 0x28(%rsp)
movl 0x8(%rsp), %ecx
decl %ecx
movq 0x3d4f(%rip), %rdx      # 0x5fa8
pushq $0x1
popq %rsi
movq %rbp, %rdi
movq 0x90(%rsp), %rbx
movq %rbx, %r8
callq 0x1180
cmpl $0x0, (%rbp)
jne 0x2280
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x1120
movl 0x8(%rsp), %ecx
decl %ecx
movq 0x3d1b(%rip), %rdx      # 0x5fa8
pushq $0x1
popq %rsi
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %r8
callq 0x1180
movl 0xc(%rsp), %edi
leal 0x1(%rdi), %eax
movl (%r14), %ecx
imull %ecx, %eax
movl 0x8(%rsp), %esi
cltd
idivl %esi
movl %eax, %r8d
imull %edi, %ecx
movl %ecx, %eax
cltd
idivl %esi
subl %eax, %r8d
movl %r8d, 0x24(%rsp)
movl %r8d, %r15d
imull %r13d, %r15d
movl (%rbp), %esi
imull %r15d, %esi
callq 0x1bc5
movq 0x30(%rsp), %rbx
movq %rax, (%rbx)
movl 0xc(%rsp), %edi
movl (%rbp), %esi
shll $0x3, %esi
callq 0x1bc5
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq (%rbx), %rcx
movl (%rbp), %edx
movl %r15d, 0x18(%rsp)
movslq %r15d, %rsi
xorl %edi, %edi
cmpl %edx, %edi
jge 0x2319
movq %rcx, (%rax,%rdi,8)
addq %rsi, %rcx
incq %rdi
jmp 0x2309
movq %rbp, %r15
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %esi
leal -0x1(%rsi), %eax
cmpl %eax, %edi
jne 0x2344
movl (%r14), %esi
imull %r13d, %esi
callq 0x1bc5
movq %rax, %rbp
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %esi
jmp 0x2344
movl (%r14), %edx
leaq 0x50(%rsp), %rbx
leaq 0x48(%rsp), %r14
movq %rbx, %rcx
movq %r14, %r8
callq 0x1c41
movslq %r13d, %rax
movq %rax, 0x38(%rsp)
movq (%rbx), %r12
movq (%r14), %rbx
xorl %r14d, %r14d
xorl %r13d, %r13d
movslq (%r15), %rax
cmpq %rax, %r13
jge 0x23e5
movl 0x8(%rsp), %eax
decl %eax
cmpl %eax, 0xc(%rsp)
jne 0x23a4
movq 0x10(%rsp), %rax
movslq (%rax), %rdx
movq %rbp, %rdi
movq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rcx
callq 0x1160
movl 0x8(%rsp), %eax
decl %eax
movslq %r14d, %r14
movq 0x30(%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 0x2c(%rsp), %r9d
pushq 0x98(%rsp)
pushq %rax
pushq %rcx
callq 0x10e0
addq $0x20, %rsp
incq %r13
addl 0x18(%rsp), %r14d
jmp 0x2370
movq %r12, %rdi
callq 0x10f0
movq %rbx, %rdi
callq 0x10f0
movl 0x8(%rsp), %eax
decl %eax
cmpl %eax, 0xc(%rsp)
jne 0x2409
movq %rbp, %rdi
callq 0x10f0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq