// File: /workspace/github_c_makefile_star2_O1/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 %rsi, %r12
movq %rdi, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
movq %rdx, %rdi
callq 0x1b74
movl %eax, %r13d
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1100
leaq 0x14(%rsp), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1170
movl (%r14), %eax
decl %eax
cmpl %eax, (%rbp)
jne 0x2808
leaq 0x19a5(%rip), %rsi      # 0x4172
movq 0x18(%rsp), %rdi
callq 0x10c0
testq %rax, %rax
je 0x27f8
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rax, %rcx
movq %rax, 0x20(%rsp)
callq 0x1160
jmp 0x2808
movl $0x0, (%r15)
movq $0x0, 0x20(%rsp)
movl 0x10(%rsp), %ecx
decl %ecx
movq 0x3793(%rip), %rdx      # 0x5fa8
movq %r15, %rdi
movl $0x1, %esi
movq %rbx, %r8
callq 0x1180
movl 0x14(%rsp), %eax
orl (%r15), %eax
jne 0x2850
leaq 0x193f(%rip), %rdi      # 0x4174
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x1050
movq 0x37b0(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
callq 0x1240
movl 0x14(%rsp), %edi
leal 0x1(%rdi), %eax
movl (%r15), %ecx
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
imull %r13d, %esi
callq 0x1be6
movq %rax, %rdi
movq %rax, (%r12)
movl 0x14(%rsp), %r10d
movl 0x10(%rsp), %r9d
leal -0x1(%r9), %ecx
cmpl %ecx, %r10d
jne 0x293e
movl 0x10(%rsp), %r8d
movslq %r13d, %rsi
cmpl $0x2, %r8d
jl 0x297a
xorl %r14d, %r14d
movq %rbx, 0x18(%rsp)
movq 0x28(%rsp), %rbx
movq %r12, %rbp
movq (%rbp), %rdi
leal 0x1(%r14), %r13d
movl (%r15), %ecx
movl %ecx, %eax
imull %r13d, %eax
cltd
idivl %r8d
movl %eax, %r9d
imull %r14d, %ecx
movl %ecx, %eax
cltd
idivl %r8d
subl %eax, %r9d
movslq %r9d, %rdx
movq 0x20(%rsp), %rcx
movq %rsi, %r12
callq 0x1160
movq (%rbp), %rdi
movl (%r15), %ecx
movl %ecx, %eax
imull %r13d, %eax
movl 0x10(%rsp), %r8d
cltd
idivl %r8d
movl %eax, %esi
imull %r14d, %ecx
movl %ecx, %eax
cltd
idivl %r8d
subl %eax, %esi
movq %rbx, %rdx
movl %r14d, %ecx
xorl %r8d, %r8d
movq 0x18(%rsp), %r9
callq 0x1040
movq %r12, %rsi
movl 0x10(%rsp), %r8d
leal -0x1(%r8), %eax
movl %r13d, %r14d
cmpl %eax, %r13d
jl 0x28bc
jmp 0x297d
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 %rbx, %r9
callq 0x1140
jmp 0x29bc
movq %r12, %rbp
movq (%rbp), %rdi
movl 0x14(%rsp), %r9d
leal 0x1(%r9), %eax
movl (%r15), %ecx
imull %ecx, %eax
cltd
idivl %r8d
movl %eax, %r10d
imull %r9d, %ecx
movl %ecx, %eax
cltd
idivl %r8d
subl %eax, %r10d
movslq %r10d, %rdx
movq 0x20(%rsp), %rbx
movq %rbx, %rcx
callq 0x1160
movq %rbx, %rdi
callq 0x11c0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq