// File: /workspace/github_c_makefile_star2_O2/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 0xdfda3
callq 0xeaf3c
andq $0x0, (%r14)
testq %rbx, %rbx
je 0xdff96
movq %rbx, (%r14)
testb $0x2, %bpl
je 0xdfdd4
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
jle 0xdfdd4
movq 0x8(%rbx), %rax
cmpl $0x2f, -0x4(%rax,%rsi,4)
jne 0xdfdd4
decq %rsi
movq %rbx, %rdi
callq 0xeac8c
testb $0x1, %bpl
je 0xdfe1f
cmpq $0x2, 0x10(%rbx)
jl 0xdfdfb
movq 0x8(%rbx), %rax
cmpl $0x2f, (%rax)
jne 0xdfdfb
cmpl $0x2f, 0x4(%rax)
je 0xdfdfb
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xead2a
cmpb $0x0, 0x89(%r15)
je 0xdfe1f
movb $0x1, %bpl
cmpq $0x1, 0x10(%rbx)
jne 0xdfe21
movq 0x8(%rbx), %rax
cmpl $0x2e, (%rax)
jne 0xdfe21
movb $0x1, 0xd(%r14)
jmp 0xdfe21
xorl %ebp, %ebp
movq 0x10(%rbx), %rax
xorl %ecx, %ecx
testq %rax, %rax
cmovleq %rcx, %rax
movabsq $0x400000035002101, %rdx # imm = 0x400000035002101
pushq $0x5f
popq %rsi
cmpq %rcx, %rax
je 0xdfe92
movq 0x8(%rbx), %rdi
movl (%rdi,%rcx,4), %r8d
cmpl $0x2f, %r8d
sete %r9b
testb %r9b, %bpl
jne 0xdfe85
leal -0x20(%r8), %r9d
cmpl $0x5e, %r9d
ja 0xdfe6f
leal -0x22(%r8), %r9d
cmpl $0x3a, %r9d
ja 0xdfe8a
btq %r9, %rdx
jae 0xdfe8a
leal -0xa0(%r8), %r9d
cmpl $0x10ff60, %r9d         # imm = 0x10FF60
cmovael %esi, %r8d
movl %r8d, (%rdi,%rcx,4)
incq %rcx
jmp 0xdfe3b
cmpl $0x7c, %r8d
je 0xdfe6f
jmp 0xdfe81
movq %rbx, %rdi
callq 0xead03
movq 0x10(%rbx), %rax
cmpq $0x2, %rax
je 0xdfeb5
cmpq $0x1, %rax
jne 0xdfeca
movq 0x8(%rbx), %rcx
cmpl $0x2e, (%rcx)
je 0xdfec4
jmp 0xdfeca
movq 0x8(%rbx), %rcx
cmpl $0x2e, (%rcx)
jne 0xdfeca
cmpl $0x2e, 0x4(%rcx)
jne 0xdfeca
movl $0x5f, (%rcx)
testb %bpl, %bpl
je 0xdff12
testq %rax, %rax
jle 0xdfee3
movq 0x8(%rbx), %rcx
cmpl $0x2f, (%rcx)
jne 0xdfee3
movl $0x5f, (%rcx)
leaq -0x1(%rax), %rcx
xorl %edx, %edx
testq %rcx, %rcx
cmovleq %rdx, %rcx
cmpq %rdx, %rcx
je 0xdff1c
movq 0x8(%rbx), %rsi
cmpl $0x2f, (%rsi,%rdx,4)
jne 0xdff0d
cmpl $0x2f, 0x4(%rsi,%rdx,4)
jne 0xdff0d
movl $0x5f, (%rsi,%rdx,4)
incq %rdx
jmp 0xdfef0
testq %rax, %rax
jg 0xdff96
jmp 0xdffa1
leaq -0x2(%rax), %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0xdff5c
movq 0x8(%rbx), %rdi
cmpl $0x2e, (%rdi,%rsi,4)
jne 0xdff57
cmpl $0x2e, 0x4(%rdi,%rsi,4)
jne 0xdff57
testq %rsi, %rsi
je 0xdff44
cmpl $0x2f, -0x4(%rdi,%rsi,4)
jne 0xdff57
cmpq %rdx, %rsi
jge 0xdff50
cmpl $0x2f, 0x8(%rdi,%rsi,4)
jne 0xdff57
movl $0x5f, (%rdi,%rsi,4)
incq %rsi
jmp 0xdff22
cmpq $0x2, %rax
jl 0xdff7e
movq 0x8(%rbx), %rcx
cmpl $0x2f, -0x8(%rcx,%rax,4)
jne 0xdff87
cmpl $0x2e, -0x4(%rcx,%rax,4)
jne 0xdff87
movl $0x5f, -0x4(%rcx,%rax,4)
jmp 0xdff87
testq %rax, %rax
jle 0xdffa1
movq 0x8(%rbx), %rcx
cmpl $0x2f, -0x4(%rcx,%rax,4)
jne 0xdff96
movl $0x5f, -0x4(%rcx,%rax,4)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x41754(%rip), %rsi     # 0x1216fc
pushq $0x5
popq %rdx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xeae42