// File: /workspace/github_c_makefile_star2_O0/baileywjohnson[P]mpi-matrix-mult/MyMPI.c
// Function: print_checkerboard_matrix
void print_checkerboard_matrix (
   void       **a,            /* IN -2D matrix */
   MPI_Datatype dtype,        /* IN -Matrix element type */
   int          m,            /* IN -Matrix rows */
   int          n,            /* IN -Matrix columns */
   MPI_Comm     grid_comm)    /* IN - Communicator */
{
   void      *buffer;         /* Room to hold 1 matrix row */
   int        coords[2];      /* Grid coords of process
                                 sending elements */
   int        datum_size;     /* Bytes per matrix element */
   int        els;            /* Elements received */
   int        grid_coords[2]; /* Coords of this process */
   int        grid_id;        /* Process rank in grid */
   int        grid_period[2]; /* Wraparound */
   int        grid_size[2];   /* Dims of process grid */
   int        i, j, k;
   void      *laddr;          /* Where to put subrow */
   int        local_cols;     /* Matrix cols on this proc */
   int        p;              /* Number of processes */
   int        src;            /* ID of proc with subrow */
   MPI_Status status;         /* Result of receive */

   MPI_Comm_rank (grid_comm, &grid_id);
   MPI_Comm_size (grid_comm, &p);
   datum_size = get_size (dtype);

   MPI_Cart_get (grid_comm, 2, grid_size, grid_period,
      grid_coords);
   local_cols = BLOCK_SIZE(grid_coords[1],grid_size[1],n);

   if (!grid_id)
      buffer = my_malloc (grid_id, n*datum_size);

   /* For each row of the process grid */
   for (i = 0; i < grid_size[0]; i++) {
      coords[0] = i;

      /* For each matrix row controlled by the process row */
      for (j = 0; j < BLOCK_SIZE(i,grid_size[0],m); j++) {

         /* Collect the matrix row on grid process 0 and
            print it */
         if (!grid_id) {
            for (k = 0; k < grid_size[1]; k++) {
               coords[1] = k;
               MPI_Cart_rank (grid_comm, coords, &src);
               els = BLOCK_SIZE(k,grid_size[1],n);
               laddr = buffer +
                  BLOCK_LOW(k,grid_size[1],n) * datum_size;
               if (src == 0) {
                  memcpy (laddr, a[j], els * datum_size);
               } else {
                  MPI_Recv(laddr, els, dtype, src, 0,
                     grid_comm, &status);
               }
            }
            print_subvector (buffer, dtype, n);
            putchar ('\n');
         } else if (grid_coords[0] == i) {
            MPI_Send (a[j], local_cols, dtype, 0, 0,
               grid_comm);
         }
      }
   }
   if (!grid_id) {
      free (buffer);
      putchar ('\n');
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x1160
movq -0x20(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x10f0
movq -0x10(%rbp), %rdi
callq 0x1f70
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x54(%rbp), %rdx
leaq -0x4c(%rbp), %rcx
leaq -0x40(%rbp), %r8
movl $0x2, %esi
callq 0x1100
movl -0x3c(%rbp), %eax
addl $0x1, %eax
imull -0x18(%rbp), %eax
cltd
idivl -0x50(%rbp)
subl $0x1, %eax
movl %eax, -0x94(%rbp)
movl -0x3c(%rbp), %eax
imull -0x18(%rbp), %eax
cltd
idivl -0x50(%rbp)
movl %eax, %ecx
movl -0x94(%rbp), %eax
subl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x3448
movl -0x44(%rbp), %edi
movl -0x18(%rbp), %esi
imull -0x34(%rbp), %esi
callq 0x2020
movq %rax, -0x28(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x35fb
movl -0x58(%rbp), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
imull -0x14(%rbp), %eax
cltd
idivl -0x54(%rbp)
movl %eax, %ecx
subl $0x1, %ecx
movl -0x58(%rbp), %eax
imull -0x14(%rbp), %eax
cltd
idivl -0x54(%rbp)
movl %eax, %edx
movl -0x98(%rbp), %eax
subl %edx, %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x35eb
cmpl $0x0, -0x44(%rbp)
jne 0x35af
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x3593
movl -0x60(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x74(%rbp), %rdx
callq 0x11c0
movl -0x60(%rbp), %eax
addl $0x1, %eax
imull -0x18(%rbp), %eax
cltd
idivl -0x50(%rbp)
subl $0x1, %eax
movl %eax, -0xa4(%rbp)
movl -0x60(%rbp), %eax
imull -0x18(%rbp), %eax
cltd
idivl -0x50(%rbp)
movl %eax, %ecx
movl -0xa4(%rbp), %eax
subl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0x60(%rbp), %eax
imull -0x18(%rbp), %eax
cltd
idivl -0x50(%rbp)
movl %eax, %ecx
movq -0xa0(%rbp), %rax
imull -0x34(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x74(%rbp)
jne 0x355e
movq -0x68(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0x38(%rbp), %eax
imull -0x34(%rbp), %eax
movslq %eax, %rdx
callq 0x1210
jmp 0x3583
movq -0x68(%rbp), %rdi
movl -0x38(%rbp), %esi
movq -0x10(%rbp), %rdx
movl -0x74(%rbp), %ecx
movq -0x20(%rbp), %r9
xorl %r8d, %r8d
leaq -0x90(%rbp), %rax
movq %rax, (%rsp)
callq 0x1130
jmp 0x3585
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x34b5
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x18(%rbp), %edx
callq 0x32e0
movl $0xa, %edi
callq 0x1080
jmp 0x35db
movl -0x40(%rbp), %eax
cmpl -0x58(%rbp), %eax
jne 0x35d9
movq -0x8(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x6c(%rbp), %esi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %r9
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x1040
jmp 0x35db
jmp 0x35dd
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x3468
jmp 0x35ed
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x344f
cmpl $0x0, -0x44(%rbp)
jne 0x3614
movq -0x28(%rbp), %rdi
callq 0x10e0
movl $0xa, %edi
callq 0x1080
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)