// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-user.c
// Function: make_output_filename
static char *make_output_filename(deark *c, const char *dirname, const char *fn,
	const char *suffix, unsigned int flags)
{
	char *newfn = NULL;
	const char *fn_part;
	size_t newfn_alloc;
	de_ucstring *tmps = NULL;
	i64 fnpartpos;

	tmps = ucstring_create(c);

	if(dirname && dirname[0]) {
		ucstring_append_sz(tmps, dirname, DE_ENCODING_UTF8);
		append_pathsep_if_needed(tmps);
	}

	fnpartpos = tmps->len;

	if(flags & 0x1) {
		// Use base filename only
		fn_part = get_basename_ptr(fn);
	}
	else {
		fn_part = fn;
	}
	if(fn_part) {
		ucstring_append_sz(tmps, fn_part, DE_ENCODING_UTF8);
	}

	if(tmps->len <= fnpartpos) {
		// Disallow empty filename
		ucstring_append_sz(tmps, "_", DE_ENCODING_LATIN1);
	}

	if(suffix) {
		ucstring_append_sz(tmps, suffix, DE_ENCODING_UTF8);
	}

	if(flags & 0x2) {
		// Remove path separators; sanitize
		i64 i;

		for(i=fnpartpos; i<tmps->len; i++) {
			if(is_pathsep(tmps->str[i])) {
				tmps->str[i] = '_';
			}

			if(i==fnpartpos && tmps->str[i]=='.') {
				tmps->str[i] = '_';
			}
		}
	}

#ifdef DE_WINDOWS
	if(flags & 0x4) {
		// When a filename-like option is supplied on the command line, there are
		// cases where we can't be agnostic about which characters are path
		// separators. One of them is when that name is written to an archive
		// (zip/tar) file.
		// Our rule is that, for Windows builds, both "\" and "/" are path
		// separators. For Unix builds, only "/" is, and "\" will be treated as
		// an ordinary filename character, if allowed by the archive format.
		// This difference in behavior on different platforms is unfortunate, but
		// I think it's the least bad thing to do.
		backslashes_to_slashes(tmps);
	}
#endif

	// Don't allow empty filename
	if(tmps->len<1) goto done;

	newfn_alloc = (size_t)ucstring_count_utf8_bytes(tmps) + 1;
	newfn = de_malloc(c, newfn_alloc);
	ucstring_to_sz(tmps, newfn, newfn_alloc, 0, DE_ENCODING_UTF8);

done:
	ucstring_destroy(tmps);
	return newfn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x18ed57
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x18ed57
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x2, %edx
callq 0x1715e0
movq -0x48(%rbp), %rdi
callq 0x18f850
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x18ed7d
movq -0x18(%rbp), %rdi
callq 0x18f8b0
movq %rax, -0x38(%rbp)
jmp 0x18ed85
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x18ed9e
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x2, %edx
callq 0x1715e0
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x50(%rbp), %rax
jg 0x18edc1
movq -0x48(%rbp), %rdi
leaq 0x27c4f(%rip), %rsi     # 0x1b6a06
movl $0x5, %edx
callq 0x1715e0
cmpq $0x0, -0x20(%rbp)
je 0x18edda
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x1715e0
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x18ee6c
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x18ee6a
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x18f920
cmpl $0x0, %eax
je 0x18ee2b
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
movl $0x5f, (%rax,%rcx,4)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x18ee5a
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
cmpl $0x2e, (%rax,%rcx,4)
jne 0x18ee5a
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
movl $0x5f, (%rax,%rcx,4)
jmp 0x18ee5c
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x18edf1
jmp 0x18ee6c
movq -0x48(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jge 0x18ee79
jmp 0x18eeb4
movq -0x48(%rbp), %rdi
callq 0x172060
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %ecx, %ecx
movl $0x2, %r8d
callq 0x172200
movq -0x48(%rbp), %rdi
callq 0x171750
movq -0x30(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)