// File: /workspace/github_cpp_makefile_star2_O2/spatialfruitsalad[P]volume2position/./tomogram.hpp
// Function: tomogram3d<unsigned char>::write_ppm(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned long) const
void write_ppm(std::string outfilename, unsigned long picnumber) const
    {
        std::cout << "write " << outfilename << " ... " << std::flush;
        std::ofstream myfile;
        myfile.open (outfilename.c_str());
        myfile << "P3" << std::endl;
        myfile << sx << " " << sy << "\n255"  << std::endl;
        VALUE maxvalue = *std::max_element (data.begin()+(picnumber*sx*sy),data.begin()+((picnumber+1)*sx*sy));
        std::vector<int> cvals((maxvalue+1)*3, 0);

        std::default_random_engine rng;
        std::uniform_real_distribution<double> d(0,1);

        unsigned int N = 15;
        // create color list
        std::cout << "create " << maxvalue << " colors" << std::endl;


        unsigned int idx = 0;
        for (unsigned long k = 1; k <= maxvalue; ++k)
        {
            hsv ch;
            ch.h = 360.0/static_cast<double>(N) * static_cast<double>(idx);
            ch.s = 0.5 + 0.5 * d(rng);
            ch.v = 0.3 + 0.7 * d(rng);
            rgb c = hsv2rgb(ch);
            idx++;
            if (idx >= N) idx = 0;
            //std::cout << "r= " << c.r*255.0 << std::endl;
            //std::cout << "g= " << c.g*255.0 << std::endl;
            //std::cout << "b= " << c.b << std::endl;
            cvals[k*3 + 0] = (c.r*255.0);
            cvals[k*3 + 1] = (c.g*255.0);
            cvals[k*3 + 2] = (c.b*255.0);
        }

        for (unsigned long j = 0; j != sy; ++j)
        {
            for (unsigned long i = 0; i != sx; ++i)
            {
                int val = int(get(i,j,picnumber));

                int r = cvals.at(val*3 + 0);
                int g = cvals.at(val*3 + 1);
                int b = cvals.at(val*3 + 2);
                myfile << r << " " << g << " " << b << " ";
            }
            myfile << std::endl;
        }
        myfile.close();
        std::cout << " done" << std::endl;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdx, 0x28(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
movq 0x9c0b(%rip), %rdi      # 0x17fc8
leaq 0x3536(%rip), %rsi      # 0x118fa
callq 0x3260
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3230
leaq 0x34f1(%rip), %rsi      # 0x118cc
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x31b0
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
callq 0x33f0
movq (%rbx), %rsi
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x3040
leaq 0x34f1(%rip), %rsi      # 0x11901
leaq 0xa8(%rsp), %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
movq 0x18(%r15), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x31a0
leaq 0x3815(%rip), %rsi      # 0x11c52
movq %rax, %rdi
callq 0x3260
movq 0x20(%r15), %rsi
movq %rax, %rdi
callq 0x31a0
leaq 0x34ac(%rip), %rsi      # 0x11904
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
movq (%r15), %rax
movq 0x20(%r15), %rdi
imulq 0x18(%r15), %rdi
movq 0x28(%rsp), %rcx
leaq 0x1(%rcx), %rsi
imulq %rdi, %rsi
imulq %rcx, %rdi
addq %rax, %rdi
addq %rax, %rsi
callq 0xe8eb
movzbl (%rax), %ebx
leaq (%rbx,%rbx,2), %rsi
addq $0x3, %rsi
leaq 0x60(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x38(%rsp), %rdi
leaq 0x50(%rsp), %rcx
callq 0xdd26
movq %r15, 0x20(%rsp)
movq $0x1, 0x30(%rsp)
xorpd %xmm0, %xmm0
movhpd 0x2b7c(%rip), %xmm0     # xmm0 = xmm0[0],mem[0]
movapd %xmm0, 0x50(%rsp)
movq 0x9aef(%rip), %rdi      # 0x17fc8
leaq 0x3429(%rip), %rsi      # 0x11909
callq 0x3260
movsbl %bl, %esi
movq %rax, %rdi
callq 0x32b0
leaq 0x341a(%rip), %rsi      # 0x11911
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3110
imulq $0xc, %rbx, %r14
leaq 0x50(%rsp), %rbx
leaq 0x30(%rsp), %r15
leaq 0x60(%rsp), %r12
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq %rbp, %r14
je 0xe5f9
movl %r13d, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x2b48(%rip), %xmm0     # 0x11080
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xdd7c
movapd %xmm0, 0x90(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xdd7c
movapd 0x90(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
mulpd 0x2b9e(%rip), %xmm1     # 0x11110
addpd 0x2ba6(%rip), %xmm1     # 0x11120
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movupd %xmm1, 0x80(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x4e35
incl %r13d
cmpl $0xf, %r13d
movl $0x0, %eax
cmovael %eax, %r13d
movapd 0x60(%rsp), %xmm0
mulpd 0x2b65(%rip), %xmm0     # 0x11130
cvttpd2dq %xmm0, %xmm0
movq 0x38(%rsp), %rax
movlpd %xmm0, 0xc(%rax,%rbp)
movsd 0x70(%rsp), %xmm0
mulsd 0x2aa0(%rip), %xmm0     # 0x11088
cvttsd2si %xmm0, %ecx
movl %ecx, 0x14(%rax,%rbp)
addq $0xc, %rbp
jmp 0xe51f
xorl %r15d, %r15d
leaq 0x38(%rsp), %r13
movq 0x20(%rsp), %r14
cmpq 0x20(%r14), %r15
je 0xe6e6
xorl %ebp, %ebp
movq %r15, 0x18(%rsp)
cmpq 0x18(%r14), %rbp
je 0xe6d1
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq 0x28(%rsp), %rcx
callq 0xad44
movzbl %al, %eax
leal (%rax,%rax,2), %r12d
movq %r13, %rdi
movq %r12, %rsi
callq 0xaaee
movl (%rax), %r15d
leal 0x1(%r12), %esi
movq %r13, %rdi
callq 0xaaee
movl (%rax), %r14d
addl $0x2, %r12d
movq %r13, %rbx
movq %r13, %rdi
movq %r12, %rsi
callq 0xaaee
leaq 0x35e0(%rip), %r13      # 0x11c52
movl (%rax), %r12d
leaq 0xa8(%rsp), %rdi
movl %r15d, %esi
callq 0x3410
movq %rax, %rdi
movq %r13, %rsi
callq 0x3260
movq %rax, %rdi
movl %r14d, %esi
callq 0x3410
movq %rax, %rdi
movq %r13, %rsi
callq 0x3260
movq %rax, %rdi
movl %r12d, %esi
callq 0x3410
movq %rax, %rdi
movq %r13, %rsi
callq 0x3260
incq %rbp
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r15
movq %rbx, %r13
jmp 0xe617
leaq 0xa8(%rsp), %rdi
callq 0x3110
incq %r15
jmp 0xe606
leaq 0xa8(%rsp), %rdi
callq 0x3330
movq 0x98ce(%rip), %rdi      # 0x17fc8
leaq 0x3181(%rip), %rsi      # 0x11882
callq 0x3260
movq %rax, %rdi
callq 0x3110
leaq 0x38(%rsp), %rdi
callq 0xb1c8
leaq 0xa8(%rsp), %rdi
callq 0x3350
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe73f
jmp 0xe73f
jmp 0xe74e
jmp 0xe74e
movq %rax, %rbx
jmp 0xe75b
jmp 0xe74e
jmp 0xe74e
jmp 0xe74e
jmp 0xe74e
jmp 0xe74e
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xb1c8
leaq 0xa8(%rsp), %rdi
callq 0x3350
movq %rbx, %rdi
callq 0x3420