// File: MPSLab-ASU[P]DiRAC/./src/network.cc
// Function: MultiCastNetwork_Input::setupNetwork(bool*, bool*, unsigned short*, unsigned char*, unsigned char*, PE**, unsigned char)
void MultiCastNetwork_Input::setupNetwork(bool *inConfig, bool *inForward,
  data_type *inData, uint8_t *inRowTag, uint8_t *inColTag,
  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, i, 0);
    rowWiseMC[i].setConfig(inConfig);
    rowWiseMC[i].setForward(inForward);
    rowWiseMC[i].setInData(inData);
    rowWiseMC[i].setInTags(inColTag, inRowTag);
  }

  // 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
      colWiseMC[i][j].setupController(0, i, j);
      colWiseMC[i][j].setConfig(rowWiseMC[i].getPtrConfigBus());
      colWiseMC[i][j].setForward(rowWiseMC[i].getPtrForwardBus());
      colWiseMC[i][j].setInData(rowWiseMC[i].getPtrOutData());
      colWiseMC[i][j].setInTags(rowWiseMC[i].getPtrColTagOut());

      // connect each column-wise multicast controller to a PE
      PEArray[i][j].setConfig(colWiseMC[i][j].getPtrConfigBus(), networkId);
      PEArray[i][j].setForward(colWiseMC[i][j].getPtrForwardBus(), networkId);
      PEArray[i][j].setInData(colWiseMC[i][j].getPtrOutData(), networkId);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movb 0x18(%rbp), %al
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movw $0x0, -0x32(%rbp)
movzwl -0x32(%rbp), %eax
movq $0x61e5ac, %rcx         # imm = 0x61E5AC
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x419381
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movzwl -0x32(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
movl $0x1, %esi
xorl %ecx, %ecx
movzwl -0x32(%rbp), %edx
callq 0x419600
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movzwl -0x32(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x419640
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movzwl -0x32(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x419660
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movzwl -0x32(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x419680
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movzwl -0x32(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x4196a0
movw -0x32(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x32(%rbp)
jmp 0x4192c8
movw $0x0, -0x34(%rbp)
movzwl -0x34(%rbp), %eax
movq $0x61e5ac, %rcx         # imm = 0x61E5AC
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x4195f0
movw $0x0, -0x36(%rbp)
movzwl -0x36(%rbp), %eax
movq $0x61e5ae, %rcx         # imm = 0x61E5AE
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x4195dd
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movzwl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x36(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
movw -0x34(%rbp), %ax
xorl %esi, %esi
movzwl %ax, %edx
movzwl -0x36(%rbp), %ecx
callq 0x419600
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movzwl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movzwl -0x36(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movq %rcx, -0x78(%rbp)
movq (%rax), %rdi
movzwl -0x34(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x4196e0
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x419640
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movzwl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movzwl -0x36(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movq %rcx, -0x70(%rbp)
movq (%rax), %rdi
movzwl -0x34(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x419700
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x419660
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movzwl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movzwl -0x36(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movq %rcx, -0x68(%rbp)
movq (%rax), %rdi
movzwl -0x34(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x419720
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x419680
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movzwl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movzwl -0x36(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movq %rcx, -0x60(%rbp)
movq (%rax), %rdi
movzwl -0x34(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x419740
movq -0x60(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x4196a0
movq -0x40(%rbp), %rax
movq 0x10(%rbp), %rcx
movzwl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movzwl -0x36(%rbp), %edx
imulq $0x148, %rdx, %rdx      # imm = 0x148
addq %rdx, %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rax
movzwl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x36(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x4196e0
movq -0x58(%rbp), %rdi
movq %rax, %rsi
movzbl 0x18(%rbp), %edx
callq 0x423b90
movq -0x40(%rbp), %rax
movq 0x10(%rbp), %rcx
movzwl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movzwl -0x36(%rbp), %edx
imulq $0x148, %rdx, %rdx      # imm = 0x148
addq %rdx, %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rax
movzwl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x36(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x419700
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movzbl 0x18(%rbp), %edx
callq 0x423bc0
movq -0x40(%rbp), %rax
movq 0x10(%rbp), %rcx
movzwl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movzwl -0x36(%rbp), %edx
imulq $0x148, %rdx, %rdx      # imm = 0x148
addq %rdx, %rcx
movq %rcx, -0x48(%rbp)
movq 0x8(%rax), %rax
movzwl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x36(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x419720
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movzbl 0x18(%rbp), %edx
callq 0x423bf0
movw -0x36(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x36(%rbp)
jmp 0x4193a3
jmp 0x4195df
movw -0x34(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x34(%rbp)
jmp 0x419387
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)