// File: princelab[P]emass/emass.cpp
// Function: print_pattern(std::vector<peak, std::allocator<peak>>&, int)
void print_pattern(Pattern & result, int digits)
{
  // find the maximum
  double max_area = 0;
  double sum_area = 0;
  for(Pattern::iterator i = result.begin(); i != result.end(); ++i) {
    if(max_area < (*i).rel_area)
      max_area = (*i).rel_area;
    sum_area += (*i).rel_area;
  }
  if(max_area == 0)
    return; // empty pattern

  wcout.setf(ios::fixed);
  wcout.precision(digits);
  double print_limit = pow(10.0, -digits) / 2;
  //wcout.precision(30);
  //double print_limit = 0.000001 / 2;
  for(Pattern::iterator i = result.begin(); i != result.end(); ++i) {
    double mass = (*i).mass;
    double rel_area = (*i).rel_area;
    double val_perc = rel_area / max_area * 100;
    //double val_norm = rel_area / sum_area;
    if(mass != DUMMY_MASS && val_perc >= print_limit)
      wcout << mass << L" " << val_perc << endl;
    //wcout << mass << L" " << val_perc << L" " << val_norm << endl;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6490
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6500
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x64c0
testb $0x1, %al
jne 0x519c
jmp 0x51f5
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6530
movsd -0x68(%rbp), %xmm1
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x51d2
leaq -0x28(%rbp), %rdi
callq 0x6530
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6530
movsd 0x8(%rax), %xmm0
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x6690
jmp 0x517c
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x520a
jp 0x520a
jmp 0x534d
movq 0x15db7(%rip), %rax     # 0x1afc8
movq (%rax), %rax
movq 0x15dad(%rip), %rdi     # 0x1afc8
addq -0x18(%rax), %rdi
movl $0x4, %esi
callq 0x66b0
movq 0x15d98(%rip), %rax     # 0x1afc8
movq (%rax), %rax
movq 0x15d8e(%rip), %rdi     # 0x1afc8
addq -0x18(%rax), %rdi
movslq -0xc(%rbp), %rsi
callq 0x66e0
xorl %eax, %eax
subl -0xc(%rbp), %eax
cvtsi2sd %eax, %xmm1
movsd 0xcdc8(%rip), %xmm0     # 0x12020
callq 0x4610
movsd 0xcdb3(%rip), %xmm1     # 0x12018
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6490
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6500
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x64c0
testb $0x1, %al
jne 0x529e
jmp 0x534d
leaq -0x40(%rbp), %rdi
callq 0x6530
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x6530
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
divsd -0x18(%rbp), %xmm0
movsd 0xcd53(%rip), %xmm1     # 0x12028
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x50(%rbp), %xmm0
movsd 0xcd25(%rip), %xmm1     # 0x12010
ucomisd %xmm1, %xmm0
jne 0x52f5
jp 0x52f5
jmp 0x533d
movsd -0x60(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jb 0x533d
movsd -0x50(%rbp), %xmm0
movq 0x15cbb(%rip), %rdi     # 0x1afc8
callq 0x4210
movq %rax, %rdi
leaq 0xcd68(%rip), %rsi      # 0x12084
callq 0x46a0
movq %rax, %rdi
movsd -0x60(%rbp), %xmm0
callq 0x4210
movq %rax, %rdi
movq 0x15c78(%rip), %rsi     # 0x1afb0
callq 0x4600
jmp 0x533f
leaq -0x40(%rbp), %rdi
callq 0x6690
jmp 0x527b
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)