// File: orbitcowboy[P]gnuplot-cpp/./gnuplot_i.hpp
// Function: Gnuplot::init()
void Gnuplot::init(void)
{
    // char * getenv ( const char * name );  get value of environment variable
    // Retrieves a C string containing the value of the environment variable
    // whose name is specified as argument.  If the requested variable is not
    // part of the environment list, the function returns a NULL pointer.
#if ( defined(unix) || defined(__unix) || defined(__unix__) ) && !defined(__APPLE__)
    if (getenv("DISPLAY") == nullptr)
    {
        valid = false;
        throw GnuplotException("Can't find DISPLAY variable");
    }
#endif

    // if gnuplot not available
    if (!Gnuplot::get_program_path())
    {
        valid = false;
        throw GnuplotException("Can't find gnuplot");
    }

    // open pipe
    std::string tmp = Gnuplot::m_sGNUPlotPath + "/" +
                      Gnuplot::m_sGNUPlotFileName;

    // FILE *popen(const char *command, const char *mode);
    // The popen() function shall execute the command specified by the string
    // command, create a pipe between the calling program and the executed
    // command, and return a pointer to a stream that can be used to either read
    // from or write to the pipe.
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
    gnucmd = _popen(tmp.c_str(), "w");
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    gnucmd = popen(tmp.c_str(), "w");
#endif

    // popen() shall return a pointer to an open stream that can be used to read
    // or write to the pipe.  Otherwise, it shall return a null pointer and may
    // set errno to indicate the error.
    if (!gnucmd)
    {
        valid = false;
        throw GnuplotException("Couldn't open connection to gnuplot");
    }

    nplots = 0;
    valid = true;
    smooth.clear();

    //set terminal type
    showonscreen();

    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq 0x8f33(%rip), %rdi      # 0x10084
callq 0x3360
cmpq $0x0, %rax
jne 0x7223
movq -0xd8(%rbp), %rax
movb $0x0, 0x8(%rax)
movb $0x1, -0x3d(%rbp)
movl $0x10, %edi
callq 0x3170
movq %rax, -0xe8(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x3510
movq -0xe0(%rbp), %rdx
leaq 0x8eee(%rip), %rsi      # 0x1008c
leaq -0x28(%rbp), %rdi
callq 0xbb50
jmp 0x71a9
movq -0xe8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xbcd0
jmp 0x71bb
movq -0xe8(%rbp), %rdi
movb $0x0, -0x3d(%rbp)
leaq 0xeb7b(%rip), %rsi      # 0x15d48
leaq 0x4b3c(%rip), %rdx      # 0xbd10
callq 0x34d0
jmp 0x74d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7201
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x35c8
leaq -0x29(%rbp), %rdi
callq 0x32f0
testb $0x1, -0x3d(%rbp)
jne 0x7212
jmp 0x721e
movq -0xe8(%rbp), %rdi
callq 0x3210
jmp 0x74cb
callq 0x74e0
testb $0x1, %al
jne 0x72f3
movq -0xd8(%rbp), %rax
movb $0x0, 0x8(%rax)
movb $0x1, -0x62(%rbp)
movl $0x10, %edi
callq 0x3170
movq %rax, -0xf8(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x3510
movq -0xf0(%rbp), %rdx
leaq 0x9044(%rip), %rsi      # 0x102b2
leaq -0x60(%rbp), %rdi
callq 0xbb50
jmp 0x7279
movq -0xf8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xbcd0
jmp 0x728b
movq -0xf8(%rbp), %rdi
movb $0x0, -0x62(%rbp)
leaq 0xeaab(%rip), %rsi      # 0x15d48
leaq 0x4a6c(%rip), %rdx      # 0xbd10
callq 0x34d0
jmp 0x74d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x72d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x35c8
leaq -0x61(%rbp), %rdi
callq 0x32f0
testb $0x1, -0x62(%rbp)
jne 0x72e2
jmp 0x72ee
movq -0xf8(%rbp), %rdi
callq 0x3210
jmp 0x74cb
leaq 0xf036(%rip), %rsi      # 0x16330
leaq 0x8d7d(%rip), %rdx      # 0x1007e
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0xbc50
movq -0x100(%rbp), %rsi
leaq 0xefee(%rip), %rdx      # 0x16310
leaq -0x88(%rbp), %rdi
callq 0xbc00
jmp 0x7330
leaq -0xa8(%rbp), %rdi
callq 0x35c8
leaq -0x88(%rbp), %rdi
callq 0x3110
movq %rax, %rdi
leaq 0x8f73(%rip), %rsi      # 0x102c5
callq 0x30b0
movq %rax, -0x108(%rbp)
jmp 0x7360
movq -0xd8(%rbp), %rax
movq -0x108(%rbp), %rcx
movq %rcx, (%rax)
cmpq $0x0, (%rax)
jne 0x7481
movq -0xd8(%rbp), %rax
movb $0x0, 0x8(%rax)
movb $0x1, -0xca(%rbp)
movl $0x10, %edi
callq 0x3170
movq %rax, -0x118(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x3510
movq -0x110(%rbp), %rdx
leaq 0x8f08(%rip), %rsi      # 0x102c7
leaq -0xc8(%rbp), %rdi
callq 0xbb50
jmp 0x73cd
movq -0x118(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xbcd0
jmp 0x73e2
movq -0x118(%rbp), %rdi
movb $0x0, -0xca(%rbp)
leaq 0xe951(%rip), %rsi      # 0x15d48
leaq 0x4912(%rip), %rdx      # 0xbd10
callq 0x34d0
jmp 0x74d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x35c8
jmp 0x74cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x74bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x745c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x35c8
leaq -0xc9(%rbp), %rdi
callq 0x32f0
testb $0x1, -0xca(%rbp)
jne 0x7473
jmp 0x747f
movq -0x118(%rbp), %rdi
callq 0x3210
jmp 0x74bf
movq -0xd8(%rbp), %rdi
movl $0x0, 0xc(%rdi)
movb $0x1, 0x8(%rdi)
addq $0x30, %rdi
callq 0x33b0
movq -0xd8(%rbp), %rdi
callq 0x3e10
jmp 0x74aa
leaq -0x88(%rbp), %rdi
callq 0x35c8
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0x35c8
movq -0x38(%rbp), %rdi
callq 0x3500
nopw %cs:(%rax,%rax)