// File: orbitcowboy[P]gnuplot-cpp/./gnuplot_i.hpp
// Function: Gnuplot::get_program_path()
bool Gnuplot::get_program_path(void)
{
    //
    // first look in m_sGNUPlotPath for Gnuplot
    //
    std::string tmp = Gnuplot::m_sGNUPlotPath + "/" +
                      Gnuplot::m_sGNUPlotFileName;

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
    if ( Gnuplot::file_exists(tmp, 0) ) // check existence
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    if ( Gnuplot::file_exists(tmp, 1) ) // check existence and execution permission
#endif
    {
        return true;
    }


    //
    // second look in PATH for Gnuplot
    // Retrieves a C string containing the value of environment variable PATH
    const char * const path = getenv("PATH");

    if (path == nullptr)
    {
        throw GnuplotException("Path is not set");
    }
    std::list<std::string> ls;

    //split path (one long string) into list ls of strings
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
    stringtok(ls, path, ";");
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    stringtok(ls, path, ":");
#endif

    // scan list for Gnuplot program files
    for (std::list<std::string>::const_iterator i = ls.cbegin();
            i != ls.cend(); ++i)
    {
        tmp = (*i) + "/" + Gnuplot::m_sGNUPlotFileName;
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
        if ( Gnuplot::file_exists(tmp, 0) ) // check existence
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
        if ( Gnuplot::file_exists(tmp, 1) ) // check existence and execution permission
#endif
        {
            Gnuplot::m_sGNUPlotPath = *i; // set m_sGNUPlotPath
            return true;
        }
    }

    tmp = "Can't find gnuplot neither in PATH nor in \"" +
          Gnuplot::m_sGNUPlotPath + "\"";
    throw GnuplotException(tmp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
leaq 0xee3e(%rip), %rsi      # 0x16330
leaq 0x8b85(%rip), %rdx      # 0x1007e
leaq -0x48(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0xbc50
movq -0x160(%rbp), %rsi
leaq 0xedf9(%rip), %rdx      # 0x16310
leaq -0x28(%rbp), %rdi
callq 0xbc00
jmp 0x7522
leaq -0x48(%rbp), %rdi
callq 0x35c8
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x3970
movb %al, -0x161(%rbp)
jmp 0x7541
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x754d
jmp 0x7588
movb $0x1, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
jmp 0x7964
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x35c8
jmp 0x7984
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x797b
leaq 0x8d5c(%rip), %rdi      # 0x102eb
callq 0x3360
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x766a
movb $0x1, -0x82(%rbp)
movl $0x10, %edi
callq 0x3170
movq %rax, -0x178(%rbp)
leaq -0x81(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x3510
movq -0x170(%rbp), %rdx
leaq 0x8d14(%rip), %rsi      # 0x102f0
leaq -0x80(%rbp), %rdi
callq 0xbb50
jmp 0x75e7
movq -0x178(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xbcd0
jmp 0x75f9
movq -0x178(%rbp), %rdi
movb $0x0, -0x82(%rbp)
leaq 0xe73a(%rip), %rsi      # 0x15d48
leaq 0x46fb(%rip), %rdx      # 0xbd10
callq 0x34d0
jmp 0x798d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7642
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x35c8
leaq -0x81(%rbp), %rdi
callq 0x32f0
testb $0x1, -0x82(%rbp)
jne 0x7659
jmp 0x7665
movq -0x178(%rbp), %rdi
callq 0x3210
jmp 0x797b
leaq -0xa0(%rbp), %rdi
callq 0xbee0
movq -0x60(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x3510
movq -0x188(%rbp), %rsi
movq -0x180(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0xbb50
jmp 0x76b0
leaq 0x8b3b(%rip), %rdx      # 0x101f2
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xbf00
jmp 0x76cc
leaq -0xc0(%rbp), %rdi
callq 0x35c8
leaq -0xc1(%rbp), %rdi
callq 0x32f0
leaq -0xa0(%rbp), %rdi
callq 0xc060
movq %rax, -0xd0(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xc0c0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xc090
testb $0x1, %al
jne 0x7726
jmp 0x7875
leaq -0xd0(%rbp), %rdi
callq 0xc0f0
movq %rax, %rsi
leaq 0x8942(%rip), %rdx      # 0x1007e
leaq -0x118(%rbp), %rdi
callq 0xbc50
jmp 0x774a
leaq 0xebbf(%rip), %rdx      # 0x16310
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xbc00
jmp 0x7766
leaq -0x28(%rbp), %rdi
movq %rdi, -0x198(%rbp)
leaq -0xf8(%rbp), %rsi
movq %rsi, -0x1a0(%rbp)
callq 0x3370
movq -0x1a0(%rbp), %rdi
callq 0x35c8
leaq -0x118(%rbp), %rdi
callq 0x35c8
movq -0x198(%rbp), %rdi
movl $0x1, %esi
callq 0x3970
movb %al, -0x189(%rbp)
jmp 0x77b5
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x77c4
jmp 0x7862
leaq -0xd0(%rbp), %rdi
callq 0xc0f0
movq %rax, %rsi
leaq 0xeb56(%rip), %rdi      # 0x16330
callq 0x3030
jmp 0x77e1
movb $0x1, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xc190
jmp 0x7964
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7823
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x35c8
leaq -0xc1(%rbp), %rdi
callq 0x32f0
jmp 0x7956
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x7956
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x35c8
jmp 0x7956
jmp 0x7864
leaq -0xd0(%rbp), %rdi
callq 0xc120
jmp 0x76f7
leaq 0x8a84(%rip), %rsi      # 0x10300
leaq 0xeaad(%rip), %rdx      # 0x16330
leaq -0x158(%rbp), %rdi
callq 0xbdd0
jmp 0x7891
leaq 0x8b0d(%rip), %rdx      # 0x103a5
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0xc140
jmp 0x78ad
leaq -0x28(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
leaq -0x138(%rbp), %rsi
movq %rsi, -0x1b8(%rbp)
callq 0x3370
movq -0x1b8(%rbp), %rdi
callq 0x35c8
leaq -0x158(%rbp), %rdi
callq 0x35c8
movl $0x10, %edi
callq 0x3170
movq -0x1b0(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1a8(%rbp)
callq 0xbcd0
jmp 0x7908
movq -0x1a8(%rbp), %rdi
leaq 0xe432(%rip), %rsi      # 0x15d48
leaq 0x43f3(%rip), %rdx      # 0xbd10
callq 0x34d0
jmp 0x798d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x35c8
jmp 0x7956
movq -0x1a8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x3210
leaq -0xa0(%rbp), %rdi
callq 0xc190
jmp 0x797b
leaq -0x28(%rbp), %rdi
callq 0x35c8
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x35c8
movq -0x50(%rbp), %rdi
callq 0x3500
nopl (%rax)