// File: /workspace/github_cpp_makefile_star2_O2/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
movl %r8d, %ebp
movq %rcx, 0x18(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
pushq $0x10
popq %rbx
xorl %r13d, %r13d
movq 0x10(%rsp), %r14
movq $0x6085ac, %rax         # imm = 0x6085AC
movzwl (%rax), %eax
cmpq %rax, %r13
jae 0x40eaf6
movq (%r14), %rax
leaq (%rax,%rbx), %rdi
addq $-0x10, %rdi
movb $0x1, 0x14(%rdi)
callq 0x40ec1a
movq (%r14), %rax
addq %rbx, %rax
movq %rax, (%r12,%r13,8)
movq (%r14), %rax
addq %rbx, %rax
addq $0x2, %rax
movq %rax, (%r15,%r13,8)
incq %r13
addq $0x18, %rbx
jmp 0x40eab2
xorl %r15d, %r15d
movzbl %bpl, %ecx
movl %ecx, 0xc(%rsp)
movq 0x18(%rsp), %r12
movl 0xc(%rsp), %r14d
movzwl %ax, %eax
cmpq %rax, %r15
jae 0x40ec04
imulq $0x18, %r15, %rax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %esi, %esi
movq $0x6085ae, %rax         # imm = 0x6085AE
movzwl (%rax), %eax
cmpq %rax, %rsi
jae 0x40ebf2
movq 0x10(%rsp), %rbp
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
movq (%rcx,%r15,8), %rcx
addq %rbx, %rcx
addq $0x10, %rcx
movq 0x20(%rsp), %rdx
movq (%rax,%rdx), %rax
movq %rcx, (%rax,%rsi,8)
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
movq (%rcx,%r15,8), %rcx
leaq 0x12(%rcx,%rbx), %rcx
movq 0x8(%rax,%rdx), %rax
movq %rcx, (%rax,%rsi,8)
movq 0x8(%rbp), %rax
movq (%rax,%r15,8), %rdi
movb $0x0, 0x14(%rdi,%rbx)
addq %rbx, %rdi
movq %rsi, 0x30(%rsp)
callq 0x40ec1a
movq 0x8(%rbp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x28(%rsp)
movq (%r12,%r15,8), %rdi
addq %r13, %rdi
movl %r14d, %esi
callq 0x4125ea
movq 0x28(%rsp), %rcx
movq (%rcx,%rbx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbp), %rax
movq (%rax,%r15,8), %rbp
movq (%r12,%r15,8), %rdi
addq %r13, %rdi
movl %r14d, %esi
callq 0x4125e2
movq 0x30(%rsp), %rsi
movq 0x8(%rbp,%rbx), %rcx
movq %rax, (%rcx)
incq %rsi
addq $0x18, %rbx
addq $0x148, %r13            # imm = 0x148
jmp 0x40eb27
incq %r15
movq $0x6085ac, %rax         # imm = 0x6085AC
movzwl (%rax), %eax
jmp 0x40eb0b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop