// File: orbitcowboy[P]gnuplot-cpp/./gnuplot_i.hpp
// Function: Gnuplot::plot_image(unsigned char const*, unsigned int, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
Gnuplot& Gnuplot::plot_image(const unsigned char * ucPicBuf,
                             const unsigned int iWidth,
                             const unsigned int iHeight,
                             const std::string &title)
{
    std::ofstream tmp;
    std::string name = create_tmpfile(tmp);
    if (name.empty())
    {
        return *this;
    }

    //
    // write the data to file
    //
    int iIndex = 0;
    for(unsigned int iRow = 0; iRow < iHeight; ++iRow)
    {
        for(unsigned int iColumn = 0; iColumn < iWidth; ++iColumn)
        {
            tmp << iColumn << " " << iRow  << " "
                << static_cast<float>(ucPicBuf[iIndex++]) << std::endl;
        }
    }

    tmp.flush();
    tmp.close();

    std::ostringstream cmdstr;
    //
    // command to be sent to gnuplot
    //
    if (nplots > 0  &&  two_dim == true)
    {
        cmdstr << "replot ";
    }
    else
    {
        cmdstr << "plot ";
    }

    if (title.empty())
    {
        cmdstr << "\"" << name << "\" with image";
    }
    else
    {
        cmdstr << "\"" << name << "\" title \"" << title << "\" with image";
    }

    //
    // Do the actual plot
    //
    return cmd(cmdstr.str());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x410(%rbp)
leaq -0x228(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0x34c0
movq -0x410(%rbp), %rsi
movq -0x408(%rbp), %rdx
leaq -0x248(%rbp), %rdi
callq 0x6b90
jmp 0x67c7
leaq -0x248(%rbp), %rdi
callq 0x3490
testb $0x1, %al
jne 0x67d9
jmp 0x680a
movq -0x410(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x258(%rbp)
jmp 0x6b3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x6b70
movl $0x0, -0x25c(%rbp)
movl $0x0, -0x260(%rbp)
movl -0x260(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x693e
movl $0x0, -0x264(%rbp)
movl -0x264(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x6928
movl -0x264(%rbp), %esi
leaq -0x228(%rbp), %rdi
callq 0x33c0
movq %rax, -0x418(%rbp)
jmp 0x6861
movq -0x418(%rbp), %rdi
leaq 0x99fa(%rip), %rsi      # 0x10269
callq 0x3280
movq %rax, -0x420(%rbp)
jmp 0x687d
movq -0x420(%rbp), %rdi
movl -0x260(%rbp), %esi
callq 0x33c0
movq %rax, -0x428(%rbp)
jmp 0x6898
movq -0x428(%rbp), %rdi
leaq 0x99c3(%rip), %rsi      # 0x10269
callq 0x3280
movq %rax, -0x430(%rbp)
jmp 0x68b4
movq -0x430(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x25c(%rbp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, -0x25c(%rbp)
movzbl (%rax,%rcx), %eax
cvtsi2ss %eax, %xmm0
callq 0x3220
movq %rax, -0x438(%rbp)
jmp 0x68e6
movq -0x438(%rbp), %rdi
movq 0xf6ac(%rip), %rsi      # 0x15fa0
callq 0x32d0
jmp 0x68fb
jmp 0x68fd
movl -0x264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x264(%rbp)
jmp 0x6837
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x6b64
jmp 0x692a
movl -0x260(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x260(%rbp)
jmp 0x681e
leaq -0x228(%rbp), %rdi
callq 0x31d0
jmp 0x694c
leaq -0x228(%rbp), %rdi
callq 0x3410
jmp 0x695a
leaq -0x3e0(%rbp), %rdi
callq 0x33d0
jmp 0x6968
movq -0x410(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jle 0x69b7
movq -0x410(%rbp), %rax
movb 0x9(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x69b7
leaq 0x988b(%rip), %rsi      # 0x1021b
leaq -0x3e0(%rbp), %rdi
callq 0x3280
jmp 0x699e
jmp 0x69ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x6b31
leaq 0x985f(%rip), %rsi      # 0x1021d
leaq -0x3e0(%rbp), %rdi
callq 0x3280
jmp 0x69cc
jmp 0x69ce
movq -0x28(%rbp), %rdi
callq 0x3490
testb $0x1, %al
jne 0x69dd
jmp 0x6a2f
leaq 0x99c1(%rip), %rsi      # 0x103a5
leaq -0x3e0(%rbp), %rdi
callq 0x3280
movq %rax, -0x440(%rbp)
jmp 0x69f9
movq -0x440(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x3270
movq %rax, -0x448(%rbp)
jmp 0x6a15
movq -0x448(%rbp), %rdi
leaq 0x9870(%rip), %rsi      # 0x10293
callq 0x3280
jmp 0x6a2a
jmp 0x6ab3
leaq 0x996f(%rip), %rsi      # 0x103a5
leaq -0x3e0(%rbp), %rdi
callq 0x3280
movq %rax, -0x450(%rbp)
jmp 0x6a4b
movq -0x450(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x3270
movq %rax, -0x458(%rbp)
jmp 0x6a67
movq -0x458(%rbp), %rdi
leaq 0x982b(%rip), %rsi      # 0x102a0
callq 0x3280
movq %rax, -0x460(%rbp)
jmp 0x6a83
movq -0x460(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3270
movq %rax, -0x468(%rbp)
jmp 0x6a9c
movq -0x468(%rbp), %rdi
leaq 0x97e9(%rip), %rsi      # 0x10293
callq 0x3280
jmp 0x6ab1
jmp 0x6ab3
leaq -0x400(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
callq 0x32b0
jmp 0x6ac8
movq -0x410(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x3d00
movq %rax, -0x470(%rbp)
jmp 0x6ae4
movq -0x470(%rbp), %rax
movq %rax, -0x8(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x35c8
movl $0x1, -0x258(%rbp)
leaq -0x3e0(%rbp), %rdi
callq 0x3090
jmp 0x6b3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x35c8
leaq -0x3e0(%rbp), %rdi
callq 0x3090
jmp 0x6b64
leaq -0x248(%rbp), %rdi
callq 0x35c8
leaq -0x228(%rbp), %rdi
callq 0x3430
movq -0x8(%rbp), %rax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
leaq -0x248(%rbp), %rdi
callq 0x35c8
leaq -0x228(%rbp), %rdi
callq 0x3430
movq -0x250(%rbp), %rdi
callq 0x3500
nopl (%rax,%rax)