// File: /workspace/github_c_makefile_star2_O3/Paxa[P]fast_excel/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c
// Function: tmpfileplus
FILE *tmpfileplus(const char *dir, const char *prefix, char **pathname, int keep)
{
	FILE *fp = NULL;
	char *tmpname = NULL;
	char *tmpdir = NULL;
	const char *pfx = (prefix ? prefix : "tmp.");
	char *tempdirs[12] = { 0 };
#ifdef _WIN32
	char env1[FILENAME_MAX+1] = { 0 };
	char env2[FILENAME_MAX+1] = { 0 };
#else
	char env3[FILENAME_MAX+1] = { 0 };
#endif
	int ntempdirs = 0;
	int i;

	/* Set up a list of temp directories we will try in order */
	i = 0;
	tempdirs[i++] = (char *)dir;
#ifdef _WIN32
	tempdirs[i++] = getenv_save("TMP", env1, sizeof(env1));
	tempdirs[i++] = getenv_save("TEMP", env2, sizeof(env2));
#else
	tempdirs[i++] = getenv_save("TMPDIR", env3, sizeof(env3));
	tempdirs[i++] = P_tmpdir;
#endif
	tempdirs[i++] = ".";
	ntempdirs = i;

	errno = 0;

	/* Work through list we set up before, and break once we are successful */
	for (i = 0; i < ntempdirs; i++)
	{
		tmpdir = tempdirs[i];
		DPRINTF1("Trying tmpdir=[%s]\n", tmpdir);
		fp = mktempfile_internal(tmpdir, pfx, &tmpname, keep);
		if (fp) break;
	}
	/* If we succeeded and the user passed a pointer, set it to the alloc'd pathname: the user must free this */
	if (fp && pathname)
		*pathname = tmpname;
	else	/* Otherwise, free the alloc'd memory */
		free(tmpname);

	return fp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1138, %rsp           # imm = 0x1138
movl %ecx, 0xc(%rsp)
movq %rdx, %r14
movq %rdi, %r15
testq %rsi, %rsi
leaq 0x2d567(%rip), %rax     # 0x40068
cmovneq %rsi, %rax
movq %rax, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
leaq 0x130(%rsp), %rbx
movl $0x1001, %edx           # imm = 0x1001
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc640
movq %r15, 0x40(%rsp)
leaq 0x2d523(%rip), %rdi     # 0x4006d
callq 0xc050
testq %rax, %rax
movq %r14, 0x38(%rsp)
je 0x12b6b
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
movq %rax, %rsi
callq 0xc170
jmp 0x12b6d
xorl %ebx, %ebx
movq %rbx, 0x48(%rsp)
leaq 0x2d4fb(%rip), %rax     # 0x40074
movq %rax, 0x50(%rsp)
leaq 0x3234a(%rip), %rax     # 0x44ecf
movq %rax, 0x58(%rsp)
callq 0xc150
movq %rax, %r12
movl $0x0, (%rax)
movabsq $0x3837363534333231, %rbp # imm = 0x3837363534333231
leaq 0x10(%rsp), %r13
movabsq $-0x7bdef7bdef7bdef7, %r15 # imm = 0x8421084210842109
leaq 0x2d4d9(%rip), %r14     # 0x40091
xorl %ebx, %ebx
movq %rax, 0x20(%rsp)
movq 0x40(%rsp,%rbx,8), %rdi
movq %rbp, 0x10(%rsp)
movl $0x303938, 0x17(%rsp)   # imm = 0x303938
testq %rdi, %rdi
je 0x12bf6
movq %rdi, 0x30(%rsp)
leaq 0xa0(%rsp), %rsi
callq 0xc8d0
testl %eax, %eax
jne 0x12bf6
testb $0x40, 0xb9(%rsp)
jne 0x12c0c
movl $0x2, (%r12)
incq %rbx
cmpq $0x4, %rbx
jne 0x12bbf
jmp 0x12d6c
movq 0x30(%rsp), %rdi
callq 0xc480
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
callq 0xc480
movq %rax, %rbp
movq %r13, %rdi
callq 0xc480
addq (%rsp), %rbp
leaq (%rax,%rbp), %rdi
addq $0x2, %rdi
callq 0xca50
testq %rax, %rax
je 0x12d16
xorl %r12d, %r12d
movq %rax, (%rsp)
movl 0x4554e(%rip), %edi     # 0x581a4
testl %edi, %edi
jne 0x12c71
xorl %edi, %edi
callq 0xc9b0
movq %rax, %rbp
shll $0x8, %ebp
callq 0xc3f0
movq %rax, %rdi
xorl %ebp, %edi
leal 0x1(%rdi), %eax
movl %eax, 0x4552a(%rip)     # 0x581a4
callq 0xc7b0
cmpb $0x0, 0x10(%rsp)
je 0x12cc5
xorl %ebp, %ebp
callq 0xd0c0
movslq %eax, %rcx
movq %rcx, %rax
shrq %rax
mulq %r15
shrq $0x4, %rdx
movq %rdx, %rax
shlq $0x6, %rax
addq %rdx, %rdx
subq %rax, %rdx
addq %rcx, %rdx
movb (%r14,%rdx), %al
movb %al, 0x10(%rsp,%rbp)
incq %rbp
movq %r13, %rdi
callq 0xc480
cmpq %rax, %rbp
jb 0x12c88
movq (%rsp), %rbp
movq %rbp, %rdi
leaq 0x2d3b1(%rip), %rsi     # 0x40084
movq 0x30(%rsp), %rdx
leaq 0x2f7a7(%rip), %rcx     # 0x42486
movq 0x28(%rsp), %r8
movq %r13, %r9
xorl %eax, %eax
callq 0xcf50
movq %rbp, %rdi
movl $0xc2, %esi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0xcda0
cmpl $-0x1, %eax
jne 0x12d20
incl %r12d
cmpl $0xa, %r12d
jne 0x12c50
jmp 0x12d50
movl $0xc, (%r12)
jmp 0x12d5d
movl %eax, %edi
leaq 0x2d364(%rip), %rsi     # 0x4008d
callq 0xcc10
movq %rax, %r12
movq 0x20(%rsp), %rax
movl $0x0, (%rax)
cmpl $0x0, 0xc(%rsp)
jne 0x12d4b
movq %rbp, %rdi
callq 0xc160
testq %r12, %r12
jne 0x12d8e
movq %rbp, %rdi
callq 0xc0c0
movq 0x20(%rsp), %r12
movabsq $0x3837363534333231, %rbp # imm = 0x3837363534333231
jmp 0x12bfe
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xc0c0
movq %r12, %rax
addq $0x1138, %rsp           # imm = 0x1138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x12d71
movq %rbp, (%rax)
jmp 0x12d79