// File: orbitcowboy[P]gnuplot-cpp/./gnuplot_i.hpp
// Function: Gnuplot::create_tmpfile[abi:cxx11](std::basic_ofstream<char, std::char_traits<char>>&)
std::string Gnuplot::create_tmpfile(std::ofstream &tmp)
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
    char name[15] = {'g', 'n', 'u', 'p', 'l', 'o', 't', 'i', 'X', 'X', 'X', 'X', 'X', 'X', '\0'}; //tmp file in working directory
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    char name[20] = {'/', 't', 'm', 'p', '/', 'g', 'n', 'u', 'p', 'l', 'o', 't', 'i', 'X', 'X', 'X', 'X', 'X', 'X', '\0'}; // tmp file in /tmp
#endif

    //
    // check if maximum number of temporary files reached
    //
    if (Gnuplot::tmpfile_num == GP_MAX_TMP_FILES - 1)
    {
        std::ostringstream except;
        except << "Maximum number of temporary files reached ("
               << GP_MAX_TMP_FILES << "): cannot open more files" << std::endl;

        throw GnuplotException( except.str() );
    }

    // int mkstemp(char *name);
    // shall replace the contents of the string pointed to by "name" by a unique
    // filename, and return a file descriptor for the file open for reading and
    // writing.  Otherwise, -1 shall be returned if no suitable file could be
    // created.  The string in template should look like a filename with six
    // trailing 'X' s; mkstemp() replaces each 'X' with a character from the
    // portable filename character set.  The characters are chosen such that the
    // resulting name does not duplicate the name of an existing file at the
    // time of a call to mkstemp()


    //
    // open temporary files for output
    //
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
    if (_mktemp(name) == nullptr)
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    int tmpfd;
    if ((tmpfd = mkstemp(name)) == -1)
#endif
    {
        std::ostringstream except;
        except << "Cannot create temporary file \"" << name << "\"";
        throw GnuplotException(except.str());
    }
#if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
    (void)close(tmpfd);
#endif

    tmp.open(name);
    if (tmp.bad())
    {
        std::ostringstream except;
        except << "Cannot create temporary file \"" << name << "\"";
        throw GnuplotException(except.str());
    }

    //
    // Save the temporary filename
    //
    tmpfile_list.push_back(name);
    Gnuplot::tmpfile_num++;

    return name;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5e0, %rsp            # imm = 0x5E0
movq %rdi, -0x560(%rbp)
movq %rdi, %rax
movq %rax, -0x558(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x550(%rbp)
movq 0x9e66(%rip), %rax      # 0x10a30
movq %rax, -0x30(%rbp)
movq 0x9e63(%rip), %rax      # 0x10a38
movq %rax, -0x28(%rbp)
movl 0x9e61(%rip), %eax      # 0x10a40
movl %eax, -0x20(%rbp)
cmpl $0x3f, 0xf723(%rip)     # 0x1630c
jne 0x6d41
leaq -0x1a8(%rbp), %rdi
movq %rdi, -0x570(%rbp)
callq 0x33d0
movq -0x570(%rbp), %rdi
leaq 0x97a8(%rip), %rsi      # 0x103b8
callq 0x3280
movq %rax, -0x568(%rbp)
jmp 0x6c1e
movq -0x568(%rbp), %rdi
movl $0x40, %esi
callq 0x34f0
movq %rax, -0x578(%rbp)
jmp 0x6c38
movq -0x578(%rbp), %rdi
leaq 0x979e(%rip), %rsi      # 0x103e4
callq 0x3280
movq %rax, -0x580(%rbp)
jmp 0x6c54
movq -0x580(%rbp), %rdi
movq 0xf33e(%rip), %rsi      # 0x15fa0
callq 0x32d0
jmp 0x6c69
movb $0x1, -0x1d9(%rbp)
movl $0x10, %edi
callq 0x3170
movq %rax, -0x588(%rbp)
leaq -0x1d8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x32b0
jmp 0x6c96
movq -0x588(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0xbcd0
jmp 0x6cab
movq -0x588(%rbp), %rdi
movb $0x0, -0x1d9(%rbp)
leaq 0xf088(%rip), %rsi      # 0x15d48
leaq 0x5049(%rip), %rdx      # 0xbd10
callq 0x34d0
jmp 0x7124
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x6d30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x6d17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x35c8
testb $0x1, -0x1d9(%rbp)
jne 0x6d22
jmp 0x6d2e
movq -0x588(%rbp), %rdi
callq 0x3210
jmp 0x6d30
leaq -0x1a8(%rbp), %rdi
callq 0x3090
jmp 0x7118
leaq -0x30(%rbp), %rdi
callq 0x30c0
movl %eax, -0x1e0(%rbp)
cmpl $-0x1, %eax
jne 0x6e8e
leaq -0x358(%rbp), %rdi
movq %rdi, -0x598(%rbp)
callq 0x33d0
movq -0x598(%rbp), %rdi
leaq 0x9684(%rip), %rsi      # 0x103fe
callq 0x3280
movq %rax, -0x590(%rbp)
jmp 0x6d88
movq -0x590(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3280
movq %rax, -0x5a0(%rbp)
jmp 0x6da1
movq -0x5a0(%rbp), %rdi
leaq 0x95f6(%rip), %rsi      # 0x103a5
callq 0x3280
jmp 0x6db6
movb $0x1, -0x379(%rbp)
movl $0x10, %edi
callq 0x3170
movq %rax, -0x5a8(%rbp)
leaq -0x378(%rbp), %rdi
leaq -0x358(%rbp), %rsi
callq 0x32b0
jmp 0x6de3
movq -0x5a8(%rbp), %rdi
leaq -0x378(%rbp), %rsi
callq 0xbcd0
jmp 0x6df8
movq -0x5a8(%rbp), %rdi
movb $0x0, -0x379(%rbp)
leaq 0xef3b(%rip), %rsi      # 0x15d48
leaq 0x4efc(%rip), %rdx      # 0xbd10
callq 0x34d0
jmp 0x7124
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x6e7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x6e64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x35c8
testb $0x1, -0x379(%rbp)
jne 0x6e6f
jmp 0x6e7b
movq -0x5a8(%rbp), %rdi
callq 0x3210
jmp 0x6e7d
leaq -0x358(%rbp), %rdi
callq 0x3090
jmp 0x7118
movl -0x1e0(%rbp), %edi
callq 0x3590
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x10, %edx
callq 0x3040
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
addq -0x18(%rax), %rdi
callq 0x3540
testb $0x1, %al
jne 0x6ec4
jmp 0x6ff9
leaq -0x4f8(%rbp), %rdi
movq %rdi, -0x5b8(%rbp)
callq 0x33d0
movq -0x5b8(%rbp), %rdi
leaq 0x9519(%rip), %rsi      # 0x103fe
callq 0x3280
movq %rax, -0x5b0(%rbp)
jmp 0x6ef3
movq -0x5b0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3280
movq %rax, -0x5c0(%rbp)
jmp 0x6f0c
movq -0x5c0(%rbp), %rdi
leaq 0x948b(%rip), %rsi      # 0x103a5
callq 0x3280
jmp 0x6f21
movb $0x1, -0x519(%rbp)
movl $0x10, %edi
callq 0x3170
movq %rax, -0x5c8(%rbp)
leaq -0x518(%rbp), %rdi
leaq -0x4f8(%rbp), %rsi
callq 0x32b0
jmp 0x6f4e
movq -0x5c8(%rbp), %rdi
leaq -0x518(%rbp), %rsi
callq 0xbcd0
jmp 0x6f63
movq -0x5c8(%rbp), %rdi
movb $0x0, -0x519(%rbp)
leaq 0xedd0(%rip), %rsi      # 0x15d48
leaq 0x4d91(%rip), %rdx      # 0xbd10
callq 0x34d0
jmp 0x7124
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x6fe8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x6fcf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x518(%rbp), %rdi
callq 0x35c8
testb $0x1, -0x519(%rbp)
jne 0x6fda
jmp 0x6fe6
movq -0x5c8(%rbp), %rdi
callq 0x3210
jmp 0x6fe8
leaq -0x4f8(%rbp), %rdi
callq 0x3090
jmp 0x7118
movq -0x550(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x5d8(%rbp)
leaq -0x541(%rbp), %rdi
movq %rdi, -0x5d0(%rbp)
callq 0x3510
movq -0x5d0(%rbp), %rdx
leaq -0x540(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xbb50
jmp 0x7037
movq -0x5d8(%rbp), %rdi
leaq -0x540(%rbp), %rsi
callq 0xc1b0
jmp 0x704c
leaq -0x540(%rbp), %rdi
callq 0x35c8
leaq -0x541(%rbp), %rdi
callq 0x32f0
movl 0xf2a2(%rip), %eax      # 0x1630c
incl %eax
movl %eax, 0xf29a(%rip)      # 0x1630c
leaq -0x542(%rbp), %rdi
movq %rdi, -0x5e0(%rbp)
callq 0x3510
movq -0x560(%rbp), %rdi
movq -0x5e0(%rbp), %rdx
leaq -0x30(%rbp), %rsi
callq 0xbb50
jmp 0x709e
leaq -0x542(%rbp), %rdi
callq 0x32f0
movq -0x558(%rbp), %rax
addq $0x5e0, %rsp            # imm = 0x5E0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x70ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x540(%rbp), %rdi
callq 0x35c8
leaq -0x541(%rbp), %rdi
callq 0x32f0
jmp 0x7118
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x542(%rbp), %rdi
callq 0x32f0
movq -0x1b0(%rbp), %rdi
callq 0x3500
nopw %cs:(%rax,%rax)