// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rdi, 0x20(%rsp)
movq $0x60b5ac, %rax         # imm = 0x60B5AC
movzwl (%rax), %edi
testq %rdi, %rdi
je 0x412627
movq %rsi, %r12
movl %r8d, 0x2c(%rsp)
movq %rcx, 0x30(%rsp)
movl $0x10, %ebx
xorl %r15d, %r15d
movq $0x60b5ae, %r14         # imm = 0x60B5AE
movq 0x20(%rsp), %rcx
movq %rdi, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq (%rcx), %rbp
leaq (%rbx,%rbp), %rax
movq %rax, 0x8(%rsp)
movb $0x1, 0x4(%rbp,%rbx)
movzwl (%r14), %r13d
shll $0x3, %r13d
movq %r13, %rdi
callq 0x418d20
movq %rax, -0x8(%rbp,%rbx)
movq %r13, %rdi
callq 0x418d20
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rdi
movq %rax, -0x10(%rbp,%rbx)
movq 0x8(%rsp), %rax
movq %rax, (%r12,%r15,8)
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
addq %rbx, %rax
addq $0x2, %rax
movq %rax, (%rdx,%r15,8)
incq %r15
addq $0x18, %rbx
cmpq %r15, %rdi
jne 0x41247d
testw %di, %di
movl 0x2c(%rsp), %ecx
je 0x412627
movzwl (%r14), %eax
xorl %r15d, %r15d
movzbl %cl, %edx
movl %edx, 0x10(%rsp)
testw %ax, %ax
je 0x412616
movl $0x10, %r13d
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x20(%rsp), %r12
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 0x8(%r12), %rax
movq %rax, 0x8(%rsp)
movq (%rax,%r15,8), %r14
movb $0x0, 0x4(%r14,%r13)
movl $0x8, %edi
callq 0x418d20
movq %rax, -0x8(%r14,%r13)
movl $0x8, %edi
callq 0x418d20
movq %rax, -0x10(%r14,%r13)
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rax
movq (%rax,%r15,8), %rdi
addq %rbx, %rdi
movl 0x10(%rsp), %r14d
movl %r14d, %esi
callq 0x417126
movq 0x8(%rsp), %rcx
movq -0x10(%rcx,%r13), %rcx
movq %rax, (%rcx)
movq 0x8(%r12), %rax
movq (%rax,%r15,8), %r12
movq 0x30(%rsp), %rax
movq (%rax,%r15,8), %rdi
addq %rbx, %rdi
movl %r14d, %esi
callq 0x41711e
movq -0x8(%r12,%r13), %rcx
movq $0x60b5ae, %rdx         # imm = 0x60B5AE
movq %rax, (%rcx)
incq %rbp
movzwl (%rdx), %eax
addq $0x18, %r13
addq $0x148, %rbx            # imm = 0x148
cmpq %rax, %rbp
jb 0x412521
movq $0x60b5ac, %rcx         # imm = 0x60B5AC
movzwl (%rcx), %edi
jmp 0x412618
xorl %eax, %eax
incq %r15
movzwl %di, %ecx
cmpq %rcx, %r15
jb 0x4124fd
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq