// File: /workspace/github_c_makefile_star2_O1/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 -0x88(%rbp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movl 0x16620(%rip), %edx     # 0x19704
leaq 0x16675(%rip), %rdi     # 0x19760
leaq -0x90(%rbp), %rsi
callq 0xbd18
movq %rsp, %r15
movq -0x68(%rbp), %rax
movq %rsp, %r13
leaq (%rax,%rax,4), %rax
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq -0x78(%rbp), %r14
leaq -0x88(%rbp), %r12
cmpq %r12, %r14
je 0x3163
leaq 0x10(%r13), %rbx
movq 0x20(%r14), %rdi
callq 0x23a0
movq %rax, -0x10(%rbx)
movl 0x40(%r14), %eax
movl %eax, -0x8(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq %r14, %rdi
callq 0x2230
movq %rax, %r14
addq $0x28, %rbx
cmpq %r12, %rax
jne 0x312b
cmpl $0x0, 0x1659e(%rip)     # 0x19708
jle 0x34e5
movl $0x8, %edi
callq 0x21f0
movq %rax, %r14
movq %rax, %rdi
callq 0x9ebc
movq %r14, 0x165c4(%rip)     # 0x19750
movl 0x16572(%rip), %edx     # 0x19704
movzbl 0x16567(%rip), %ecx     # 0x19700
leaq 0x165c0(%rip), %rdi     # 0x19760
movq %r14, %rsi
callq 0xbd40
movq %r15, -0xa0(%rbp)
movq %rsp, -0x98(%rbp)
movl 0x1654c(%rip), %ecx     # 0x19708
movq %rsp, %r14
movq %rcx, %rax
shlq $0x4, %rax
movq %rax, -0x48(%rbp)
leaq (%rax,%rax,2), %rax
subq %rax, %r14
movq %r14, %rsp
movq %rcx, -0x50(%rbp)
testq %rcx, %rcx
je 0x3203
leaq 0x8(%r14), %rcx
xorl %edx, %edx
movl $0x0, (%rcx)
movq %rdx, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rdx, 0x20(%rcx)
addq $0x30, %rcx
addq $-0x30, %rax
jne 0x31e3
leaq 0xe02c(%rip), %rdi      # 0x11236
xorl %eax, %eax
callq 0x2060
movq $0x0, 0x16504(%rip) # 0x19720
cmpl $0x0, 0x164e5(%rip)     # 0x19708
jle 0x32ec
xorl %ebx, %ebx
movq 0x14d8e(%rip), %r12     # 0x17fc0
movq %r14, %r15
movq 0x164fc(%rip), %rdi     # 0x19738
movq (%rdi), %rax
callq *0x90(%rax)
movq 0x164ec(%rip), %rdi     # 0x19738
movl 0x164be(%rip), %esi     # 0x19710
movl 0x164bc(%rip), %edx     # 0x19714
callq 0xb230
movq 0x164d4(%rip), %rdi     # 0x19738
movq (%rdi), %rax
callq *0x78(%rax)
movq 0x164c7(%rip), %rdi     # 0x19738
movq (%rdi), %rax
callq *0x88(%rax)
xorl %edi, %edi
callq 0xb150
movq 0x164c8(%rip), %rdi     # 0x19750
movq 0x164a9(%rip), %rsi     # 0x19738
callq 0xa2e0
xorl %edi, %edi
callq 0xb170
xorl %edi, %edi
callq 0xb190
addsd 0x16476(%rip), %xmm0    # 0x19720
movsd %xmm0, 0x1646e(%rip)    # 0x19720
movq 0x16497(%rip), %rdi     # 0x19750
movl 0x16445(%rip), %edx     # 0x19704
movq %r15, %rsi
callq 0xa570
movq (%r12), %rsi
movl $0x2e, %edi
callq 0x2280
incq %rbx
movslq 0x16429(%rip), %rax     # 0x19708
addq $0x30, %r15
cmpq %rax, %rbx
jl 0x3235
movq 0x14ccd(%rip), %rax     # 0x17fc0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x2280
cvtsi2sdl 0x16400(%rip), %xmm1 # 0x19708
movsd 0x16410(%rip), %xmm0    # 0x19720
divsd %xmm1, %xmm0
movsd %xmm0, 0x16404(%rip)    # 0x19720
leaq 0xdf2f(%rip), %rdi      # 0x11252
movb $0x1, %al
callq 0x2060
movq -0x78(%rbp), %rcx
leaq -0x88(%rbp), %rax
cmpq %rax, %rcx
je 0x34b5
xorl %ebx, %ebx
movq %r13, -0x58(%rbp)
movq %rbx, -0x60(%rbp)
movl 0x163ba(%rip), %eax     # 0x19708
xorpd %xmm1, %xmm1
testl %eax, %eax
movq %rcx, -0x40(%rbp)
jle 0x33a8
leaq 0x20(%rcx), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r14, %r12
xorl %ebx, %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0x4374
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
incq %rbx
movslq 0x16372(%rip), %rax     # 0x19708
addq $0x30, %r12
cmpq %rax, %rbx
jl 0x336c
movq -0x40(%rbp), %rcx
movsd -0x30(%rbp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
cmpl $0x0, 0x16349(%rip)     # 0x19708
jle 0x343d
leaq 0x20(%rcx), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq %r14, %r12
xorl %ebx, %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0x4374
movl (%rax), %r13d
movq %r12, %rdi
movq %r15, %rsi
callq 0x4374
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%rax), %xmm1
movsd -0x30(%rbp), %xmm2
subsd %xmm2, %xmm0
subsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movslq 0x162f5(%rip), %rax     # 0x19708
leal -0x1(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd %xmm0, %xmm1
movsd -0x38(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
incq %rbx
addq $0x30, %r12
cmpq %rax, %rbx
jl 0x33d3
jmp 0x3446
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
ucomisd 0xdbbd(%rip), %xmm0     # 0x11010
jb 0x345b
sqrtsd %xmm0, %xmm0
jmp 0x3460
callq 0x2190
movq -0x58(%rbp), %r13
movq -0x40(%rbp), %rdi
movq -0x60(%rbp), %rbx
xorps %xmm1, %xmm1
cvtsi2sdl 0x40(%rdi), %xmm1
movsd -0x30(%rbp), %xmm2
subsd %xmm2, %xmm1
divsd %xmm0, %xmm1
leaq (%rbx,%rbx,4), %rax
movsd %xmm2, 0x10(%r13,%rax,8)
movsd %xmm0, 0x18(%r13,%rax,8)
movsd %xmm1, 0x20(%r13,%rax,8)
callq 0x2230
movq %rax, %rcx
incq %rbx
leaq -0x88(%rbp), %rax
cmpq %rax, %rcx
jne 0x3344
cmpq $0x0, -0x50(%rbp)
je 0x34d7
addq $-0x30, %r14
movq -0x48(%rbp), %rax
leaq (%rax,%rax,2), %rbx
leaq (%r14,%rbx), %rdi
callq 0x43fc
addq $-0x30, %rbx
jne 0x34c8
movq -0x98(%rbp), %rsp
movq -0xa0(%rbp), %r15
movq -0x68(%rbp), %rsi
leaq -0x816(%rip), %rcx      # 0x2cda
movl $0x28, %edx
movq %r13, %rdi
callq 0x23c0
movl -0x68(%rbp), %esi
movq %r13, %rdi
callq 0x35ce
leaq 0xdd68(%rip), %rdi      # 0x11277
leaq 0x159ea(%rip), %rsi     # 0x18f00
xorl %eax, %eax
callq 0x2060
cmpb $0x1, 0x161dd(%rip)     # 0x19701
jne 0x353b
leaq 0xdd68(%rip), %rdi      # 0x11295
leaq 0x15dcc(%rip), %rsi     # 0x19300
xorl %eax, %eax
callq 0x2060
cmpl $0x0, -0x68(%rbp)
jle 0x355c
xorl %ebx, %ebx
movq (%r13), %rdi
callq 0x2260
incq %rbx
movslq -0x68(%rbp), %rax
addq $0x28, %r13
cmpq %rax, %rbx
jl 0x3543
movq %r15, %rsp
leaq -0x90(%rbp), %rdi
callq 0x43fc
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x8, %esi
movq %r14, %rdi
callq 0x2200
jmp 0x35ba
movq %rax, %rbx
jmp 0x35ba
jmp 0x3595
jmp 0x3595
movq %rax, %rbx
cmpq $0x0, -0x50(%rbp)
je 0x35ba
addq $-0x30, %r14
movq -0x48(%rbp), %rax
leaq (%rax,%rax,2), %r15
leaq (%r14,%r15), %rdi
callq 0x43fc
addq $-0x30, %r15
jne 0x35ab
leaq -0x90(%rbp), %rdi
callq 0x43fc
movq %rbx, %rdi
callq 0x2370