// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movb 0x68(%rsp), %al
movq %rdi, 0x10(%rsp)
movq (%rdi), %rdi
addq $0x38, %rdi
xorl %r10d, %r10d
movq $0x6085ac, %rbx         # imm = 0x6085AC
movzwl (%rbx), %r11d
cmpq %r11, %r10
jae 0x40dae3
movb $0x1, -0x3(%rdi)
movw %r10w, -0x2(%rdi)
andw $0x0, (%rdi)
movq %rsi, -0x38(%rdi)
movq %rdx, -0x30(%rdi)
movq %rcx, -0x28(%rdi)
movq %r9, -0x10(%rdi)
movq %r8, -0x18(%rdi)
incq %r10
addq $0x40, %rdi
jmp 0x40dab0
xorl %r12d, %r12d
movzbl %al, %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %ebp
movq 0x10(%rsp), %r15
movzwl %r11w, %eax
cmpq %rax, %r12
jae 0x40dc1f
movq %r12, %rax
shlq $0x6, %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %esi, %esi
movq $0x6085ae, %rax         # imm = 0x6085AE
movzwl (%rax), %eax
cmpq %rax, %rsi
jae 0x40dc0c
movq 0x10(%rsp), %rdx
movq 0x8(%rdx), %rax
movq (%rax,%r12,8), %rcx
movb $0x0, 0x35(%rcx,%r14)
movw %r12w, 0x36(%rcx,%r14)
movq %rsi, 0x20(%rsp)
movw %si, 0x38(%rcx,%r14)
movq (%rdx), %rdx
movq 0x18(%rsp), %rdi
leaq 0x1a(%rdx,%rdi), %rsi
movq %rsi, (%rcx,%r14)
movq (%rax,%r12,8), %rcx
leaq 0x1b(%rdx,%rdi), %rsi
movq %rsi, 0x8(%rcx,%r14)
movq (%rax,%r12,8), %rcx
leaq 0x18(%rdx,%rdi), %rsi
movq %rsi, 0x10(%rcx,%r14)
movq (%rax,%r12,8), %rcx
addq %rdi, %rdx
addq $0x30, %rdx
movq %rdx, 0x28(%rcx,%r14)
cmpb $0x1, 0x35(%rcx,%r14)
jne 0x40db99
andq $0x0, 0x20(%rcx,%r14)
movq 0x60(%rsp), %rbx
movq (%rbx,%r12,8), %rdi
addq %r13, %rdi
movq (%rax,%r12,8), %rax
leaq (%rax,%r14), %rsi
addq $0x1a, %rsi
movl %ebp, %edx
callq 0x4125be
movq (%rbx,%r12,8), %rdi
addq %r13, %rdi
movq 0x8(%r15), %rax
movq (%rax,%r12,8), %rax
leaq (%rax,%r14), %rsi
addq $0x1b, %rsi
movl %ebp, %edx
callq 0x4125ca
movq (%rbx,%r12,8), %rdi
addq %r13, %rdi
movq 0x8(%r15), %rax
movq (%rax,%r12,8), %rax
leaq (%rax,%r14), %rsi
addq $0x18, %rsi
movl %ebp, %edx
callq 0x4125d6
movq 0x20(%rsp), %rsi
incq %rsi
addq $0x40, %r14
addq $0x148, %r13            # imm = 0x148
jmp 0x40db17
incq %r12
movq $0x6085ac, %rax         # imm = 0x6085AC
movzwl (%rax), %r11d
jmp 0x40daf6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq