// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2028, %rsp           # imm = 0x2028
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, -0x30(%rbp)
leaq 0xe979(%rip), %rdx      # 0x39f91
xorl %r13d, %r13d
leaq -0x2050(%rbp), %rbx
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
movq %r15, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0xb130
leaq 0xdde1(%rip), %rsi      # 0x3941f
movq %rbx, %rdi
callq 0xace0
testq %rax, %rax
je 0x2b66b
movq %rax, %rbx
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
movq %r15, %rsi
callq 0xa530
movq %rbx, %rdi
callq 0xaa80
jmp 0x2b772
movq %r14, -0x38(%rbp)
movq -0x30(%rbp), %rbx
movq %r15, %rdi
callq 0xafa0
testq %rax, %rax
je 0x2b721
movq %rax, %r13
movq %rax, %rdi
callq 0xb050
testq %rax, %rax
movq %r12, %r14
movq -0x38(%rbp), %r12
je 0x2b707
cmpb $0x4, 0x12(%rax)
jne 0x2b6fa
cmpb $0x2e, 0x13(%rax)
jne 0x2b6b9
cmpb $0x2e, 0x14(%rax)
jne 0x2b6b3
cmpb $0x0, 0x15(%rax)
je 0x2b6fa
cmpb $0x0, 0x14(%rax)
je 0x2b6fa
addq $0x13, %rax
movl $0x1000, %esi           # imm = 0x1000
leaq -0x1040(%rbp), %rbx
movq %rbx, %rdi
leaq 0xe8be(%rip), %rdx      # 0x39f91
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xb130
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0xb3f0
testl %eax, %eax
je 0x2b787
movq %r13, %rdi
callq 0xb050
testq %rax, %rax
jne 0x2b69b
movq %r13, %rdi
callq 0xb150
leaq 0xe881(%rip), %rdi      # 0x39f97
callq 0xa1f0
movq -0x30(%rbp), %rdi
jmp 0x2b730
leaq 0xe86f(%rip), %rdi      # 0x39f97
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x1581f(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0xe6ad(%rip), %rsi      # 0x39dfc
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r13d
movl %r13d, %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0xb150
xorl %r13d, %r13d
jmp 0x2b772