// File: /workspace/github_c_makefile_star2_O2/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 $0x1148, %rsp           # imm = 0x1148
movl %ecx, 0x14(%rsp)
movq %rdx, %r14
movq %rdi, %r15
testq %rsi, %rsi
leaq 0x2d76b(%rip), %rax     # 0x3d068
cmovneq %rsi, %rax
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
leaq 0x140(%rsp), %rbx
movl $0x1001, %edx           # imm = 0x1001
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc690
movq %r15, 0x50(%rsp)
leaq 0x2d724(%rip), %rdi     # 0x3d06d
callq 0xc050
testq %rax, %rax
movq %r14, 0x38(%rsp)
je 0xf96a
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
movq %rax, %rsi
callq 0xc190
jmp 0xf96c
xorl %ebx, %ebx
movq %rbx, 0x58(%rsp)
leaq 0x2d6fc(%rip), %rax     # 0x3d074
movq %rax, 0x60(%rsp)
leaq 0x3254b(%rip), %rax     # 0x41ecf
movq %rax, 0x68(%rsp)
callq 0xc170
movq %rax, %r12
andl $0x0, (%rax)
leaq 0x28(%rsp), %r13
pushq $0x3e
popq %r15
leaq 0x2d6ed(%rip), %r14     # 0x3d091
xorl %ecx, %ecx
movq %rax, 0x18(%rsp)
cmpq $0x4, %rcx
je 0xfb5c
movq 0x50(%rsp,%rcx,8), %rbx
movabsq $0x3837363534333231, %rax # imm = 0x3837363534333231
movq %rax, 0x28(%rsp)
movl $0x303938, 0x2f(%rsp)   # imm = 0x303938
testq %rbx, %rbx
je 0xf9fe
movq %rcx, 0x8(%rsp)
movq %rbx, %rdi
leaq 0xb0(%rsp), %rsi
callq 0xc930
testl %eax, %eax
jne 0xf9f9
testb $0x40, 0xc9(%rsp)
jne 0xfa0b
movq 0x8(%rsp), %rcx
movl $0x2, (%r12)
incq %rcx
jmp 0xf9ab
movq %rbx, %rdi
callq 0xc4c0
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %rdi
callq 0xc4c0
movq %rax, %rbp
movq %r13, %rdi
callq 0xc4c0
addq 0x40(%rsp), %rbp
leaq (%rax,%rbp), %rdi
addq $0x2, %rdi
callq 0xcab0
testq %rax, %rax
je 0xfb0a
movq %rax, %rbp
xorl %ecx, %ecx
xorl %r12d, %r12d
movq %rbx, 0x48(%rsp)
cmpl $0xa, %r12d
je 0xfb14
movq %rbp, %rbx
movl 0x4477c(%rip), %edi     # 0x541e4
testl %edi, %edi
jne 0xfa83
xorl %edi, %edi
callq 0xca10
movq %rax, %rbp
shll $0x8, %ebp
callq 0xc420
movq %rax, %rdi
xorl %ebp, %edi
leal 0x1(%rdi), %eax
movl %eax, 0x44758(%rip)     # 0x541e4
callq 0xc810
xorl %ebp, %ebp
movq %r13, %rdi
callq 0xc4c0
cmpq %rax, %rbp
jae 0xfab9
callq 0xd140
cltq
xorl %edx, %edx
divq %r15
movb (%rdx,%r14), %al
movb %al, 0x28(%rsp,%rbp)
incq %rbp
jmp 0xfa93
movq %rbx, %rbp
movq %rbx, %rdi
leaq 0x2d5be(%rip), %rsi     # 0x3d084
movq 0x48(%rsp), %rdx
leaq 0x2f9b4(%rip), %rcx     # 0x3f486
movq 0x20(%rsp), %r8
movq %r13, %r9
xorl %eax, %eax
callq 0xcfd0
movq %rbx, %rdi
movl $0xc2, %esi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0xce20
incl %r12d
movb $0x1, %cl
cmpl $-0x1, %eax
je 0xfa55
movq 0x18(%rsp), %r12
jmp 0xfb20
movl $0xc, (%r12)
jmp 0xfb52
xorl %eax, %eax
testb $0x1, %cl
movq 0x18(%rsp), %r12
jne 0xfb4a
movl %eax, %edi
leaq 0x2d564(%rip), %rsi     # 0x3d08d
callq 0xcc80
movq %rax, %rbx
andl $0x0, (%r12)
cmpl $0x0, 0x14(%rsp)
jne 0xfb45
movq %rbp, %rdi
callq 0xc180
testq %rbx, %rbx
jne 0xfb7d
movq %rbp, %rdi
callq 0xc0d0
movq 0x8(%rsp), %rcx
jmp 0xfa06
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xc0d0
movq %rbx, %rax
addq $0x1148, %rsp           # imm = 0x1148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0xfb60
movq %rbp, (%rax)
jmp 0xfb68