// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/psd.cc
// Function: Histogram(std::ostream&, double, int, std::vector<double, std::allocator<double>>&, int, double, double, int)
void Histogram(ostream& output, const double binSize, const int maxBins, vector<double>& diam, int count, double nodefrac, double outfrac, int numSamples){
  assert(binSize > threshold);
  int bins[maxBins]; 
  double cumBins[maxBins];
  double derivBins[maxBins];
  for (int i=0; i<maxBins; i++){
    bins[i] = 0;
    cumBins[i] = 0;
    derivBins[i] = 0;
  }
 
  int bin;
  for (unsigned int i=0; i<diam.size(); i++){
    bin = diam.at(i)/binSize;
    if (bin >= maxBins){
      bin = maxBins - 1;
    }
    bins[bin]++;
    for (int j=0; j<bin+1; j++){
      cumBins[j]++;
    }
  }
//Cumulative distribution: 1 is added to the bin PLUS all preceding bins. 
//Each bin is divided by the value of the first bin.
  double maxC= cumBins[0];
  for (unsigned int b=0; b<maxBins; b++){
    cumBins[b] = (cumBins[b]/maxC);
  }
//Derivative of cumulative distribution: This is pore size distribution. 
  double deriv;
  for (unsigned int n=1; n<maxBins-1; n++){
    double fxh= cumBins[n+1];
    double fx = cumBins[n-1];
    deriv = (fxh-fx)/(2.0*binSize);
    if (deriv!=0) deriv= deriv*-1.0;
    if (deriv >= maxBins){
      deriv = maxBins - 1;
    }
    derivBins[n]=deriv;
  }
 
  double numBin;
  numBin = binSize * 1.0 * maxBins;

  //new format - easier to parse
  output << "Pore size distribution histogram\nBin size (A): "<<binSize<<"\nNumber of bins: "<<maxBins<<"\nFrom: 0\nTo: "<<numBin<<"\nTotal samples: "<<numSamples<<"\nAccessible samples: "<<count<<"\nFraction of sample points in node spheres: "<<nodefrac<<"\nFraction of sample points outside node spheres: "<<outfrac<<"\n\nBin Count Cumulative_dist Derivative_dist\n";
  for (int i=0; i<maxBins; i++){
    output<<binSize*1.0*i<<" "<<bins[i]<<" "<<cumBins[i]<<" "<<derivBins[i]<<"\n";
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm2, -0x70(%rbp)
movsd %xmm1, -0x68(%rbp)
movq %rdi, -0x50(%rbp)
movsd %xmm0, -0x30(%rbp)
ucomisd 0x98005(%rip), %xmm0    # 0x1011e8
jbe 0x694e9
movl %ecx, %r9d
movq %rdx, %r13
movl %esi, %edx
movq %rsp, %rcx
leaq 0xf(,%rdx,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x40(%rbp)
movq %rcx, %rsp
movq %rsp, %r12
movq %rdx, -0x60(%rbp)
leaq 0xf(,%rdx,8), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
xorl %eax, %eax
testl %esi, %esi
movl $0x0, %ecx
cmovgl %esi, %ecx
movq %rcx, -0x58(%rbp)
movq -0x40(%rbp), %rcx
cmpq %rax, -0x58(%rbp)
je 0x69259
andl $0x0, (%rcx,%rax,4)
andq $0x0, (%r12,%rax,8)
andq $0x0, (%r15,%rax,8)
incq %rax
jmp 0x69240
movl %r8d, -0x44(%rbp)
movl %r9d, -0x48(%rbp)
leal -0x1(%rsi), %eax
movl %eax, -0x38(%rbp)
xorl %r14d, %r14d
movl %r14d, %r14d
movq 0x8(%r13), %rax
subq (%r13), %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x692da
movq %r13, %rdi
movq %r15, %rbx
movq %rsi, %r15
movq %r14, %rsi
callq 0xaa50
movsd 0x92dc1(%rip), %xmm1    # 0xfc058
movq %r15, %rsi
movq %rbx, %r15
movsd (%rax), %xmm0
divsd -0x30(%rbp), %xmm0
cvttsd2si %xmm0, %eax
cmpl %esi, %eax
cmovgel -0x38(%rbp), %eax
cltq
movq -0x40(%rbp), %rcx
incl (%rcx,%rax,4)
xorl %ecx, %ecx
cmpq %rax, %rcx
jg 0x692d5
movsd (%r12,%rcx,8), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%r12,%rcx,8)
incq %rcx
jmp 0x692bb
incl %r14d
jmp 0x6926a
movsd (%r12), %xmm0
xorl %eax, %eax
movq -0x60(%rbp), %rcx
cmpq %rax, %rcx
je 0x69300
movsd (%r12,%rax,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r12,%rax,8)
incq %rax
jmp 0x692e6
movsd -0x30(%rbp), %xmm0
cvtsi2sd %esi, %xmm6
movl -0x38(%rbp), %eax
cvtsi2sd %eax, %xmm1
addsd %xmm0, %xmm0
movl %eax, %eax
pushq $0x1
popq %rcx
movapd 0x972af(%rip), %xmm2    # 0x1005d0
movl -0x48(%rbp), %ebx
cmpq %rax, %rcx
jae 0x6937c
movsd 0x8(%r12,%rcx,8), %xmm3
subsd -0x8(%r12,%rcx,8), %xmm3
divsd %xmm0, %xmm3
movapd %xmm3, %xmm4
xorpd %xmm2, %xmm4
movapd %xmm3, %xmm5
cmpneqsd %xmm4, %xmm5
andpd %xmm5, %xmm4
andnpd %xmm3, %xmm5
orpd %xmm4, %xmm5
movapd %xmm6, %xmm3
cmpnlesd %xmm5, %xmm3
movapd %xmm3, %xmm4
andpd %xmm5, %xmm4
andnpd %xmm1, %xmm3
orpd %xmm4, %xmm3
movlpd %xmm3, (%r15,%rcx,8)
incq %rcx
jmp 0x69324
mulsd -0x30(%rbp), %xmm6
movsd %xmm6, -0x38(%rbp)
movq %rsi, %r14
leaq 0x9b705(%rip), %rsi     # 0x104a95
movq -0x50(%rbp), %rdi
callq 0x4480
movq %rax, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x46c0
leaq 0x9b718(%rip), %rsi     # 0x104ac5
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movl %r14d, %esi
callq 0x4760
leaq 0x9b710(%rip), %rsi     # 0x104ad7
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x46c0
leaq 0x9b702(%rip), %rsi     # 0x104ae5
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movl -0x44(%rbp), %esi
callq 0x4760
leaq 0x9b6f9(%rip), %rsi     # 0x104af6
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movl %ebx, %esi
callq 0x4760
leaq 0x9b6f6(%rip), %rsi     # 0x104b0c
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movsd -0x68(%rbp), %xmm0
callq 0x46c0
leaq 0x9b707(%rip), %rsi     # 0x104b39
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movsd -0x70(%rbp), %xmm0
callq 0x46c0
leaq 0x9b71d(%rip), %rsi     # 0x104b6b
movq %rax, %rdi
callq 0x4480
xorl %ebx, %ebx
leaq 0x9b0b3(%rip), %r14     # 0x104512
leaq 0x99118(%rip), %r13     # 0x10257e
cmpq %rbx, -0x58(%rbp)
je 0x694da
cvtsi2sd %ebx, %xmm0
mulsd -0x30(%rbp), %xmm0
movq -0x50(%rbp), %rdi
callq 0x46c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x4480
movq -0x40(%rbp), %rcx
movl (%rcx,%rbx,4), %esi
movq %rax, %rdi
callq 0x4760
movq %rax, %rdi
movq %r14, %rsi
callq 0x4480
movsd (%r12,%rbx,8), %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x4480
movsd (%r15,%rbx,8), %xmm0
movq %rax, %rdi
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
incq %rbx
jmp 0x69466
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x980c5(%rip), %rdi     # 0x1015b5
leaq 0x9b538(%rip), %rsi     # 0x104a2f
leaq 0x9b538(%rip), %rcx     # 0x104a36
movl $0x2ef, %edx            # imm = 0x2EF
callq 0x42c0