// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rcx, %r15
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
movq 0x90(%rsp), %rbp
leaq 0x8(%rsp), %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1100
leaq 0xc(%rsp), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1170
movq %r15, 0x50(%rsp)
movq %r15, %rdi
callq 0x1b74
movl %eax, %r15d
movl (%r14), %eax
decl %eax
cmpl %eax, (%r12)
jne 0x22ca
leaq 0x1efc(%rip), %rsi      # 0x4172
movq %rbx, %rdi
callq 0x10c0
testq %rax, %rax
je 0x22b9
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %rax, %rbx
movq %rax, %rcx
callq 0x1160
movl $0x4, %esi
movl $0x1, %edx
movq 0x10(%rsp), %rdi
movq %rbx, 0x38(%rsp)
movq %rbx, %rcx
callq 0x1160
jmp 0x22ca
movl $0x0, (%r13)
movq $0x0, 0x38(%rsp)
movl 0x8(%rsp), %ecx
decl %ecx
movq 0x3cd1(%rip), %rdx      # 0x5fa8
movq %r13, %rdi
movl $0x1, %esi
movq %rbp, %r8
callq 0x1180
cmpl $0x0, (%r13)
jne 0x22fb
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x1120
movl 0x8(%rsp), %ecx
decl %ecx
movq 0x3ca0(%rip), %rdx      # 0x5fa8
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0x1, %esi
movq %rbp, %r8
callq 0x1180
movl 0xc(%rsp), %edi
leal 0x1(%rdi), %eax
movl (%rbx), %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, 0x34(%rsp)
imull %r15d, %r8d
movl (%r13), %esi
movl %r8d, 0x1c(%rsp)
imull %r8d, %esi
callq 0x1be6
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
movl 0xc(%rsp), %edi
movl (%r13), %esi
shll $0x3, %esi
callq 0x1be6
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
movl (%r13), %ecx
testl %ecx, %ecx
jle 0x239e
movq 0x28(%rsp), %rdx
movq (%rdx), %rdx
movslq 0x1c(%rsp), %rsi
xorl %edi, %edi
movq %rdx, (%rax,%rdi,8)
addq %rsi, %rdx
incq %rdi
cmpl %edi, %ecx
jne 0x2390
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %eax
decl %eax
cmpl %eax, %edi
jne 0x23bf
movq 0x10(%rsp), %rax
movl (%rax), %esi
imull %r15d, %esi
callq 0x1be6
movq %rax, %rbp
movl %r15d, %ebx
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rax
movl (%rax), %edx
leaq 0x48(%rsp), %rcx
leaq 0x40(%rsp), %r8
callq 0x1c66
cmpl $0x0, (%r13)
jle 0x2477
movq %r13, %r15
movslq %ebx, %rax
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %r12
movq 0x40(%rsp), %r14
xorl %ebx, %ebx
xorl %r13d, %r13d
movl 0x8(%rsp), %eax
decl %eax
cmpl %eax, 0xc(%rsp)
jne 0x242b
movq 0x10(%rsp), %rax
movslq (%rax), %rdx
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rcx
callq 0x1160
movslq %ebx, %rbx
movq 0x28(%rsp), %rax
movq (%rax), %r8
addq %rbx, %r8
movl 0x8(%rsp), %eax
decl %eax
subq $0x8, %rsp
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq 0x58(%rsp), %rcx
movl 0x3c(%rsp), %r9d
pushq 0x98(%rsp)
pushq %rax
pushq %rcx
callq 0x10e0
addq $0x20, %rsp
incq %r13
movslq (%r15), %rax
addl 0x1c(%rsp), %ebx
cmpq %rax, %r13
jl 0x2405
movq 0x48(%rsp), %rdi
callq 0x10f0
movq 0x40(%rsp), %rdi
callq 0x10f0
movl 0x8(%rsp), %eax
decl %eax
cmpl %eax, 0xc(%rsp)
jne 0x249f
movq %rbp, %rdi
callq 0x10f0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq