// File: /workspace/github_c_makefile_star2_O3/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), %rbx
movl $0x0, (%rbx)
xorl %eax, %eax
movq %rax, 0x8(%rbx)
movq %rbx, 0x10(%rbx)
movq %rbx, 0x18(%rbx)
movq %rax, 0x20(%rbx)
movl 0x16628(%rip), %edx     # 0x19704
leaq 0x1667d(%rip), %rdi     # 0x19760
leaq -0x90(%rbp), %rsi
callq 0xbe6c
movq %rsp, -0xa0(%rbp)
movq -0x68(%rbp), %rax
movq %rsp, %rcx
leaq (%rax,%rax,4), %rax
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
movq -0x78(%rbp), %r14
cmpq %rbx, %r14
je 0x3163
movq %rbx, %r15
movq -0x38(%rbp), %rax
leaq 0x10(%rax), %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 %r15, %rax
jne 0x312b
cmpl $0x0, 0x1659e(%rip)     # 0x19708
jle 0x34e3
movl $0x8, %edi
callq 0x21f0
movq %rax, %r14
movq %rax, %rdi
callq 0xa032
movq %r14, 0x165c4(%rip)     # 0x19750
movl 0x16572(%rip), %edx     # 0x19704
movzbl 0x16567(%rip), %ecx     # 0x19700
leaq 0x165c0(%rip), %rdi     # 0x19760
movq %r14, %rsi
callq 0xbe94
movq %rsp, -0x98(%rbp)
movl 0x16553(%rip), %ecx     # 0x19708
movq %rsp, %r14
movq %rcx, %rax
shlq $0x4, %rax
movq %rax, -0x50(%rbp)
leaq (%rax,%rax,2), %rax
subq %rax, %r14
movq %r14, %rsp
movq %rcx, -0x58(%rbp)
testq %rcx, %rcx
je 0x31fc
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 0x31dc
leaq 0xe033(%rip), %rdi      # 0x11236
xorl %eax, %eax
callq 0x2060
movq $0x0, 0x1650b(%rip) # 0x19720
cmpl $0x0, 0x164ec(%rip)     # 0x19708
jle 0x32e5
xorl %ebx, %ebx
movq 0x14d95(%rip), %r12     # 0x17fc0
movq %r14, %r15
movq 0x16503(%rip), %rdi     # 0x19738
movq (%rdi), %rax
callq *0x90(%rax)
movq 0x164f3(%rip), %rdi     # 0x19738
movl 0x164c5(%rip), %esi     # 0x19710
movl 0x164c3(%rip), %edx     # 0x19714
callq 0xb3ac
movq 0x164db(%rip), %rdi     # 0x19738
movq (%rdi), %rax
callq *0x78(%rax)
movq 0x164ce(%rip), %rdi     # 0x19738
movq (%rdi), %rax
callq *0x88(%rax)
xorl %edi, %edi
callq 0xb2cc
movq 0x164cf(%rip), %rdi     # 0x19750
movq 0x164b0(%rip), %rsi     # 0x19738
callq 0xa454
xorl %edi, %edi
callq 0xb2ec
xorl %edi, %edi
callq 0xb30c
addsd 0x1647d(%rip), %xmm0    # 0x19720
movsd %xmm0, 0x16475(%rip)    # 0x19720
movq 0x1649e(%rip), %rdi     # 0x19750
movl 0x1644c(%rip), %edx     # 0x19704
movq %r15, %rsi
callq 0xa6e8
movq (%r12), %rsi
movl $0x2e, %edi
callq 0x2280
incq %rbx
movslq 0x16430(%rip), %rax     # 0x19708
addq $0x30, %r15
cmpq %rax, %rbx
jl 0x322e
movq 0x14cd4(%rip), %rax     # 0x17fc0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x2280
cvtsi2sdl 0x16407(%rip), %xmm1 # 0x19708
movsd 0x16417(%rip), %xmm0    # 0x19720
divsd %xmm1, %xmm0
movsd %xmm0, 0x1640b(%rip)    # 0x19720
leaq 0xdf36(%rip), %rdi      # 0x11252
movb $0x1, %al
callq 0x2060
movq -0x78(%rbp), %rcx
leaq -0x88(%rbp), %rax
movq %rcx, -0x40(%rbp)
cmpq %rax, %rcx
movq -0x38(%rbp), %rbx
je 0x34ba
xorl %r15d, %r15d
movq %r15, -0x60(%rbp)
movl 0x163bc(%rip), %eax     # 0x19708
testl %eax, %eax
jle 0x343b
movq -0x40(%rbp), %rax
leaq 0x20(%rax), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r14, %r12
xorl %r13d, %r13d
movq %r12, %rdi
movq %r15, %rsi
callq 0x4404
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
incq %r13
movslq 0x16373(%rip), %rax     # 0x19708
addq $0x30, %r12
cmpq %rax, %r13
jl 0x336b
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
xorpd %xmm0, %xmm0
testl %eax, %eax
jle 0x3453
movsd %xmm0, -0x48(%rbp)
movq %r14, %r12
xorl %r13d, %r13d
movq %r12, %rdi
movq %r15, %rsi
callq 0x4404
movl (%rax), %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0x4404
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%rax), %xmm1
movsd -0x30(%rbp), %xmm2
subsd %xmm2, %xmm0
subsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movslq 0x16300(%rip), %rax     # 0x19708
leal -0x1(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd %xmm0, %xmm1
movsd -0x48(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
incq %r13
addq $0x30, %r12
cmpq %rax, %r13
jl 0x33ca
movq -0x38(%rbp), %rbx
movsd -0x48(%rbp), %xmm0
jmp 0x3453
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0x30(%rbp)
ucomisd 0xdbb5(%rip), %xmm0     # 0x11010
jb 0x3463
sqrtsd %xmm0, %xmm0
jmp 0x3468
callq 0x2190
movq -0x60(%rbp), %r15
movq -0x40(%rbp), %rdi
xorps %xmm1, %xmm1
cvtsi2sdl 0x40(%rdi), %xmm1
movsd -0x30(%rbp), %xmm2
subsd %xmm2, %xmm1
divsd %xmm0, %xmm1
leaq (%r15,%r15,4), %rax
movsd %xmm2, 0x10(%rbx,%rax,8)
movsd %xmm0, 0x18(%rbx,%rax,8)
movsd %xmm1, 0x20(%rbx,%rax,8)
callq 0x2230
movq %rax, %rcx
incq %r15
leaq -0x88(%rbp), %rax
movq %rcx, -0x40(%rbp)
cmpq %rax, %rcx
jne 0x3342
cmpq $0x0, -0x58(%rbp)
je 0x34dc
addq $-0x30, %r14
movq -0x50(%rbp), %rax
leaq (%rax,%rax,2), %rbx
leaq (%r14,%rbx), %rdi
callq 0x448c
addq $-0x30, %rbx
jne 0x34cd
movq -0x98(%rbp), %rsp
movq -0x68(%rbp), %rsi
leaq -0x81c(%rip), %rcx      # 0x2cd2
movl $0x28, %edx
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x23c0
movl -0x68(%rbp), %esi
movq %rbx, %rdi
callq 0x35d8
leaq 0xdd66(%rip), %rdi      # 0x11277
leaq 0x159e8(%rip), %rsi     # 0x18f00
xorl %eax, %eax
callq 0x2060
cmpb $0x1, 0x161db(%rip)     # 0x19701
jne 0x353d
leaq 0xdd66(%rip), %rdi      # 0x11295
leaq 0x15dca(%rip), %rsi     # 0x19300
xorl %eax, %eax
callq 0x2060
cmpl $0x0, -0x68(%rbp)
movq -0x38(%rbp), %r14
jle 0x3561
xorl %ebx, %ebx
movq (%r14), %rdi
callq 0x2260
incq %rbx
movslq -0x68(%rbp), %rax
addq $0x28, %r14
cmpq %rax, %rbx
jl 0x3549
movq -0xa0(%rbp), %rsp
leaq -0x90(%rbp), %rdi
callq 0x448c
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 0x35c3
movq %rax, %rbx
jmp 0x35c3
jmp 0x359e
jmp 0x359e
movq %rax, %rbx
cmpq $0x0, -0x58(%rbp)
je 0x35c3
addq $-0x30, %r14
movq -0x50(%rbp), %rax
leaq (%rax,%rax,2), %r15
leaq (%r14,%r15), %rdi
callq 0x448c
addq $-0x30, %r15
jne 0x35b4
leaq -0x90(%rbp), %rdi
callq 0x448c
movq %rbx, %rdi
callq 0x2370
nop