// File: sundale[P]gcode/rs274ngc/interp_o_word.cc
// Function: Interp::findFile(char*, char*, char*)
int Interp::findFile( // ARGUMENTS
		     char *direct,  // the directory to start looking in
		     char *target,  // the name of the file to find
		     char *foundFileDirect) // where to store the result
{
    FILE *file;
    DIR *aDir;
    struct dirent *aFile;
    char targetPath[PATH_MAX+1];

    snprintf(targetPath, PATH_MAX, "%s/%s", direct, target);

    file = fopen(targetPath, "r");

    if(file)
    {
        strncpy(foundFileDirect, direct, PATH_MAX);
        fclose(file);
        return INTERP_OK;
    }

    aDir = opendir(direct);

    if(!aDir)
    {
	ERS(NCE_FILE_NOT_OPEN);
    }

    while((aFile = readdir(aDir)))
    {
        if(aFile->d_type == DT_DIR &&
           (0 != strcmp(aFile->d_name, "..")) &&
           (0 != strcmp(aFile->d_name, ".")))
        {
            char path[PATH_MAX+1];
            snprintf(path, PATH_MAX, "%s/%s", direct, aFile->d_name);
            if(INTERP_OK == findFile(path, target, foundFileDirect))
            {
	        closedir(aDir);
                return INTERP_OK;
            }
        }
    }
    closedir(aDir);
    ERS(NCE_FILE_NOT_OPEN);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2070, %rsp           # imm = 0x2070
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x2068(%rbp)
leaq -0x1050(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x13e9f(%rip), %rdx     # 0x7ece0
movb $0x0, %al
callq 0x11c00
leaq -0x1050(%rbp), %rdi
leaq 0x12ea9(%rip), %rsi     # 0x7dcff
callq 0x11490
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x6ae8d
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x10840
movq -0x30(%rbp), %rdi
callq 0x11160
movl $0x0, -0x4(%rbp)
jmp 0x6b11e
movq -0x18(%rbp), %rdi
callq 0x119c0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x6af7d
jmp 0x6aea7
leaq 0x13e38(%rip), %rdi     # 0x7ece6
callq 0x10380
movq -0x2068(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x1c095(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x1c084(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x1c076(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x13df5(%rip), %rsi     # 0x7ecf4
movl $0x50, %edx
callq 0x10840
movq 0x1c050(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1c042(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x1c02a(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x1c01a(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x1c00d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1bfff(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x6b11e
jmp 0x6af7f
movq -0x38(%rbp), %rdi
callq 0x11a90
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x6b044
movq -0x40(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x4, %eax
jne 0x6b03f
movq -0x40(%rbp), %rdi
addq $0x13, %rdi
leaq 0x13d6b(%rip), %rsi     # 0x7ed21
callq 0x11820
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x6b03f
movq -0x40(%rbp), %rdi
addq $0x13, %rdi
leaq 0x13708(%rip), %rsi     # 0x7e6da
callq 0x11820
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x6b03f
leaq -0x2060(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %r8
addq $0x13, %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x13ce2(%rip), %rdx     # 0x7ece0
movb $0x0, %al
callq 0x11c00
movq -0x2068(%rbp), %rdi
leaq -0x2060(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x11fa0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x6b03d
movq -0x38(%rbp), %rdi
callq 0x11c40
movl $0x0, -0x4(%rbp)
jmp 0x6b11e
jmp 0x6b03f
jmp 0x6af7f
movq -0x38(%rbp), %rdi
callq 0x11c40
leaq 0x13c92(%rip), %rdi     # 0x7ece6
callq 0x10380
movq -0x2068(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x1beef(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x1bede(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x1bed0(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x13c4f(%rip), %rsi     # 0x7ecf4
movl $0x50, %edx
callq 0x10840
movq 0x1beaa(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1be9c(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x1be84(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x1be74(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x1be67(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1be59(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2070, %rsp           # imm = 0x2070
popq %rbp
retq
nopw (%rax,%rax)