// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/cache1d.c
// Function: findfrompath
int findfrompath(const char *fn, char **where)
{
	searchpath_t *sp;
	char *pfn, *ffn;
	size_t allocsiz;

	// pathsearchmode == 0: tests current dir and then the dirs of the path stack
	// pathsearchmode == 1: tests fn without modification, then like for pathsearchmode == 0
	
	if (pathsearchmode) {
		// test unmolested filename first
		if (access(fn, F_OK) >= 0) {
			*where = strdup(fn);
			return 0;
		}
	}

	for (; toupperlookup[(int)(unsigned char)*fn] == '/'; fn++);
	ffn = strdup(fn);
	if (!ffn) return -1;
	Bcorrectfilename(ffn,0);	// compress relative paths
	
	allocsiz = max(maxsearchpathlen, 2u);	// "./" (aka. curdir)
	allocsiz += strlen(ffn);
	allocsiz += 1;	// a nul
	
	pfn = (char *)malloc(allocsiz);
	if (!pfn) { free(ffn); return -1; }

	strcpy(pfn, "./");
	strcat(pfn, ffn);
	if (access(pfn, F_OK) >= 0) {
		*where = pfn;
		free(ffn);
		return 0;
	}
	
	for (sp = searchpathhead; sp; sp = sp->next) {
		strcpy(pfn, sp->path);
		strcat(pfn, ffn);
		//buildprintf("Trying %s\n", pfn);
		if (access(pfn, F_OK) >= 0) {
			*where = pfn;
			free(ffn);
			return 0;
		}
	}
	free(pfn); free(ffn);
	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpl $0x0, 0x1c1f99(%rip)    # 0x1f1260
je 0x2f2fa
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x6150
cmpl $0x0, %eax
jl 0x2f2f8
movq -0x10(%rbp), %rdi
callq 0x6060
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x2f493
jmp 0x2f2fa
jmp 0x2f2fc
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movslq %eax, %rcx
leaq 0xb10f3(%rip), %rax     # 0xe0400
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x2f326
jmp 0x2f318
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x2f2fc
movq -0x10(%rbp), %rdi
callq 0x6060
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2f346
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2f493
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x328d0
cmpq $0x2, 0x1c1f17(%rip)    # 0x1f1270
jbe 0x2f368
movq 0x1c1f0e(%rip), %rax    # 0x1f1270
movq %rax, -0x40(%rbp)
jmp 0x2f373
movl $0x2, %eax
movq %rax, -0x40(%rbp)
jmp 0x2f373
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x63d0
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x68f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2f3c1
movq -0x30(%rbp), %rdi
callq 0x61c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2f493
movq -0x28(%rbp), %rdi
leaq 0x82c1e(%rip), %rsi     # 0xb1fea
callq 0x63e0
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6690
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x6150
cmpl $0x0, %eax
jl 0x2f40e
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
callq 0x61c0
movl $0x0, -0x4(%rbp)
jmp 0x2f493
movq 0x1c1e53(%rip), %rax    # 0x1f1268
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x2f47a
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x63e0
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6690
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x6150
cmpl $0x0, %eax
jl 0x2f46b
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
callq 0x61c0
movl $0x0, -0x4(%rbp)
jmp 0x2f493
jmp 0x2f46d
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x2f419
movq -0x28(%rbp), %rdi
callq 0x61c0
movq -0x30(%rbp), %rdi
callq 0x61c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)