// File: /workspace/github_c_makefile_star2_O3/msteveb[P]autosetup/./jimsh0.c
// Function: Jim_MakeTempFile
int Jim_MakeTempFile(Jim_Interp *interp, const char *filename_template, int unlink_file)
{
    int fd;
    mode_t mask;
    Jim_Obj *filenameObj;

    if (filename_template == NULL) {
        const char *tmpdir = getenv("TMPDIR");
        if (tmpdir == NULL || *tmpdir == '\0' || access(tmpdir, W_OK) != 0) {
            tmpdir = "/tmp/";
        }
        filenameObj = Jim_NewStringObj(interp, tmpdir, -1);
        if (tmpdir[0] && tmpdir[strlen(tmpdir) - 1] != '/') {
            Jim_AppendString(interp, filenameObj, "/", 1);
        }
        Jim_AppendString(interp, filenameObj, "tcl.tmp.XXXXXX", -1);
    }
    else {
        filenameObj = Jim_NewStringObj(interp, filename_template, -1);
    }


#ifdef HAVE_UMASK
    mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
#endif
#ifdef HAVE_MKSTEMP
    fd = mkstemp(filenameObj->bytes);
#else
    if (mktemp(filenameObj->bytes) == NULL) {
        fd = -1;
    }
    else {
        fd = open(filenameObj->bytes, O_RDWR | O_CREAT | O_TRUNC);
    }
#endif
#ifdef HAVE_UMASK
    umask(mask);
#endif
    if (fd < 0) {
        Jim_SetResultErrno(interp, Jim_String(filenameObj));
        Jim_FreeNewObj(interp, filenameObj);
        return -1;
    }
    if (unlink_file) {
        remove(Jim_String(filenameObj));
    }

    Jim_SetResult(interp, filenameObj);
    return fd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r15d
movq %rdi, %rbx
testq %rsi, %rsi
je 0x12f82
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7508
movq %rax, %r14
jmp 0x1300b
leaq 0x18329(%rip), %rdi     # 0x2b2b2
callq 0x6030
testq %rax, %rax
je 0x12fac
movq %rax, %r12
cmpb $0x0, (%rax)
je 0x12fac
movq %r12, %rdi
movl $0x2, %esi
callq 0x6430
testl %eax, %eax
je 0x12fb3
leaq 0x18306(%rip), %r12     # 0x2b2b9
movq %rbx, %rdi
movq %r12, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7508
movq %rax, %r14
cmpb $0x0, (%r12)
je 0x12ff4
movq %r12, %rdi
callq 0x6180
cmpb $0x2f, -0x1(%rax,%r12)
je 0x12ff4
leaq 0x182d9(%rip), %rdx     # 0x2b2bd
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %ecx
callq 0x86a0
leaq 0x182c4(%rip), %rdx     # 0x2b2bf
movq %rbx, %rdi
movq %r14, %rsi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x86a0
movl $0x7f, %edi
callq 0x6300
movl %eax, %r13d
movq (%r14), %rdi
callq 0x62b0
movl %eax, %r12d
movl %r13d, %edi
callq 0x6300
testl %r12d, %r12d
js 0x13071
testl %r15d, %r15d
je 0x1304f
movq (%r14), %rdi
testq %rdi, %rdi
jne 0x1304a
movq 0x8(%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movq (%r14), %rdi
callq 0x60a0
incl 0x10(%r14)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x1306c
movq %rbx, %rdi
callq 0x758c
movq %r14, (%rbx)
jmp 0x1309f
movq (%r14), %rsi
testq %rsi, %rsi
jne 0x13086
movq 0x8(%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x12f20
movq %rbx, %rdi
movq %r14, %rsi
callq 0x758c
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq