// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/compat.c
// Function: Bcorrectfilename
int Bcorrectfilename(char *filename, int removefn)
{
	char *fn;
	const int MAXTOKARR = 64;
	char *tokarr[64], *first, *next, *token;
	int i, ntok = 0, leadslash = 0, trailslash = 0;
	
	fn = strdup(filename);
	if (!fn) return -1;
	
	// find the end of the string
	for (first=fn; *first; first++) {
#ifdef _WIN32
		// translating backslashes to forwardslashes on the way
		if (*first == '\\') *first = '/';
#endif
	}
	leadslash = (*fn == '/');
	trailslash = (first>fn && first[-1] == '/');
	
	// carve up the string into pieces by directory, and interpret
	// the . and .. components
	first = fn;
	do {
		token = Bstrtoken(first, "/", &next, 1);
		first = NULL;
		if (!token) break;
		else if (token[0] == 0) continue;
		else if (token[0] == '.' && token[1] == 0) continue;
		else if (token[0] == '.' && token[1] == '.' && token[2] == 0) ntok = max(0,ntok-1);
		else tokarr[ntok++] = token;
	} while (ntok < MAXTOKARR);
	
	if (!trailslash && removefn) { ntok = max(0,ntok-1); trailslash = 1; }
	if (ntok == 0 && trailslash && leadslash) trailslash = 0;
	
	// rebuild the filename
	first = filename;
	if (leadslash) *(first++) = '/';
	for (i=0; i<ntok; i++) {
		if (i>0) *(first++) = '/';
		for (token=tokarr[i]; *token; token++)
			*(first++) = *token;
	}
	if (trailslash) *(first++) = '/';
	*(first++) = 0;
	
	free(fn);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x40, -0x24(%rbp)
movl $0x0, -0x250(%rbp)
movl $0x0, -0x254(%rbp)
movl $0x0, -0x258(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6060
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x32927
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x32c58
movq -0x20(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x238(%rbp), %rax
cmpb $0x0, (%rax)
je 0x32954
jmp 0x32940
movq -0x238(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x238(%rbp)
jmp 0x32932
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x254(%rbp)
movq -0x238(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x259(%rbp)
jbe 0x32998
movq -0x238(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x2f, %eax
sete %al
movb %al, -0x259(%rbp)
movb -0x259(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x258(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x238(%rbp), %rdi
leaq 0x7f629(%rip), %rsi     # 0xb1feb
leaq -0x240(%rbp), %rdx
movl $0x1, %ecx
callq 0x32c70
movq %rax, -0x248(%rbp)
movq $0x0, -0x238(%rbp)
cmpq $0x0, -0x248(%rbp)
jne 0x329f4
jmp 0x32ac8
movq -0x248(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x32a08
jmp 0x32abb
movq -0x248(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x32a2c
movq -0x248(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x32a2c
jmp 0x32abb
movq -0x248(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x32a91
movq -0x248(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2e, %eax
jne 0x32a91
movq -0x248(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x32a91
movl -0x250(%rbp), %ecx
subl $0x1, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jle 0x32a74
xorl %eax, %eax
movl %eax, -0x260(%rbp)
jmp 0x32a83
movl -0x250(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x260(%rbp)
movl -0x260(%rbp), %eax
movl %eax, -0x250(%rbp)
jmp 0x32ab3
movq -0x248(%rbp), %rcx
movl -0x250(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x250(%rbp)
cltq
movq %rcx, -0x230(%rbp,%rax,8)
jmp 0x32ab5
jmp 0x32ab7
jmp 0x32ab9
jmp 0x32abb
cmpl $0x40, -0x250(%rbp)
jl 0x329b4
cmpl $0x0, -0x258(%rbp)
jne 0x32b15
cmpl $0x0, -0x14(%rbp)
je 0x32b15
movl -0x250(%rbp), %ecx
subl $0x1, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jle 0x32af0
xorl %eax, %eax
movl %eax, -0x264(%rbp)
jmp 0x32aff
movl -0x250(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x264(%rbp)
movl -0x264(%rbp), %eax
movl %eax, -0x250(%rbp)
movl $0x1, -0x258(%rbp)
cmpl $0x0, -0x250(%rbp)
jne 0x32b3a
cmpl $0x0, -0x258(%rbp)
je 0x32b3a
cmpl $0x0, -0x254(%rbp)
je 0x32b3a
movl $0x0, -0x258(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x238(%rbp)
cmpl $0x0, -0x254(%rbp)
je 0x32b66
movq -0x238(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x238(%rbp)
movb $0x2f, (%rax)
movl $0x0, -0x24c(%rbp)
movl -0x24c(%rbp), %eax
cmpl -0x250(%rbp), %eax
jge 0x32c0f
cmpl $0x0, -0x24c(%rbp)
jle 0x32ba3
movq -0x238(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x238(%rbp)
movb $0x2f, (%rax)
movslq -0x24c(%rbp), %rax
movq -0x230(%rbp,%rax,8), %rax
movq %rax, -0x248(%rbp)
movq -0x248(%rbp), %rax
cmpb $0x0, (%rax)
je 0x32bf9
movq -0x248(%rbp), %rax
movb (%rax), %cl
movq -0x238(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x238(%rbp)
movb %cl, (%rax)
movq -0x248(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x248(%rbp)
jmp 0x32bb9
jmp 0x32bfb
movl -0x24c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24c(%rbp)
jmp 0x32b70
cmpl $0x0, -0x258(%rbp)
je 0x32c30
movq -0x238(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x238(%rbp)
movb $0x2f, (%rax)
movq -0x238(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x238(%rbp)
movb $0x0, (%rax)
movq -0x20(%rbp), %rdi
callq 0x61c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
nopw %cs:(%rax,%rax)