// File: /workspace/github_c_makefile_star2_O1/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, 0x14(%rsp)
movq %rdx, %r14
testq %rsi, %rsi
leaq 0x2d7c2(%rip), %rax     # 0x40068
cmovneq %rsi, %rax
movq %rax, 0x30(%rsp)
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
leaq 0x130(%rsp), %rbx
movl $0x1001, %edx           # imm = 0x1001
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc640
movq %r15, 0x40(%rsp)
leaq 0x2d771(%rip), %rdi     # 0x4006d
callq 0xc050
movb $0x0, (%rbx)
testq %rax, %rax
movq %r14, 0x38(%rsp)
je 0x12928
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
movq %rax, %rsi
callq 0xc170
movb $0x0, 0x1130(%rsp)
jmp 0x1292a
xorl %ebx, %ebx
movq %rbx, 0x48(%rsp)
leaq 0x2d73e(%rip), %rax     # 0x40074
movq %rax, 0x50(%rsp)
leaq 0x3257d(%rip), %rax     # 0x44ebf
movq %rax, 0x58(%rsp)
callq 0xc150
movq %rax, %rbx
movl $0x0, (%rax)
leaq 0x18(%rsp), %r13
movabsq $-0x7bdef7bdef7bdef7, %r15 # imm = 0x8421084210842109
leaq 0x2d726(%rip), %r14     # 0x40091
xorl %r12d, %r12d
movq $0x0, (%rsp)
movq %rax, 0x28(%rsp)
movq 0x40(%rsp,%r12,8), %rbp
movabsq $0x3837363534333231, %rax # imm = 0x3837363534333231
movq %rax, 0x18(%rsp)
movl $0x303938, 0x1f(%rsp)   # imm = 0x303938
testq %rbp, %rbp
je 0x129ba
movq %rbp, %rdi
leaq 0xa0(%rsp), %rsi
callq 0xc8d0
testl %eax, %eax
jne 0x129ba
testb $0x40, 0xb9(%rsp)
jne 0x129d9
movl $0x2, (%rbx)
xorl %ebp, %ebp
testq %rbp, %rbp
jne 0x12b62
incq %r12
cmpq $0x4, %r12
jne 0x1297b
jmp 0x12b60
movq %rbp, %rdi
callq 0xc480
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
callq 0xc480
movq %rax, %rbx
movq %r13, %rdi
callq 0xc480
addq 0x8(%rsp), %rbx
leaq (%rax,%rbx), %rdi
addq $0x2, %rdi
callq 0xca50
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x12b24
movq %rbp, (%rsp)
xorl %ebp, %ebp
cmpl $0x0, 0x4477c(%rip)     # 0x571a4
jne 0x12a44
xorl %edi, %edi
callq 0xc9b0
movq %rax, %rbx
shll $0x8, %ebx
callq 0xc3f0
xorl %ebx, %eax
movl %eax, 0x44760(%rip)     # 0x571a4
movl 0x4475a(%rip), %edi     # 0x571a4
leal 0x1(%rdi), %eax
movl %eax, 0x44751(%rip)     # 0x571a4
callq 0xc7b0
cmpb $0x0, 0x18(%rsp)
je 0x12a9e
xorl %ebx, %ebx
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, 0x18(%rsp,%rbx)
incq %rbx
movq %r13, %rdi
callq 0xc480
cmpq %rax, %rbx
jb 0x12a61
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x2d5d7(%rip), %rsi     # 0x40084
movq (%rsp), %rdx
leaq 0x2f9be(%rip), %rcx     # 0x42476
movq 0x30(%rsp), %r8
movq %r13, %r9
xorl %eax, %eax
callq 0xcf50
movq %rbx, %rdi
movl $0xc2, %esi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0xcda0
cmpl $-0x1, %eax
jne 0x12af0
incl %ebp
cmpl $0xa, %ebp
jne 0x12a21
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
movq 0x28(%rsp), %rbx
je 0x12b34
movl %eax, %edi
leaq 0x2d58a(%rip), %rsi     # 0x4008d
callq 0xcc10
movq %rax, %rbp
movl $0x0, (%rbx)
cmpl $0x0, 0x14(%rsp)
jne 0x12b36
movq 0x8(%rsp), %rdi
callq 0xc160
jmp 0x12b36
movq 0x28(%rsp), %rbx
movl $0xc, (%rbx)
jmp 0x129c0
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x12b49
movq 0x8(%rsp), %rax
movq %rax, (%rsp)
jmp 0x129c2
movq 0x8(%rsp), %rdi
callq 0xc0c0
movq $0x0, (%rsp)
jmp 0x129c2
xorl %ebp, %ebp
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x12b7a
testq %rbp, %rbp
je 0x12b7a
movq (%rsp), %rcx
movq %rcx, (%rax)
jmp 0x12b83
movq (%rsp), %rdi
callq 0xc0c0
movq %rbp, %rax
addq $0x1138, %rsp           # imm = 0x1138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq