// File: /workspace/github_cpp_makefile_star2_O1/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 0x14a32(%rip), %rbx     # 0x1cfc8
leaq 0xf72c(%rip), %rsi      # 0x17cc9
movl $0x19, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32b0
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 0x872a
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 0x8717
xorl %ebx, %ebx
cmpq $0x0, 0x70(%rsp)
je 0x8709
xorl %r15d, %r15d
movq (%rbp), %r13
cmpq 0x8(%rbp), %r13
je 0x86fb
cmpl %r14d, (%r13)
jne 0x86f2
cmpl %r15d, 0x8(%r13)
jb 0x86f2
cmpl %r15d, 0x4(%r13)
ja 0x86f2
cmpl %ebx, 0x10(%r13)
jb 0x86f2
cmpl %ebx, 0xc(%r13)
ja 0x86f2
movq 0xb0(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x9144
movw %ax, 0xf8(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x86c5
movw %ax, (%rsi)
addq $0x2, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x86d7
leaq 0x30(%rsp), %rdi
leaq 0xf8(%rsp), %rdx
callq 0x14f9c
incl %r12d
movzwl 0xf8(%rsp), %eax
movl %eax, 0x5c(%rsp)
fldt 0x20(%rsp)
fiaddl 0x5c(%rsp)
fstpt 0x20(%rsp)
addq $0x14, %r13
jmp 0x8665
incq %r15
cmpq 0x70(%rsp), %r15
jne 0x8661
incq %rbx
cmpq 0x68(%rsp), %rbx
jne 0x8652
incq %r14
cmpq 0xa8(%rsp), %r14
jne 0x8644
jmp 0x8731
fstpt 0x20(%rsp)
xorl %r12d, %r12d
movq 0x14890(%rip), %rdi     # 0x1cfc8
leaq 0xf5a4(%rip), %rsi      # 0x17ce3
movl $0x10, %edx
callq 0x3300
movl %r12d, %ebx
movq 0x14875(%rip), %rdi     # 0x1cfc8
movq %rbx, %rsi
callq 0x31d0
movq %rax, %r14
leaq 0xf58f(%rip), %rsi      # 0x17cf4
movl $0x18, %edx
movq %rax, %rdi
callq 0x3300
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 0x33d0
movq %rax, %r14
leaq 0xf560(%rip), %rsi      # 0x17d0d
movl $0xe, %edx
movq %rax, %rdi
callq 0x3300
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x147e0(%rip), %rdi     # 0x1cfc8
leaq 0xf52d(%rip), %rsi      # 0x17d1c
movl $0xf, %edx
callq 0x3300
movq %rbx, 0xd0(%rsp)
fildll 0xd0(%rsp)
fldt 0x20(%rsp)
fdivp %st, %st(1)
fstpt (%rsp)
movq 0x147b0(%rip), %rdi     # 0x1cfc8
callq 0x3170
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rax
cmpq %rax, %rdx
sete %sil
movq %rdx, %rcx
addq $0x2, %rcx
cmpq %rax, %rcx
sete %dil
orb %sil, %dil
movq %rdx, %rsi
movq 0x88(%rsp), %r13
movq 0x80(%rsp), %r15
jne 0x88a0
movq %rcx, %r8
movq %rdx, %r9
movzwl (%r8), %r10d
movq %r8, %rsi
cmpw (%r9), %r10w
jb 0x8894
movq %r9, %rsi
addq $0x2, %r8
movq %rsi, %r9
cmpq %rax, %r8
jne 0x8884
testb %dil, %dil
je 0x88aa
movq %rdx, %rdi
jmp 0x88c6
movzwl (%rdx), %r8d
movq %rcx, %rdi
cmpw (%rcx), %r8w
jb 0x88ba
movq %rdx, %rdi
addq $0x2, %rcx
movq %rdi, %rdx
cmpq %rax, %rcx
jne 0x88aa
movzwl (%rsi), %ebp
movzwl (%rdi), %ebx
movq 0x146f5(%rip), %rdi     # 0x1cfc8
leaq 0xf452(%rip), %rsi      # 0x17d2c
movl $0x5, %edx
callq 0x3300
movq 0x146dd(%rip), %rdi     # 0x1cfc8
movl %ebp, %esi
callq 0x3430
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq %rax, %r14
leaq 0xf40c(%rip), %rsi      # 0x17d32
movl $0x5, %edx
movq %rax, %rdi
callq 0x3300
movq %r14, %rdi
movl %ebx, %esi
callq 0x3430
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
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 0x14f68
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
fldt 0x20(%rsp)
fldz
je 0x8a05
fstp %st(0)
sarq $0x3, %rdx
movl %ebp, 0x54(%rsp)
xorl %esi, %esi
fildl 0x54(%rsp)
leaq 0xe696(%rip), %rcx      # 0x17068
cmpq %rsi, %rdx
je 0x8cab
movq %rsi, 0xc0(%rsp)
xorl %edi, %edi
testq %rsi, %rsi
sets %dil
fildll 0xc0(%rsp)
fadds (%rcx,%rdi,4)
fmul %st(2), %st
fadd %st(1), %st
fstpl (%rax,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x89d2
fstp %st(0)
fstp %st(0)
leaq 0xf8(%rsp), %rdx
movq $0x0, (%rdx)
movq %r13, %rdi
movq %r15, %rsi
callq 0x14f68
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
cmpq %rcx, %rax
fldt 0x20(%rsp)
je 0x8aca
movq (%r13), %rdi
movq 0x8(%r13), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
movsd 0xe5ff(%rip), %xmm0     # 0x17050
movzwl (%rax), %esi
subl %ebp, %esi
movl %esi, 0x50(%rsp)
fld %st(0)
fidivrl 0x50(%rsp)
flds 0xe6ea(%rip)            # 0x17150
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 0x8cbd
movsd (%rdi,%rsi,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%rsi,8)
addq $0x2, %rax
cmpq %rcx, %rax
jne 0x8a51
fstp %st(0)
movq 0x144f5(%rip), %rbx     # 0x1cfc8
leaq 0xf25e(%rip), %rsi      # 0x17d38
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq 0x144c3(%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 0x1312e
movq 0x60(%rsp), %rbp
leaq 0xf210(%rip), %rsi      # 0x17d56
leaq 0xd8(%rsp), %rdi
callq 0x3480
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
movl $0x10, %edx
callq 0x3490
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x8b7f
callq 0x3290
movq (%r13), %rcx
movq 0x8(%r13), %rdx
subq %rcx, %rdx
je 0x8c45
sarq $0x3, %rdx
xorl %ebx, %ebx
leaq 0xf8(%rsp), %r14
leaq 0xf122(%rip), %r15      # 0x17cc7
movq (%rbp), %rsi
movq 0x8(%rbp), %rax
subq %rsi, %rax
sarq $0x3, %rax
cmpq %rbx, %rax
jbe 0x8ccd
cmpq %rbx, %rdx
jbe 0x8ce1
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 0x3300
movq %r12, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x33d0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x32b0
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 0x8ba5
leaq 0xf8(%rsp), %rdi
callq 0x3370
movq 0x1435f(%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 0x3260
leaq 0x1f0(%rsp), %rdi
callq 0x30c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8c99
callq 0x3290
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 0xeab3(%rip), %rdi      # 0x17769
xorl %eax, %eax
callq 0x33a0
fstp %st(0)
leaq 0xeaa3(%rip), %rdi      # 0x17769
xorl %eax, %eax
callq 0x33a0
leaq 0xea95(%rip), %rdi      # 0x17769
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x33a0
leaq 0xea81(%rip), %rdi      # 0x17769
movq %rbx, %rsi
xorl %eax, %eax
callq 0x33a0
jmp 0x8d21
jmp 0x8cf6
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x8d36
callq 0x3290
jmp 0x8d36
jmp 0x8d33
jmp 0x8d33
jmp 0x8d33
jmp 0x8d33
jmp 0x8d33
jmp 0x8d33
jmp 0x8d21
jmp 0x8d21
jmp 0x8d33
jmp 0x8d33
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3390
jmp 0x8d36
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8d45
callq 0x3290
movq %rbx, %rdi
callq 0x3440
nop