// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10c0, %rsp           # imm = 0x10C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x11596
movq -0x10(%rbp), %rax
movq %rax, -0x10c0(%rbp)
jmp 0x115a6
leaq 0x54acb(%rip), %rax     # 0x66068
movq %rax, -0x10c0(%rbp)
jmp 0x115a6
movq -0x10c0(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x60, %edx
callq 0xc6a0
leaq -0x10b0(%rbp), %rdi
xorl %esi, %esi
movl $0x1001, %edx           # imm = 0x1001
callq 0xc6a0
movl $0x0, -0x10b4(%rbp)
movl $0x0, -0x10b8(%rbp)
movq -0x8(%rbp), %rcx
movl -0x10b8(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x10b8(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
leaq -0x10b0(%rbp), %rsi
leaq 0x54a55(%rip), %rdi     # 0x6606d
movl $0x1001, %edx           # imm = 0x1001
callq 0x11730
movq %rax, %rcx
movl -0x10b8(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x10b8(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movl -0x10b8(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x10b8(%rbp)
cltq
leaq 0x54a1a(%rip), %rcx     # 0x66074
movq %rcx, -0xa0(%rbp,%rax,8)
movl -0x10b8(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x10b8(%rbp)
cltq
leaq 0x5955b(%rip), %rcx     # 0x6abd7
movq %rcx, -0xa0(%rbp,%rax,8)
movl -0x10b8(%rbp), %eax
movl %eax, -0x10b4(%rbp)
callq 0xc180
movl $0x0, (%rax)
movl $0x0, -0x10b8(%rbp)
movl -0x10b8(%rbp), %eax
cmpl -0x10b4(%rbp), %eax
jge 0x116fa
movslq -0x10b8(%rbp), %rax
movq -0xa0(%rbp,%rax,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x1c(%rbp), %ecx
leaq -0x30(%rbp), %rdx
callq 0x117a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x116e7
jmp 0x116fa
jmp 0x116e9
movl -0x10b8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10b8(%rbp)
jmp 0x116a5
cmpq $0x0, -0x28(%rbp)
je 0x11715
cmpq $0x0, -0x18(%rbp)
je 0x11715
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1171e
movq -0x30(%rbp), %rdi
callq 0xc0d0
movq -0x28(%rbp), %rax
addq $0x10c0, %rsp           # imm = 0x10C0
popq %rbp
retq
nopl (%rax,%rax)