// File: /workspace/github_cpp_makefile_star2_O1/MPSLab-ASU[P]DiRAC/./src/network.cc
// Function: MultiCastNetwork_Output::setupNetwork(bool**, unsigned short**, PE**, unsigned char)
void MultiCastNetwork_Output::setupNetwork(bool **outWriteBack,
  data_type **outData, PE** PEArray, uint8_t networkId)
{
  // setup row-wise multicast controllers
  // connect them to the accelerator controller
  for(uint16_t i=0; i < nRows_PE_Array; i++) {
    rowWiseMC[i].setupController(1);
    rowWiseMC[i].setupBus();
    outWriteBack[i] = rowWiseMC[i].getPtrWriteBack();
    outData[i] = rowWiseMC[i].getPtrOutData();
  }

  // set up column-wise multicast controllers
  for(uint16_t i=0; i < nRows_PE_Array; i++) {
    for(uint16_t j=0; j < nCols_PE_Array; j++) {
      // connect each column-wise multicast controller to its
      // corresponding row-wise multicast controller
      rowWiseMC[i].setWriteBack(j, colWiseMC[i][j].getPtrWriteBack());
      rowWiseMC[i].setInData(j, colWiseMC[i][j].getPtrOutData());
      colWiseMC[i][j].setupController(0);
      colWiseMC[i][j].setupBus();

      // connect each column-wise multicast controller to a PE
      colWiseMC[i][j].setWriteBack(0, PEArray[i][j].getPtrWriteBack(networkId));
      colWiseMC[i][j].setInData(0, PEArray[i][j].getPtrOutData(networkId));
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdi, %r12
movq $0x60b5ac, %rax         # imm = 0x60B5AC
movzwl (%rax), %eax
testq %rax, %rax
movq %rdi, 0x10(%rsp)
je 0x4119c0
movq %rdx, %r14
movq %rsi, %rbx
movl $0x10, %ebp
xorl %r15d, %r15d
movq %rax, (%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %r12
leaq (%r12,%rbp), %rax
movq %rax, 0x8(%rsp)
movb $0x1, 0x4(%r12,%rbp)
movq $0x60b5ae, %rax         # imm = 0x60B5AE
movzwl (%rax), %r13d
shll $0x3, %r13d
movq %r13, %rdi
callq 0x4181e0
movq %rax, -0x8(%r12,%rbp)
movq %r13, %rdi
callq 0x4181e0
movq %rax, -0x10(%r12,%rbp)
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %rax
movq %rax, (%rbx,%r15,8)
movq (%r12), %rax
addq %rbp, %rax
addq $0x2, %rax
movq %rax, (%r14,%r15,8)
movq (%rsp), %rax
incq %r15
addq $0x18, %rbp
cmpq %r15, %rax
jne 0x411953
movq $0x60b5ac, %rax         # imm = 0x60B5AC
cmpw $0x0, (%rax)
je 0x411b00
xorl %r15d, %r15d
movq $0x60b5ae, %rcx         # imm = 0x60B5AE
movzbl 0x18(%rsp), %eax
movl %eax, 0x8(%rsp)
cmpw $0x0, (%rcx)
je 0x411aea
movl $0x10, %r13d
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r12), %rax
movq 0x8(%r12), %rcx
movq (%rcx,%r15,8), %rcx
addq %r13, %rcx
movq 0x18(%rsp), %rdx
movq (%rax,%rdx), %rax
movq %rcx, (%rax,%rbp,8)
movq (%r12), %rax
movq 0x8(%r12), %rcx
movq (%rcx,%r15,8), %rcx
leaq 0x2(%rcx,%r13), %rcx
movq 0x8(%rax,%rdx), %rax
movq %rcx, (%rax,%rbp,8)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r12
movq (%r12,%r15,8), %r14
movb $0x0, 0x4(%r14,%r13)
movl $0x8, %edi
callq 0x4181e0
movq %rax, -0x8(%r14,%r13)
movl $0x8, %edi
callq 0x4181e0
movq %rax, -0x10(%r14,%r13)
movq (%r12,%r15,8), %rax
movq %rax, (%rsp)
movq 0x10(%rsp), %r12
movq 0x20(%rsp), %r14
movq (%r14,%r15,8), %rdi
addq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x4165cc
movq (%rsp), %rcx
movq -0x10(%rcx,%r13), %rcx
movq %rax, (%rcx)
movq 0x8(%r12), %rax
movq (%rax,%r15,8), %rax
movq %rax, (%rsp)
movq (%r14,%r15,8), %rdi
movl 0x8(%rsp), %esi
addq %rbx, %rdi
callq 0x4165c4
movq (%rsp), %rcx
movq -0x8(%rcx,%r13), %rcx
movq %rax, (%rcx)
movq $0x60b5ae, %rcx         # imm = 0x60B5AE
incq %rbp
movzwl (%rcx), %eax
addq $0x18, %r13
addq $0x148, %rbx            # imm = 0x148
cmpq %rax, %rbp
jb 0x411a09
incq %r15
movq $0x60b5ac, %rax         # imm = 0x60B5AC
movzwl (%rax), %eax
cmpq %rax, %r15
jb 0x4119e4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop