// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-util.c
// Function: sanitize_filename2
static void sanitize_filename2(deark *c, de_ucstring *s)
{
	i64 i;

	// Don't allow an initial "/"
	if(s->len>=1 && s->str[0]=='/') {
		s->str[0] = '_';
	}

	// Don't allow consecutive slashes
	for(i=0; i<s->len-1; i++) {
		if(s->str[i]=='/' && s->str[i+1]=='/') {
			s->str[i] = '_';
		}
	}

	// Don't allow a component to be ".."
	for(i=0; i<s->len-1; i++) {
		if(s->str[i]=='.' && s->str[i+1]=='.') {
			int test1 = 0; // Is ".." at the beginning of a component?
			int test2 = 0; // Is ".." at the end of a component?
			if(i==0 || s->str[i-1]=='/') {
				test1 = 1;
			}
			if(i>=s->len-2 || s->str[i+2]=='/') {
				test2 = 1;
			}
			if(test1 && test2) {
				s->str[i] = '_';
			}
		}
	}

	// Don't allow name to end with "/."
	if(s->len>=2 && s->str[s->len-2]=='/' && s->str[s->len-1]=='.') {
		s->str[s->len-1] = '_';
	}

	// Don't allow name to end with "/"
	if(s->len>=1 && s->str[s->len-1]=='/') {
		s->str[s->len-1] = '_';
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jl 0x15fe92
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x2f, (%rax)
jne 0x15fe92
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x5f, (%rax)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x15fef7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpl $0x2f, (%rax,%rcx,4)
jne 0x15fee7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpl $0x2f, 0x4(%rax,%rcx,4)
jne 0x15fee7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movl $0x5f, (%rax,%rcx,4)
jmp 0x15fee9
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x15fe9a
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x15ffda
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpl $0x2e, (%rax,%rcx,4)
jne 0x15ffc7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpl $0x2e, 0x4(%rax,%rcx,4)
jne 0x15ffc7
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x15ff70
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpl $0x2f, (%rax,%rcx,4)
jne 0x15ff77
movl $0x1, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x2, %rcx
cmpq %rcx, %rax
jge 0x15ff9f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpl $0x2f, 0x8(%rax,%rcx,4)
jne 0x15ffa6
movl $0x1, -0x20(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x15ffc5
cmpl $0x0, -0x20(%rbp)
je 0x15ffc5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movl $0x5f, (%rax,%rcx,4)
jmp 0x15ffc7
jmp 0x15ffc9
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x15feff
movq -0x10(%rbp), %rax
cmpq $0x2, 0x10(%rax)
jl 0x160034
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x2, %rcx
cmpl $0x2f, (%rax,%rcx,4)
jne 0x160034
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x1, %rcx
cmpl $0x2e, (%rax,%rcx,4)
jne 0x160034
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x1, %rcx
movl $0x5f, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jl 0x160074
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x1, %rcx
cmpl $0x2f, (%rax,%rcx,4)
jne 0x160074
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq $0x1, %rcx
movl $0x5f, (%rax,%rcx,4)
popq %rbp
retq
nopw %cs:(%rax,%rax)