// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/tinydir.c
// Function: tinydir_file_open
_TINYDIR_FUNC
int tinydir_file_open(tinydir_file *file, const char *path)
{
	tinydir_dir dir;
	int result = 0;
	int found = 0;
	char dir_name_buf[_TINYDIR_PATH_MAX];
	char file_name_buf[_TINYDIR_FILENAME_MAX];
	char *dir_name;
	char *base_name;
#ifdef _MSC_VER
	char drive_buf[_TINYDIR_PATH_MAX];
	char ext_buf[_TINYDIR_FILENAME_MAX];
#endif

	if (file == NULL || path == NULL || strlen(path) == 0)
	{
		errno = EINVAL;
		return -1;
	}
	if (strlen(path) + _TINYDIR_PATH_EXTRA >= _TINYDIR_PATH_MAX)
	{
		errno = ENAMETOOLONG;
		return -1;
	}

	/* Get the parent path */
#ifdef _MSC_VER
	if (_splitpath_s(
			path,
			drive_buf, sizeof drive_buf,
			dir_name_buf, sizeof dir_name_buf,
			file_name_buf, sizeof file_name_buf,
			ext_buf, sizeof ext_buf))
	{
		errno = EINVAL;
		return -1;
	}
	/* Concatenate the drive letter and dir name to form full dir name */
	strcat(drive_buf, dir_name_buf);
	dir_name = drive_buf;
	/* Concatenate the file name and extension to form base name */
	strcat(file_name_buf, ext_buf);
	base_name = file_name_buf;
#else
	strcpy(dir_name_buf, path);
	dir_name = dirname(dir_name_buf);
	strcpy(file_name_buf, path);
	base_name = basename(file_name_buf);
#endif

	/* Open the parent directory */
	if (tinydir_open(&dir, dir_name) == -1)
	{
		return -1;
	}

	/* Read through the parent directory and look for the file */
	while (dir.has_next)
	{
		if (tinydir_readfile(&dir, file) == -1)
		{
			result = -1;
			goto bail;
		}
		if (strcmp(file->name, base_name) == 0)
		{
			/* File found */
			found = 1;
			goto bail;
		}
		tinydir_next(&dir);
	}
	if (!found)
	{
		result = -1;
		errno = ENOENT;
	}

bail:
	tinydir_close(&dir);
	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2160, %rsp           # imm = 0x2160
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1044(%rbp)
movl $0x0, -0x1048(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x421b14
cmpq $0x0, -0x18(%rbp)
je 0x421b14
movq -0x18(%rbp), %rdi
callq 0x401138
cmpq $0x0, %rax
jne 0x421b2b
callq 0x42de60
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x421c55
movq -0x18(%rbp), %rdi
callq 0x401138
addq $0x0, %rax
cmpq $0x1000, %rax           # imm = 0x1000
jb 0x421b57
callq 0x42de60
movl $0x24, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x421c55
leaq -0x2050(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x401020
leaq -0x2050(%rbp), %rdi
callq 0x492270
movq %rax, -0x2158(%rbp)
leaq -0x2150(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x401020
leaq -0x2150(%rbp), %rdi
callq 0x435480
movq %rax, -0x2160(%rbp)
movq -0x2158(%rbp), %rsi
leaq -0x1040(%rbp), %rdi
callq 0x421240
cmpl $-0x1, %eax
jne 0x421bc1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x421c55
jmp 0x421bc3
cmpl $0x0, -0x40(%rbp)
je 0x421c20
movq -0x10(%rbp), %rsi
leaq -0x1040(%rbp), %rdi
callq 0x421690
cmpl $-0x1, %eax
jne 0x421bea
movl $0xffffffff, -0x1044(%rbp) # imm = 0xFFFFFFFF
jmp 0x421c40
movq -0x10(%rbp), %rdi
addq $0x1000, %rdi           # imm = 0x1000
movq -0x2160(%rbp), %rsi
callq 0x4010f0
cmpl $0x0, %eax
jne 0x421c12
movl $0x1, -0x1048(%rbp)
jmp 0x421c40
leaq -0x1040(%rbp), %rdi
callq 0x4215f0
jmp 0x421bc3
cmpl $0x0, -0x1048(%rbp)
jne 0x421c3e
movl $0xffffffff, -0x1044(%rbp) # imm = 0xFFFFFFFF
callq 0x42de60
movl $0x2, (%rax)
jmp 0x421c40
leaq -0x1040(%rbp), %rdi
callq 0x421380
movl -0x1044(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2160, %rsp           # imm = 0x2160
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)