// File: /workspace/github_c_makefile_star2_O2/ComplexNetworks-DCC-FCUP[P]gtrieScanner/CmdLine.cpp
// Function: CmdLine::compute_results()
void CmdLine::compute_results() {
  int i, j;
  mapStringInt:: const_iterator ii, iiend;

  // Create map and init results
  mapStringInt m_original;  
  sg_original.populateMap(&m_original, motif_size);
  ResultType res[m_original.size()];
  for (ii=m_original.begin(), iiend=m_original.end(), i=0; ii!=iiend; ii++, i++) {
    res[i].s = strdup((ii->first).c_str());    
    res[i].f_original = ii->second;
    res[i].z_score = res[i].avg_random = res[i].dev_random = 0;
  }

  // Do we have random networks to compute?
  if (random_number > 0) {
    gt = new GTrie;
    sg_original.populateGTrieNauty(gt, motif_size, dir);
    
    mapStringInt m_count[random_number];

    // Generate all random networks
    printf("Computing random networks: ");
    time_random = 0;
    for (i=0; i<random_number; i++) {      

      // Create new random network from previous one
      g->makeVectorNeighbours();
      Random::markovChainPerEdge(g, random_exchanges, random_tries);
      g->sortNeighbours();
      g->makeArrayNeighbours();

      // Compute census
      Timer::start(0);
      gt->census(g);
      Timer::stop(0);
      time_random += Timer::elapsed(0);
      gt->populateMap(&m_count[i], motif_size);
      fputc('.', stdout);      
    }
    fputc('\n', stdout);
    time_random /= (double)random_number;
    printf("Avg time per random network: %.6fs\n\n", time_random);

    // Compute significance
    for (ii=m_original.begin(), iiend=m_original.end(), i=0; ii!=iiend; ii++, i++) {
      // Average frequency
      double avg = 0;
      for (j=0; j<random_number; j++)
	avg += m_count[j][ii->first];
      avg /= random_number;

      // Standard deviation
      double dev=0;
      for (j=0; j<random_number; j++)
	dev += double(m_count[j][ii->first]-avg)*double(m_count[j][ii->first]-avg)/double(random_number-1);
      dev = sqrt(dev);

      // zscore
      double zscore = (ii->second - avg)/dev;

      res[i].avg_random = avg;
      res[i].dev_random = dev;
      res[i].z_score    = zscore;
    }
  }

  // Sort results
  qsort(res, m_original.size(), sizeof(ResultType), compare_results);

  // print results
  show_results(res, m_original.size());
  printf("Results written to file \"%s\"\n", output_file);
  if (occurrences)
    printf("Occurences on original network written to file \"%s\"\n", occ_file);

  for (i=0; i<(int)m_original.size(); i++)
    free(res[i].s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq -0x90(%rbp), %r13
andl $0x0, (%r13)
andq $0x0, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
andq $0x0, 0x20(%r13)
movl 0x168e5(%rip), %edx     # 0x19724
leaq 0x1693a(%rip), %rdi     # 0x19780
leaq -0x98(%rbp), %rsi
callq 0xb580
movq %rsp, %r15
imulq $0x28, -0x70(%rbp), %rax
movq %rsp, %rcx
addq $0xf, %rax
andq $-0x10, %rax
movq %rcx, %r12
subq %rax, %r12
movq %r12, %rsp
movq -0x80(%rbp), %r14
negq %rax
leaq (%rcx,%rax), %rbx
addq $0x10, %rbx
cmpq %r13, %r14
je 0x2eb4
movq 0x20(%r14), %rdi
callq 0x23e0
movq %rax, -0x10(%rbx)
movl 0x40(%r14), %eax
movl %eax, -0x8(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq %r14, %rdi
callq 0x2250
movq %rax, %r14
addq $0x28, %rbx
jmp 0x2e7d
cmpl $0x0, 0x1686d(%rip)     # 0x19728
jle 0x31c6
pushq $0x8
popq %rdi
callq 0x2200
movq %rax, %r14
movq %rax, %rdi
callq 0x9640
movq %r14, 0x16895(%rip)     # 0x19770
movl 0x16843(%rip), %edx     # 0x19724
movzbl 0x16838(%rip), %ecx     # 0x19720
leaq 0x16891(%rip), %rdi     # 0x19780
movq %r14, %rsi
callq 0xb5a8
movq %r12, -0x48(%rbp)
movq %r15, -0x60(%rbp)
movq %rsp, -0x58(%rbp)
movl 0x1681f(%rip), %ecx     # 0x19728
movq %rsp, %r13
imulq $0x30, %rcx, %rax
subq %rax, %r13
movq %r13, %rsp
movq %rcx, -0x40(%rbp)
testq %rcx, %rcx
je 0x2f42
leaq 0x8(%r13), %rcx
andl $0x0, (%rcx)
andq $0x0, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
andq $0x0, 0x20(%rcx)
addq $0x30, %rcx
addq $-0x30, %rax
jne 0x2f23
leaq 0xd2ed(%rip), %rdi      # 0x10236
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2060
andq $0x0, 0x167e6(%rip)     # 0x19740
movq 0x1505f(%rip), %r12     # 0x17fc0
pushq $0x2e
popq %r14
movq %r13, %r15
movslq 0x167b9(%rip), %rax     # 0x19728
cmpq %rax, %rbx
jge 0x3022
movq 0x167d9(%rip), %rdi     # 0x19758
movq (%rdi), %rax
callq *0x90(%rax)
movq 0x167c9(%rip), %rdi     # 0x19758
movl 0x1679b(%rip), %esi     # 0x19730
movl 0x16799(%rip), %edx     # 0x19734
callq 0xab4c
movq 0x167b1(%rip), %rdi     # 0x19758
movq (%rdi), %rax
callq *0x78(%rax)
movq 0x167a4(%rip), %rdi     # 0x19758
movq (%rdi), %rax
callq *0x88(%rax)
xorl %edi, %edi
callq 0xaa6c
movq 0x167a5(%rip), %rdi     # 0x19770
movq 0x16786(%rip), %rsi     # 0x19758
callq 0x9a0e
xorl %edi, %edi
callq 0xaa8c
xorl %edi, %edi
callq 0xaaac
addsd 0x16753(%rip), %xmm0    # 0x19740
movsd %xmm0, 0x1674b(%rip)    # 0x19740
movq 0x16774(%rip), %rdi     # 0x19770
movl 0x16722(%rip), %edx     # 0x19724
movq %r15, %rsi
callq 0x9c88
movq (%r12), %rsi
movl %r14d, %edi
callq 0x22a0
incq %rbx
addq $0x30, %r15
jmp 0x2f68
movq (%r12), %rsi
pushq $0xa
popq %rdi
callq 0x22a0
cvtsi2sdl 0x166f2(%rip), %xmm1 # 0x19728
movsd 0x16702(%rip), %xmm0    # 0x19740
divsd %xmm1, %xmm0
movsd %xmm0, 0x166f6(%rip)    # 0x19740
leaq 0xd201(%rip), %rdi      # 0x10252
movb $0x1, %al
callq 0x2060
xorl %ebx, %ebx
movq -0x80(%rbp), %rcx
movq %rbx, -0x50(%rbp)
leaq -0x90(%rbp), %rax
cmpq %rax, %rcx
je 0x319a
movq %rcx, -0x68(%rbp)
leaq 0x20(%rcx), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r13, %r12
xorl %ebx, %ebx
movslq 0x16699(%rip), %rax     # 0x19728
cmpq %rax, %rbx
jge 0x30ba
movq %r12, %rdi
movq %r15, %rsi
callq 0x406a
cvtsi2sdl (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
incq %rbx
addq $0x30, %r12
jmp 0x3088
cvtsi2sd %eax, %xmm0
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq %r13, %r12
xorl %ebx, %ebx
cltq
cmpq %rax, %rbx
jge 0x313c
movq %r12, %rdi
movq %r15, %rsi
callq 0x406a
movl (%rax), %r14d
movq %r12, %rdi
movq %r15, %rsi
callq 0x406a
cvtsi2sd %r14d, %xmm0
movsd -0x30(%rbp), %xmm2
subsd %xmm2, %xmm0
cvtsi2sdl (%rax), %xmm1
subsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movl 0x1660e(%rip), %eax     # 0x19728
leal -0x1(%rax), %ecx
cvtsi2sd %ecx, %xmm0
divsd %xmm0, %xmm1
movsd -0x38(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
incq %rbx
addq $0x30, %r12
jmp 0x30da
movsd -0x38(%rbp), %xmm0
ucomisd 0xcec7(%rip), %xmm0     # 0x10010
jb 0x3151
sqrtsd %xmm0, %xmm0
jmp 0x3156
callq 0x21a0
movq -0x50(%rbp), %rbx
movq -0x68(%rbp), %rdi
cvtsi2sdl 0x40(%rdi), %xmm1
movsd -0x30(%rbp), %xmm2
subsd %xmm2, %xmm1
divsd %xmm0, %xmm1
imulq $0x28, %rbx, %rax
movq -0x48(%rbp), %rcx
movsd %xmm2, 0x10(%rcx,%rax)
movsd %xmm0, 0x18(%rcx,%rax)
movsd %xmm1, 0x20(%rcx,%rax)
callq 0x2250
movq %rax, %rcx
incq %rbx
jmp 0x305e
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x31ba
addq $-0x30, %r13
imulq $0x30, %rax, %rbx
leaq (%rbx,%r13), %rdi
callq 0x40dc
addq $-0x30, %rbx
jne 0x31ab
movq -0x58(%rbp), %rsp
movq -0x60(%rbp), %r15
movq -0x48(%rbp), %r12
movq -0x70(%rbp), %rsi
leaq -0x781(%rip), %rcx      # 0x2a50
pushq $0x28
popq %rdx
movq %r12, %rdi
callq 0x2400
movl -0x70(%rbp), %esi
movq %r12, %rdi
callq 0x32a6
leaq 0xd089(%rip), %rdi      # 0x10277
leaq 0x15d2b(%rip), %rsi     # 0x18f20
xorl %eax, %eax
callq 0x2060
cmpb $0x1, 0x1651e(%rip)     # 0x19721
jne 0x321a
leaq 0xd089(%rip), %rdi      # 0x10295
leaq 0x1610d(%rip), %rsi     # 0x19320
xorl %eax, %eax
callq 0x2060
xorl %ebx, %ebx
movslq -0x70(%rbp), %rax
cmpq %rax, %rbx
jge 0x3237
movq (%r12), %rdi
callq 0x2280
incq %rbx
addq $0x28, %r12
jmp 0x321c
movq %r15, %rsp
leaq -0x98(%rbp), %rdi
callq 0x40dc
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x2210
jmp 0x3291
movq %rax, %rbx
jmp 0x3291
jmp 0x326e
jmp 0x326e
movq %rax, %rbx
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x3291
addq $-0x30, %r13
imulq $0x30, %rax, %r14
leaq (%r14,%r13), %rdi
callq 0x40dc
addq $-0x30, %r14
jne 0x3282
leaq -0x98(%rbp), %rdi
callq 0x40dc
movq %rbx, %rdi
callq 0x23b0
nop