// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq 0x10(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x10f0
movq 0x10(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x1160
movq -0x20(%rbp), %rdi
callq 0x1f70
movl %eax, -0x3c(%rbp)
movl -0x44(%rbp), %eax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x28a1
movq -0x8(%rbp), %rdi
leaq 0x1949(%rip), %rsi      # 0x419e
callq 0x10b0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x2871
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
jmp 0x289f
movq -0x28(%rbp), %rdi
movq -0x50(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x1150
movq -0x30(%rbp), %rdi
movq -0x50(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x1150
jmp 0x28a1
movq -0x28(%rbp), %rdi
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
movq 0x10(%rbp), %r8
movl $0x1, %esi
movq 0x36ed(%rip), %rdx      # 0x5fa8
callq 0x1170
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x28d7
movq 0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x30(%rbp), %rdi
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
movq 0x10(%rbp), %r8
movl $0x1, %esi
movq 0x36b7(%rip), %rdx      # 0x5fa8
callq 0x1170
movl -0x44(%rbp), %eax
addl $0x1, %eax
movq -0x30(%rbp), %rcx
imull (%rcx), %eax
cltd
idivl -0x6c(%rbp)
subl $0x1, %eax
movl %eax, -0x84(%rbp)
movl -0x44(%rbp), %eax
movq -0x30(%rbp), %rcx
imull (%rcx), %eax
cltd
idivl -0x6c(%rbp)
movl %eax, %ecx
movl -0x84(%rbp), %eax
subl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x44(%rbp), %edi
movq -0x28(%rbp), %rax
movl (%rax), %esi
imull -0x54(%rbp), %esi
imull -0x3c(%rbp), %esi
callq 0x2020
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x44(%rbp), %edi
movq -0x28(%rbp), %rax
movslq (%rax), %rax
shlq $0x3, %rax
movl %eax, %esi
callq 0x2020
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x29cb
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x60(%rbp)
movq %rcx, (%rax)
movl -0x54(%rbp), %ecx
imull -0x3c(%rbp), %ecx
movq -0x68(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x298a
movl -0x44(%rbp), %eax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x29ee
movl -0x44(%rbp), %edi
movq -0x30(%rbp), %rax
movl (%rax), %esi
imull -0x3c(%rbp), %esi
callq 0x2020
movq %rax, -0x38(%rbp)
movl -0x44(%rbp), %edi
movl -0x6c(%rbp), %esi
movq -0x30(%rbp), %rax
movl (%rax), %edx
leaq -0x78(%rbp), %rcx
leaq -0x80(%rbp), %r8
callq 0x20d0
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x2a9e
movl -0x44(%rbp), %eax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2a42
movq -0x38(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
movq -0x30(%rbp), %rax
movslq (%rax), %rdx
movq -0x50(%rbp), %rcx
callq 0x1150
movq -0x38(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %r8
movl -0x40(%rbp), %eax
imull -0x54(%rbp), %eax
imull -0x3c(%rbp), %eax
cltq
addq %rax, %r8
movl -0x54(%rbp), %r9d
movq -0x20(%rbp), %r11
movl -0x6c(%rbp), %r10d
subl $0x1, %r10d
movq 0x10(%rbp), %rax
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x10d0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2a0e
movq -0x78(%rbp), %rdi
callq 0x10e0
movq -0x80(%rbp), %rdi
callq 0x10e0
movl -0x44(%rbp), %eax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2ac6
movq -0x38(%rbp), %rdi
callq 0x10e0
addq $0xa0, %rsp
popq %rbp
retq
nop