// File: /workspace/github_cpp_makefile_star2_O1/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 $0x2038, %rsp           # imm = 0x2038
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, -0x30(%rbp)
leaq 0xe079(%rip), %rdx      # 0x3cf99
xorl %ebx, %ebx
leaq -0x2060(%rbp), %r13
movl $0x1000, %esi           # imm = 0x1000
movq %r13, %rdi
movq %r14, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0xb130
leaq 0xd4e2(%rip), %rsi      # 0x3c427
movq %r13, %rdi
callq 0xace0
testq %rax, %rax
je 0x2ef72
movq %rax, %r13
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
movq %r14, %rsi
callq 0xa530
movq %r13, %rdi
callq 0xaa80
jmp 0x2f08a
movq %r15, -0x38(%rbp)
movq %r14, %r15
movq %r14, %rdi
callq 0xafa0
testq %rax, %rax
je 0x2f02f
movq %rax, %r13
movq %rax, %rdi
callq 0xb050
testq %rax, %rax
movq %r12, -0x40(%rbp)
movq -0x38(%rbp), %r12
je 0x2f027
movq %rax, %rbx
cmpb $0x4, 0x12(%rbx)
jne 0x2f017
addq $0x13, %rbx
movq %rbx, %rdi
leaq 0xdff0(%rip), %rsi      # 0x3cfad
callq 0xaeb0
testl %eax, %eax
je 0x2f017
movq %rbx, %rdi
leaq 0xdb6b(%rip), %rsi      # 0x3cb3b
callq 0xaeb0
testl %eax, %eax
je 0x2f017
movl $0x1000, %esi           # imm = 0x1000
leaq -0x1050(%rbp), %r14
movq %r14, %rdi
leaq 0xdfaa(%rip), %rdx      # 0x3cf99
movq %r15, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0xb130
movq -0x30(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq -0x40(%rbp), %rcx
callq 0xb3f0
testl %eax, %eax
je 0x2f09e
movq %r13, %rdi
callq 0xb050
movq %rax, %rbx
testq %rax, %rax
jne 0x2efa9
movq %r13, %rdi
callq 0xb150
leaq 0xdf69(%rip), %rdi      # 0x3cf9f
callq 0xa1f0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x14f10(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0xdd9c(%rip), %rsi      # 0x3ce04
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %ebx
movl %ebx, %eax
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0xb150
xorl %ebx, %ebx
jmp 0x2f08a