// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/src/deark-util.c
// Function: de_finfo_set_name_internal
static void de_finfo_set_name_internal(deark *c, de_finfo *fi, de_ucstring *s,
	unsigned int flags)
{
	i64 i;
	int allow_slashes;

	fi->orig_name_was_dot = 0;

	if(fi->file_name_internal) {
		ucstring_destroy(fi->file_name_internal);
		fi->file_name_internal = NULL;
	}
	if(!s) return;

	fi->file_name_internal = s;

	if((flags&DE_SNFLAG_STRIPTRAILINGSLASH) && s->len>0 && s->str[s->len-1]=='/') {
		ucstring_truncate(s, s->len-1);
	}

	if((flags&DE_SNFLAG_FULLPATH)) {
		// This part changes a name like "/a/b.c" to "a/b.c", which is probably
		// better than allowing it to be changed later to "_a/b.c".
		// TODO: I'm undecided about what to do about absolute paths when writing
		// to a zip file. We could leave them there (using an option), or delete
		// them, or prepend ".". Could have special cases if there are two
		/// leading slashes, of if the entire name is "/".
		maybe_delete_leading_slash(s);
	}

	allow_slashes = (c->allow_subdirs && (flags&DE_SNFLAG_FULLPATH));

	if(allow_slashes && s->len==1 && s->str[0]=='.') {
		// Remember that this file was named ".", which can be a valid subdir
		// name in some cases (but at this point we don't even know whether it
		// is a directory).
		fi->orig_name_was_dot = 1;
	}

	for(i=0; i<s->len; i++) {
		if(s->str[i]=='/' && allow_slashes) {
			continue;
		}
		s->str[i] = de_char_to_valid_fn_char(c, s->str[i]);
	}

	ucstring_strip_trailing_spaces(s);

	sanitize_filename1(c, s);

	if(allow_slashes) {
		sanitize_filename2(c, s);
	}

	// Don't allow empty filenames.
	if(s->len<1) {
		ucstring_append_sz(s, "_", DE_ENCODING_LATIN1);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movb $0x0, 0xd(%rsi)
movq (%rsi), %rdi
testq %rdi, %rdi
je 0xeaa35
callq 0xf6bb0
movq $0x0, (%r14)
testq %rbx, %rbx
je 0xeac53
movq %rbx, (%r14)
testb $0x2, %bpl
je 0xeaa66
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
jle 0xeaa66
movq 0x8(%rbx), %rax
cmpl $0x2f, -0x4(%rax,%rsi,4)
jne 0xeaa66
decq %rsi
movq %rbx, %rdi
callq 0xf688a
testb $0x1, %bpl
je 0xeaa8f
cmpq $0x2, 0x10(%rbx)
jl 0xeaa8f
movq 0x8(%rbx), %rax
cmpl $0x2f, (%rax)
jne 0xeaa8f
cmpl $0x2f, 0x4(%rax)
je 0xeaa8f
movl $0x1, %esi
movq %rbx, %rdi
callq 0xf692e
cmpb $0x0, 0x89(%r15)
setne %r15b
andb %bpl, %r15b
cmpb $0x1, %r15b
jne 0xeaab9
cmpq $0x1, 0x10(%rbx)
jne 0xeaab9
movq 0x8(%rbx), %rax
cmpl $0x2e, (%rax)
jne 0xeaab9
movb $0x1, 0xd(%r14)
movq 0x10(%rbx), %rax
testq %rax, %rax
jle 0xeab2a
movq 0x8(%rbx), %rcx
xorl %edx, %edx
movabsq $0x400000035002101, %rsi # imm = 0x400000035002101
movl $0x5f, %edi
movl (%rcx,%rdx,4), %r8d
cmpl $0x2f, %r8d
sete %r9b
testb %r9b, %r15b
jne 0xeab18
leal -0x20(%r8), %r9d
cmpl $0x5e, %r9d
ja 0xeab02
leal -0x22(%r8), %r9d
cmpl $0x3a, %r9d
ja 0xeab22
btq %r9, %rsi
jae 0xeab22
leal -0xa0(%r8), %r9d
cmpl $0x10ff60, %r9d         # imm = 0x10FF60
cmovael %edi, %r8d
movl %r8d, (%rcx,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0xeaad7
jmp 0xeab2a
cmpl $0x7c, %r8d
je 0xeab02
jmp 0xeab14
movq %rbx, %rdi
callq 0xf6900
movq 0x10(%rbx), %rax
cmpq $0x2, %rax
je 0xeab57
cmpq $0x1, %rax
jne 0xeab6c
movq 0x8(%rbx), %rcx
cmpl $0x2e, (%rcx)
jne 0xeab51
movl $0x5f, (%rcx)
cmpq $0x2, %rax
jne 0xeab6c
movq 0x8(%rbx), %rcx
cmpl $0x2e, (%rcx)
jne 0xeab6c
cmpl $0x2e, 0x4(%rcx)
jne 0xeab6c
movl $0x5f, (%rcx)
testb %r15b, %r15b
je 0xeac4e
testq %rax, %rax
jle 0xeab89
movq 0x8(%rbx), %rcx
cmpl $0x2f, (%rcx)
jne 0xeab89
movl $0x5f, (%rcx)
cmpq $0x2, %rax
jl 0xeac36
leaq -0x1(%rax), %rcx
movq 0x8(%rbx), %rdx
xorl %esi, %esi
cmpl $0x2f, (%rdx,%rsi,4)
jne 0xeabb1
cmpl $0x2f, 0x4(%rdx,%rsi,4)
jne 0xeabb1
movl $0x5f, (%rdx,%rsi,4)
incq %rsi
cmpq %rsi, %rcx
jne 0xeab9d
cmpq $0x2, %rax
jl 0xeac36
movq 0x8(%rbx), %rdx
leaq -0x2(%rax), %rsi
xorl %edi, %edi
cmpl $0x2e, (%rdx,%rdi,4)
jne 0xeac0e
cmpl $0x2e, 0x4(%rdx,%rdi,4)
jne 0xeac0e
testq %rdi, %rdi
je 0xeabe2
cmpl $0x2f, -0x4(%rdx,%rdi,4)
jne 0xeabe7
movb $0x1, %r8b
jmp 0xeabea
xorl %r8d, %r8d
cmpq %rsi, %rdi
jge 0xeabf6
cmpl $0x2f, 0x8(%rdx,%rdi,4)
jne 0xeabfb
movb $0x1, %r9b
jmp 0xeabfe
xorl %r9d, %r9d
andb %r9b, %r8b
cmpb $0x1, %r8b
jne 0xeac0e
movl $0x5f, (%rdx,%rdi,4)
incq %rdi
cmpq %rdi, %rcx
jne 0xeabc9
cmpq $0x2, %rax
jl 0xeac36
movq 0x8(%rbx), %rcx
cmpl $0x2f, -0x8(%rcx,%rax,4)
jne 0xeac36
cmpl $0x2e, -0x4(%rcx,%rax,4)
jne 0xeac36
movl $0x5f, -0x4(%rcx,%rax,4)
testq %rax, %rax
jle 0xeac4e
movq 0x8(%rbx), %rcx
cmpl $0x2f, -0x4(%rcx,%rax,4)
jne 0xeac4e
movl $0x5f, -0x4(%rcx,%rax,4)
testq %rax, %rax
jle 0xeac5e
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x43a0f(%rip), %rsi     # 0x12e674
movq %rbx, %rdi
movl $0x5, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xf6a40