// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rcx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq %rdx, 0x28(%rsp)
movq %rdx, %rdi
callq 0x1b5c
movl %eax, 0x24(%rsp)
leaq 0x10(%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1100
leaq 0x14(%rsp), %rbp
movq %r13, 0x18(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1170
movl (%rbx), %eax
decl %eax
cmpl %eax, (%rbp)
jne 0x273b
leaq 0x1a61(%rip), %rsi      # 0x4172
movq %r14, %rdi
callq 0x10c0
testq %rax, %rax
je 0x2734
movq %rax, %r13
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %rax, %rcx
callq 0x1160
jmp 0x273b
andl $0x0, (%r15)
xorl %r13d, %r13d
movl 0x10(%rsp), %ecx
decl %ecx
movq 0x3860(%rip), %rdx      # 0x5fa8
pushq $0x1
popq %rbp
movq %r15, %rdi
movl %ebp, %esi
movq 0x18(%rsp), %r8
callq 0x1180
movl (%r15), %ecx
movl 0x14(%rsp), %edi
movl %edi, %eax
orl %ecx, %eax
jne 0x278e
leaq 0x1a06(%rip), %rdi      # 0x4174
movq %r14, %rsi
xorl %eax, %eax
callq 0x1050
movq 0x3879(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
callq 0x1240
movl 0x14(%rsp), %edi
movl (%r15), %ecx
leal 0x1(%rdi), %eax
imull %ecx, %eax
movl 0x10(%rsp), %r8d
cltd
idivl %r8d
movl %eax, %esi
imull %edi, %ecx
movl %ecx, %eax
cltd
idivl %r8d
subl %eax, %esi
movl 0x24(%rsp), %ebx
imull %ebx, %esi
callq 0x1bc5
movq %rax, (%r12)
movl 0x14(%rsp), %r10d
movl 0x10(%rsp), %r9d
leal -0x1(%r9), %ecx
cmpl %ecx, %r10d
jne 0x2882
movslq %ebx, %r14
leal -0x1(%rbp), %ebx
leal -0x1(%r9), %eax
movq (%r12), %rdi
cmpl %eax, %ebx
jge 0x2849
movl (%r15), %ecx
movl %ecx, %eax
imull %ebp, %eax
cltd
idivl %r9d
movl %eax, %esi
imull %ebx, %ecx
movl %ecx, %eax
cltd
idivl %r9d
subl %eax, %esi
movslq %esi, %rdx
movq %r14, %rsi
movq %r13, %rcx
callq 0x1160
movq (%r12), %rdi
movl (%r15), %ecx
movl %ecx, %eax
imull %ebp, %eax
movl 0x10(%rsp), %r8d
cltd
idivl %r8d
movl %eax, %esi
imull %ebx, %ecx
movl %ecx, %eax
cltd
idivl %r8d
subl %eax, %esi
movq 0x28(%rsp), %rdx
movl %ebx, %ecx
xorl %r8d, %r8d
movq 0x18(%rsp), %r9
callq 0x1040
movl 0x10(%rsp), %r9d
incl %ebp
jmp 0x27d4
movl 0x14(%rsp), %r8d
leal 0x1(%r8), %eax
movl (%r15), %ecx
imull %ecx, %eax
cltd
idivl %r9d
movl %eax, %esi
imull %r8d, %ecx
movl %ecx, %eax
cltd
idivl %r9d
subl %eax, %esi
movslq %esi, %rdx
movq %r14, %rsi
movq %r13, %rcx
callq 0x1160
movq %r13, %rdi
callq 0x11c0
jmp 0x28c1
movq %rax, %rdi
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 0x28(%rsp), %rdx
xorl %r8d, %r8d
movq 0x18(%rsp), %r9
callq 0x1140
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq