// File: /workspace/github_c_makefile_star2_O3/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 0xea590
callq 0xf6753
movq $0x0, (%r14)
testq %rbx, %rbx
je 0xea766
movq %rbx, (%r14)
testb $0x2, %bpl
je 0xea5c1
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
jle 0xea5c1
movq 0x8(%rbx), %rax
cmpl $0x2f, -0x4(%rax,%rsi,4)
jne 0xea5c1
decq %rsi
movq %rbx, %rdi
callq 0xf642a
testb $0x1, %bpl
je 0xea60e
cmpq $0x2, 0x10(%rbx)
jl 0xea5ea
movq 0x8(%rbx), %rax
cmpl $0x2f, (%rax)
jne 0xea5ea
cmpl $0x2f, 0x4(%rax)
je 0xea5ea
movl $0x1, %esi
movq %rbx, %rdi
callq 0xf64ce
cmpb $0x0, 0x89(%r15)
je 0xea60e
movb $0x1, %bpl
cmpq $0x1, 0x10(%rbx)
jne 0xea610
movq 0x8(%rbx), %rax
cmpl $0x2e, (%rax)
jne 0xea610
movb $0x1, 0xd(%r14)
jmp 0xea610
xorl %ebp, %ebp
movq 0x10(%rbx), %rax
testq %rax, %rax
jle 0xea681
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, %bpl
jne 0xea66f
leal -0x20(%r8), %r9d
cmpl $0x5e, %r9d
ja 0xea659
leal -0x22(%r8), %r9d
cmpl $0x3a, %r9d
ja 0xea679
btq %r9, %rsi
jae 0xea679
leal -0xa0(%r8), %r9d
cmpl $0x10ff60, %r9d         # imm = 0x10FF60
cmovael %edi, %r8d
movl %r8d, (%rcx,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0xea62e
jmp 0xea681
cmpl $0x7c, %r8d
je 0xea659
jmp 0xea66b
movq %rbx, %rdi
callq 0xf64a0
movq 0x10(%rbx), %rax
cmpq $0x2, %rax
je 0xea6a4
cmpq $0x1, %rax
jne 0xea6b9
movq 0x8(%rbx), %rcx
cmpl $0x2e, (%rcx)
je 0xea6b3
jmp 0xea6b9
movq 0x8(%rbx), %rcx
cmpl $0x2e, (%rcx)
jne 0xea6b9
cmpl $0x2e, 0x4(%rcx)
jne 0xea6b9
movl $0x5f, (%rcx)
testb %bpl, %bpl
je 0xea761
testq %rax, %rax
jle 0xea771
movq 0x8(%rbx), %rcx
cmpl $0x2f, (%rcx)
jne 0xea6da
movl $0x5f, (%rcx)
cmpq $0x1, %rax
je 0xea752
leaq -0x1(%rax), %rdx
xorl %esi, %esi
cmpl $0x2f, (%rcx,%rsi,4)
jne 0xea6fa
cmpl $0x2f, 0x4(%rcx,%rsi,4)
jne 0xea6fa
movl $0x5f, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0xea6e6
leaq -0x2(%rax), %rsi
xorl %edi, %edi
cmpl $0x2e, (%rcx,%rdi,4)
jne 0xea734
cmpl $0x2e, 0x4(%rcx,%rdi,4)
jne 0xea734
testq %rdi, %rdi
je 0xea721
cmpl $0x2f, -0x4(%rcx,%rdi,4)
jne 0xea734
cmpq %rsi, %rdi
jge 0xea72d
cmpl $0x2f, 0x8(%rcx,%rdi,4)
jne 0xea734
movl $0x5f, (%rcx,%rdi,4)
incq %rdi
cmpq %rdi, %rdx
jne 0xea708
cmpl $0x2f, -0x8(%rcx,%rax,4)
jne 0xea752
cmpl $0x2e, -0x4(%rcx,%rax,4)
jne 0xea752
movl $0x5f, -0x4(%rcx,%rax,4)
cmpl $0x2f, -0x4(%rcx,%rax,4)
jne 0xea761
movl $0x5f, -0x4(%rcx,%rax,4)
testq %rax, %rax
jle 0xea771
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4420c(%rip), %rsi     # 0x12e984
movq %rbx, %rdi
movl $0x5, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xf65e3