// File: /workspace/github_c_makefile_star2_O3/baileywjohnson[P]mpi-matrix-mult/MyMPI.c
// Function: read_block_vector
void read_block_vector (
    char        *s,      /* IN - File name */
    void       **v,      /* OUT - Subvector */
    MPI_Datatype dtype,  /* IN - Element type */
    int         *n,      /* OUT - Vector length */
    MPI_Comm     comm)   /* IN - Communicator */
{
   int        datum_size;   /* Bytes per element */
   int        i;
   FILE      *infileptr;    /* Input file pointer */
   int        local_els;    /* Elements on this proc */
   MPI_Status status;       /* Result of receive */
   int        id;           /* Process rank */
   int        p;            /* Number of processes */
   int        x;            /* Result of read */

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

   /* Process p-1 opens file, determines number of vector
      elements, and broadcasts this value to the other
      processes. */

   if (id == (p-1)) {
      infileptr = fopen (s, "r");
      if (infileptr == NULL) *n = 0;
      else fread (n, sizeof(int), 1, infileptr);
   }
   MPI_Bcast (n, 1, MPI_INT, p-1, comm);
   if (! *n) {
      if (!id) {
         printf ("Input file '%s' cannot be opened\n", s);
         fflush (stdout);
      }
   }

   /* Block mapping of vector elements to processes */

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

   /* Dynamically allocate vector. */

   *v = my_malloc (id, local_els * datum_size);
   if (id == (p-1)) {
      for (i = 0; i < p-1; i++) {
         x = fread (*v, datum_size, BLOCK_SIZE(i,p,*n),
            infileptr);
         MPI_Send (*v, BLOCK_SIZE(i,p,*n), dtype, i, DATA_MSG,
            comm);
      }
      x = fread (*v, datum_size, BLOCK_SIZE(id,p,*n),
             infileptr);
      fclose (infileptr);
   } else {
      MPI_Recv (*v, BLOCK_SIZE(id,p,*n), dtype, p-1, DATA_MSG,
         comm, &status);
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
movq %rdx, %rdi
callq 0x1b80
movl %eax, %r13d
leaq 0x8(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1100
leaq 0xc(%rsp), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1170
movl (%r14), %eax
decl %eax
cmpl %eax, (%rbp)
jne 0x27fa
leaq 0x19b3(%rip), %rsi      # 0x4172
movq 0x10(%rsp), %rdi
callq 0x10c0
testq %rax, %rax
je 0x27ea
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rax, %rcx
movq %rax, 0x18(%rsp)
callq 0x1160
jmp 0x27fa
movl $0x0, (%r15)
movq $0x0, 0x18(%rsp)
movl 0x8(%rsp), %ecx
decl %ecx
movq 0x37a1(%rip), %rdx      # 0x5fa8
movq %r15, %rdi
movl $0x1, %esi
movq %rbx, %r8
callq 0x1180
movl (%r15), %ecx
movl 0xc(%rsp), %edi
movl %edi, %eax
orl %ecx, %eax
jne 0x284d
leaq 0x1949(%rip), %rdi      # 0x4174
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x1050
movq 0x37ba(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
callq 0x1240
movl 0xc(%rsp), %edi
movl (%r15), %ecx
leal 0x1(%rdi), %eax
imull %ecx, %eax
movl 0x8(%rsp), %r8d
cltd
idivl %r8d
movl %eax, %esi
imull %edi, %ecx
movl %ecx, %eax
cltd
idivl %r8d
subl %eax, %esi
imull %r13d, %esi
callq 0x1bf2
movq %rax, %rdi
movq 0x20(%rsp), %rax
movq %rdi, (%rax)
movl 0xc(%rsp), %r10d
movl 0x8(%rsp), %r9d
leal -0x1(%r9), %ecx
cmpl %ecx, %r10d
jne 0x297a
movslq %r13d, %rsi
cmpl $0x2, %r9d
jl 0x2942
xorl %r14d, %r14d
movq %rbx, 0x10(%rsp)
movq %r12, 0x28(%rsp)
movq %r15, %rbp
movq %rax, %r15
movq 0x18(%rsp), %r13
movq (%r15), %rdi
leal 0x1(%r14), %r12d
movl (%rbp), %ecx
movl %ecx, %eax
imull %r12d, %eax
cltd
idivl %r9d
movl %eax, %r8d
imull %r14d, %ecx
movl %ecx, %eax
cltd
idivl %r9d
subl %eax, %r8d
movslq %r8d, %rdx
movq %r13, %rcx
movq %rsi, %rbx
callq 0x1160
movq (%r15), %rdi
movl (%rbp), %ecx
movl %ecx, %eax
imull %r12d, %eax
movl 0x8(%rsp), %r8d
cltd
idivl %r8d
movl %eax, %esi
imull %r14d, %ecx
movl %ecx, %eax
cltd
idivl %r8d
subl %eax, %esi
movq 0x28(%rsp), %rdx
movl %r14d, %ecx
xorl %r8d, %r8d
movq 0x10(%rsp), %r9
callq 0x1040
movq %rbx, %rsi
movl 0x8(%rsp), %r9d
leal -0x1(%r9), %eax
movl %r12d, %r14d
cmpl %eax, %r12d
jl 0x28b9
movq (%r15), %rdi
movl 0xc(%rsp), %r10d
movq %rbp, %r15
leal 0x1(%r10), %eax
movl (%r15), %ecx
imull %ecx, %eax
cltd
idivl %r9d
movl %eax, %r8d
imull %r10d, %ecx
movl %ecx, %eax
cltd
idivl %r9d
subl %eax, %r8d
movslq %r8d, %rdx
movq 0x18(%rsp), %rbx
movq %rbx, %rcx
callq 0x1160
movq %rbx, %rdi
callq 0x11c0
jmp 0x29b2
leal 0x1(%r10), %eax
movl (%r15), %esi
imull %esi, %eax
cltd
idivl %r9d
movl %eax, %r8d
imull %r10d, %esi
movl %esi, %eax
cltd
idivl %r9d
subl %eax, %r8d
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
movl %r8d, %esi
movq %r12, %rdx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x1140
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq