// File: /workspace/github_cpp_makefile_star2_O3/spatialfruitsalad[P]volume2position/./selectedAreaHistogram.hpp
// Function: void selectedAreaHistogram::Process<unsigned short>(tomogram3d<unsigned short>&, std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned int)
void Process (tomogram3d<VALUE>& t, std::vector<double>& binvec, std::vector<double>& histvec, std::string foldername, unsigned int bins = 150)
    {
        std::cout << "start processing tomogram" << std::endl;

        unsigned int nx, ny, nz;
        nx = t.get_sx();
        ny = t.get_sy();
        nz = t.get_sz();

        std::vector<VALUE> greyvalues;
        long double mean = 0.0;
        unsigned int pixelsCounted = 0;
        // get all selected areas and create a vector of all grey values
        for (unsigned long k = 0; k != nz; ++k)
        for (unsigned long j = 0; j != ny; ++j)
        for (unsigned long i = 0; i != nx; ++i)
        {
            // check if the current voxel is in one of the areas
            for(auto it = m_areas.begin(); it != m_areas.end(); ++it)
            {
                if((*it).contains(i,j,k))
                {
                    pixelsCounted++;           
                    VALUE v = t.get(i,j,k);
                    greyvalues.push_back(v);
                    mean += v;
                }
            }
        }
        std::cout << "voxels counted: " << pixelsCounted << " which is a fraction of " << static_cast<double>(pixelsCounted)/static_cast<double>((nx*ny*nz)) << " of all voxels" << std::endl;
        mean /= static_cast<double>(pixelsCounted);
        std::cout << "mean value of: " << mean << std::endl;

        auto min =  (*std::min_element(greyvalues.begin(), greyvalues.end()));
        auto max =  (*std::max_element(greyvalues.begin(), greyvalues.end()));
        std::cout << "min: " << static_cast<int>(min) << std::endl << "max: " << static_cast<int>(max) << std::endl;

        auto diff = max - min;
        // create a histogram of all selected grey values
        long double binsize = static_cast<long double>(diff)/static_cast<long double>(bins);

        binvec.resize(bins + 1, 0);
        for (size_t i = 0; i != binvec.size(); ++i)
        {
           double gv = min + i * binsize;
           binvec.at(i) = gv;
        }
        histvec.resize(bins + 1, 0);
        for(auto n : greyvalues)
        {
            long double u = static_cast<long double>(n - min);
            long double v = static_cast<long double>(binsize);
            size_t idx = static_cast<size_t>(u/v);
            histvec.at(idx) += 1;
        }

        {
        std::cout << "write selected Area Histogram" << std::endl;
        std::ofstream out(foldername + "/selectedAreaHist.dat");
        for (size_t i = 0; i != histvec.size(); ++i)
        {
            long double gv = binvec.at(i);
            auto f = histvec.at(i);
            out << gv << " " << f << std::endl;      
        }
        out.close();
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movq %r9, 0x80(%rsp)
movq %r8, 0x78(%rsp)
movq %rcx, 0x88(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, %r14
movq %rdi, %rbp
movq 0x14ba6(%rip), %rbx     # 0x1cfc8
leaq 0xf890(%rip), %rsi      # 0x17cb9
movl $0x19, %edx
movq %rbx, %rdi
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x18(%r14), %rcx
movq 0x20(%r14), %rax
movq %r14, 0xb0(%rsp)
movq 0x28(%r14), %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
fldz
movq %rsi, 0x90(%rsp)
andq %rsi, %rdi
movq %rdi, 0xa8(%rsp)
movq %rax, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
je 0x85c1
fstp %st(0)
movl %ecx, %ecx
movq %rcx, 0x70(%rsp)
movl %eax, %eax
movq %rax, 0x68(%rsp)
xorl %r12d, %r12d
fldz
fstpt 0x20(%rsp)
xorl %r14d, %r14d
cmpq $0x0, 0x68(%rsp)
je 0x85ae
xorl %ebx, %ebx
cmpq $0x0, 0x70(%rsp)
je 0x85a0
movq 0x8(%rbp), %rax
xorl %r15d, %r15d
movq (%rbp), %r13
cmpq %rax, %r13
je 0x8592
cmpl %r14d, (%r13)
jne 0x8589
cmpl %r15d, 0x8(%r13)
jb 0x8589
cmpl %r15d, 0x4(%r13)
ja 0x8589
cmpl %ebx, 0x10(%r13)
jb 0x8589
cmpl %ebx, 0xc(%r13)
ja 0x8589
movq 0xb0(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x8fee
movw %ax, 0xf8(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x8558
movw %ax, (%rsi)
addq $0x2, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x856a
leaq 0x30(%rsp), %rdi
leaq 0xf8(%rsp), %rdx
callq 0x14e2c
incl %r12d
movzwl 0xf8(%rsp), %eax
movl %eax, 0x5c(%rsp)
fldt 0x20(%rsp)
fiaddl 0x5c(%rsp)
fstpt 0x20(%rsp)
movq 0x8(%rbp), %rax
addq $0x14, %r13
jmp 0x84f5
incq %r15
cmpq 0x70(%rsp), %r15
jne 0x84f1
incq %rbx
cmpq 0x68(%rsp), %rbx
jne 0x84de
incq %r14
cmpq 0xa8(%rsp), %r14
jne 0x84d0
jmp 0x85c8
fstpt 0x20(%rsp)
xorl %r12d, %r12d
movq 0x149f9(%rip), %rdi     # 0x1cfc8
leaq 0xf6fd(%rip), %rsi      # 0x17cd3
movl $0x10, %edx
callq 0x32f0
movl %r12d, %ebx
movq 0x149de(%rip), %rdi     # 0x1cfc8
movq %rbx, %rsi
callq 0x31d0
movq %rax, %r14
leaq 0xf6e8(%rip), %rsi      # 0x17ce4
movl $0x18, %edx
movq %rax, %rdi
callq 0x32f0
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movq 0xa0(%rsp), %rax
imull 0x98(%rsp), %eax
imull 0x90(%rsp), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq %r14, %rdi
callq 0x33c0
movq %rax, %r14
leaq 0xf6b9(%rip), %rsi      # 0x17cfd
movl $0xe, %edx
movq %rax, %rdi
callq 0x32f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x14949(%rip), %rdi     # 0x1cfc8
leaq 0xf686(%rip), %rsi      # 0x17d0c
movl $0xf, %edx
callq 0x32f0
movq %rbx, 0xd0(%rsp)
fildll 0xd0(%rsp)
fldt 0x20(%rsp)
fdivp %st, %st(1)
fstpt (%rsp)
movq 0x14919(%rip), %rdi     # 0x1cfc8
callq 0x3170
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
cmpq %rcx, %rax
sete %sil
movq %rax, %rdx
addq $0x2, %rdx
cmpq %rcx, %rdx
sete %dil
orb %sil, %dil
movzwl (%rax), %ebp
movq 0x88(%rsp), %r13
movq 0x80(%rsp), %r15
jne 0x8751
movl %ebp, %esi
movq %rdx, %r8
movq %rax, %rdi
movzwl (%r8), %r9d
cmpw %si, %r9w
cmovbl %r9d, %esi
cmovbq %r8, %rdi
addq $0x2, %r8
cmpq %rcx, %r8
jne 0x871d
movzwl (%rdi), %esi
movzwl (%rdx), %edi
cmpw %di, %bp
cmovbel %edi, %ebp
cmovbq %rdx, %rax
addq $0x2, %rdx
cmpq %rcx, %rdx
jne 0x8739
movl %esi, %ebp
movzwl (%rax), %ebx
movq 0x1486d(%rip), %rdi     # 0x1cfc8
leaq 0xf5ba(%rip), %rsi      # 0x17d1c
movl $0x5, %edx
callq 0x32f0
movzwl %bp, %ebp
movq 0x14852(%rip), %rdi     # 0x1cfc8
movl %ebp, %esi
callq 0x3420
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq %rax, %r14
leaq 0xf571(%rip), %rsi      # 0x17d22
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
movq %r14, %rdi
movl %ebx, %esi
callq 0x3420
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
subl %ebp, %ebx
movl %ebx, 0x58(%rsp)
movl %r15d, %eax
movq %rax, 0xc8(%rsp)
fildll 0xc8(%rsp)
fidivrl 0x58(%rsp)
fstpt 0x20(%rsp)
incl %r15d
leaq 0xf8(%rsp), %rdx
movq $0x0, (%rdx)
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x14df8
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
fldt 0x20(%rsp)
fldz
je 0x8890
fstp %st(0)
sarq $0x3, %rdx
movl %ebp, 0x54(%rsp)
xorl %ecx, %ecx
fildl 0x54(%rsp)
leaq 0xe803(%rip), %rsi      # 0x17060
cmpq %rcx, %rdx
je 0x8b36
movq %rcx, 0xc0(%rsp)
xorl %edi, %edi
testq %rcx, %rcx
sets %dil
fildll 0xc0(%rsp)
fadds (%rsi,%rdi,4)
fmul %st(2), %st
fadd %st(1), %st
fstpl (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rdx
jne 0x885d
fstp %st(0)
fstp %st(0)
leaq 0xf8(%rsp), %rdx
movq $0x0, (%rdx)
movq %r13, %rdi
movq %r15, %rsi
callq 0x14df8
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
cmpq %rcx, %rax
fldt 0x20(%rsp)
je 0x8955
movq (%r13), %rdi
movq 0x8(%r13), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
movsd 0xe774(%rip), %xmm0     # 0x17050
movzwl (%rax), %esi
subl %ebp, %esi
movl %esi, 0x50(%rsp)
fld %st(0)
fidivrl 0x50(%rsp)
flds 0xe84f(%rip)            # 0x17140
xorl %esi, %esi
fxch %st(1)
fucomi %st(1), %st
setae %sil
fldz
fcmovnb %st(2), %st
fstp %st(2)
fsubp %st, %st(1)
fnstcw 0x1e(%rsp)
movzwl 0x1e(%rsp), %r8d
orl $0xc00, %r8d            # imm = 0xC00
movw %r8w, 0x2e(%rsp)
fldcw 0x2e(%rsp)
fistpll 0xb8(%rsp)
fldcw 0x1e(%rsp)
shlq $0x3f, %rsi
xorq 0xb8(%rsp), %rsi
cmpq %rsi, %rdx
jbe 0x8b4b
movsd (%rdi,%rsi,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%rsi,8)
addq $0x2, %rax
cmpq %rcx, %rax
jne 0x88dc
fstp %st(0)
movq 0x1466a(%rip), %rbx     # 0x1cfc8
leaq 0xf3c3(%rip), %rsi      # 0x17d28
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x32f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq 0x14638(%rip), %rdi     # 0x1cfc8
callq 0x3040
movq %rax, %rdi
callq 0x31e0
leaq 0xe8(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x78(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %rdi
callq 0x12fde
movq 0x60(%rsp), %rbp
leaq 0xf375(%rip), %rsi      # 0x17d46
leaq 0xd8(%rsp), %rdi
callq 0x3470
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
movl $0x10, %edx
callq 0x3480
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x8a0a
callq 0x3280
movq (%r13), %rcx
movq 0x8(%r13), %rdx
subq %rcx, %rdx
je 0x8ad0
sarq $0x3, %rdx
xorl %ebx, %ebx
leaq 0xf8(%rsp), %r14
leaq 0xf287(%rip), %r15      # 0x17cb7
movq (%rbp), %rsi
movq 0x8(%rbp), %rax
subq %rsi, %rax
sarq $0x3, %rax
cmpq %rbx, %rax
jbe 0x8b5b
cmpq %rbx, %rdx
jbe 0x8b6f
fldl (%rsi,%rbx,8)
movsd (%rcx,%rbx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
fstpt (%rsp)
movq %r14, %rdi
callq 0x3170
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x32f0
movq %r12, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x33c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
incq %rbx
movq (%r13), %rcx
movq 0x8(%r13), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rdx, %rbx
jne 0x8a30
leaq 0xf8(%rsp), %rdi
callq 0x3360
movq 0x144d4(%rip), %rax     # 0x1cfb8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x100(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0xf8(%rsp,%rcx)
callq 0x3250
leaq 0x1f0(%rsp), %rdi
callq 0x30c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8b24
callq 0x3280
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
fstp %st(0)
fstp %st(0)
leaq 0xec18(%rip), %rdi      # 0x17759
movq %rdx, %rsi
xorl %eax, %eax
callq 0x3390
fstp %st(0)
leaq 0xec05(%rip), %rdi      # 0x17759
xorl %eax, %eax
callq 0x3390
leaq 0xebf7(%rip), %rdi      # 0x17759
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3390
leaq 0xebe3(%rip), %rdi      # 0x17759
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3390
jmp 0x8baf
jmp 0x8b84
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x8bc4
callq 0x3280
jmp 0x8bc4
jmp 0x8bc1
jmp 0x8bc1
jmp 0x8bc1
jmp 0x8bc1
jmp 0x8bc1
jmp 0x8bc1
jmp 0x8baf
jmp 0x8baf
jmp 0x8bc1
jmp 0x8bc1
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3380
jmp 0x8bc4
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8bd3
callq 0x3280
movq %rbx, %rdi
callq 0x3430
nop