#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
#ifdef MEDIA667_P31J
int16_t F7314_FindFirst(char* P4105_pc_, char* P4106_pc_)
{
        int16_t L4638_i_;


        asm     push    ds
        asm     push    si
        asm     lds     dx, P4105_pc_
        asm     mov     ah, 4Eh
        asm     mov     cx, 0
        asm     int     21h             /* DOS - 2+ - FIND FIRST ASCIZ (FINDFIRST) */
        asm                             /* CX = search attributes */
        asm                             /* DS:DX -> ASCIZ filespec */
        asm                             /* (drive, path, and wildcards allowed) */
        asm     mov     ax, 1
        asm     jb      loc_1FD33
        asm     mov     ah, 2Fh
        asm     int     21h             /* DOS - GET DISK TRANSFER AREA ADDRESS */
        asm                             /* Return: ES:BX -> DTA */
        asm     add     bx, 1Eh
        asm     lds     si, P4106_pc_
        asm     mov     byte ptr [si], 0
        loc_1FD25:
        asm     mov     al, es:[bx]
        asm     mov     [si], al
        asm     inc     bx
        asm     inc     si
        asm     cmp     al, 0
        asm     jnz     loc_1FD25
        asm     mov     ax, 0
        loc_1FD33:
        asm     pop     si
        asm     pop     ds
}

int16_t F7315_FindNext(char* P4107_pc_)
{
        int16_t L4639_i_;


        asm     push    ds
        asm     push    si
        asm     mov     ah, 4Fh
        asm     int     21h             /* DOS - 2+ - FIND NEXT ASCIZ (FINDNEXT) */
        asm                             /* [DTA] = data block from */
        asm                             /* last AH = 4Eh/4Fh call */
        asm     mov     ax, 1
        asm     jb      loc_1FD62
        asm     mov     ah, 2Fh
        asm     int     21h             /* DOS - GET DISK TRANSFER AREA ADDRESS */
        asm                             /* Return: ES:BX -> DTA */
        asm     add     bx, 1Eh
        asm     lds     si, P4107_pc_
        asm     mov     byte ptr [si], 0
        loc_1FD54:
        asm     mov     al, es:[bx]
        asm     mov     [si], al
        asm     inc     bx
        asm     inc     si
        asm     cmp     al, 0
        asm     jnz     loc_1FD54
        asm     mov     ax, 0
        loc_1FD62:
        asm     pop     si
        asm     pop     ds
}
#endif

int16_t F7316_GetFileNamesArray(FILE_DESCRIPTOR* P4108_ps_, char* P4109_pc_FileNames, unsigned int16_t P4110_i_FileNameMaximumLength, unsigned int16_t P4111_i_FileMaximumCount, int16_t* P4112_pi_FileCount)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
#ifdef MEDIA692_X31J
        register unsigned char L4648_c_;
        register int16_t L4641_i_;
        register long L4642_;
        unsigned char* L4646_pc_;
        char* L4645_;
        FILE_DESCRIPTOR* L4649_ps_;
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        int16_t L4641_i_;
        int16_t L4642_;
#endif
        int16_t L4640_i_;
        char L4643_ac_[MAX_FILE_NAME_LENGTH];
        char L4644_ac_[MAX_FILE_NAME_LENGTH];
#ifdef MEDIA671_F31E_F31J_P31J
        char L4645_[MAX_FILE_NAME_LENGTH];
        unsigned char* L4646_pc_;
#endif
        REGISTER char* L4647_pc_;
#ifdef MEDIA692_X31J
        int16_t L6063_i_Unreferenced;
        struct FILBUF L5945_;
        BOOLEAN L5946_;
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        unsigned char L4648_c_;
        FILE_DESCRIPTOR* L4649_ps_;
#endif


        *P4112_pi_FileCount = 0;
#ifdef MEDIA692_X31J
        L4641_i_ = 0;
        L5946_ = C0_FALSE;
#endif
        if (F7309_(P4108_ps_, &L4649_ps_) < 0) {
                L4641_i_ = 3;
        } else {
#ifdef MEDIA692_X31J
                if (F2088_(L4649_ps_->DriveLetterOrdinal, 1) != 1) {
                        L4641_i_ = 99;
                } else {
                        L5946_ = C1_TRUE;
#endif
                        F0088_strcpy(L4643_ac_, L4649_ps_->FileName);
                        L4647_pc_ = L4643_ac_;
                        L4646_pc_ = M774_CAST_PUC(L4647_pc_);
                        while (L4648_c_ = *L4647_pc_) {
                                if (L4648_c_ == '\\') {
                                        L4646_pc_ = M774_CAST_PUC(L4647_pc_);
                                }
                                L4647_pc_++;
                        }
                        if (L4646_pc_[1] == '\0') {
                                L4641_i_ = 3;
                        } else {
                                *L4646_pc_++ = '\0';
                                F0088_strcpy(L4644_ac_, M772_CAST_PC(L4646_pc_));
                                F0086_strcat(L4643_ac_, "\\*.*");
                                T7316001: /* ANOMALY_FMT Unwanted optimization */
                                L4640_i_ = 0;
                                L4647_pc_ = P4109_pc_FileNames;
#ifdef MEDIA692_X31J
                                asm { /* F7314_FindFirst */
                                                move.w  #32,-(sp)
                                                pea     L4643_ac_(a6)
                                                pea     L5945_(a6)
                                                dc.w    0xFF4E  /* DOS CALL FILES */
                                                lea     0xA(sp),sp
                                                move.l  d0,d5
                                                bpl.s   @Tloc_DE4C
                                                bra.w   @Tloc_DEC4
                                        @Tloc_DE4C:
                                }
                                L4645_ = &L5945_.name[2];
                                while ((L4642_ >= 0) && (L4640_i_ < P4111_i_FileMaximumCount)) {
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                                L4642_ = F7314_FindFirst(L4643_ac_, L4645_);
                                while ((L4642_ == 0) && (L4640_i_ < P4111_i_FileMaximumCount)) {
#endif
                                        if (F7102_DoesFileNameMatchPattern(L4645_, L4644_ac_)) {
                                                if (F0090_strlen(L4645_) + 1 > P4110_i_FileNameMaximumLength) {
                                                        *(L4645_ + P4110_i_FileNameMaximumLength - 1) = '\0';
                                                }
                                                F0088_strcpy(L4647_pc_, L4645_);
                                                L4647_pc_ += P4110_i_FileNameMaximumLength;
                                                L4640_i_++;
                                        }
#ifdef MEDIA692_X31J
                                        asm { /* F7315_FindNext */
                                                pea     L5945_(a6)
                                                dc.w    0xFF4F  /* DOS CALL NFILES */
                                                addq.l  #4,sp
                                                move.l  d0,L4642_
                                        }
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                                        L4642_ = F7315_FindNext(L4645_);
#endif
                                }
                                *P4112_pi_FileCount = L4640_i_;
#ifdef MEDIA671_F31E_F31J_P31J
                                L4641_i_ = 0;
#endif
                        }
#ifdef MEDIA692_X31J
                }
        }
        asm {
                @Tloc_DEC4:
        }
        if (L5946_) {
                F2089_(L4649_ps_->DriveLetterOrdinal);
#endif
        }
        return L4641_i_;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_25_(P4108_ps_, P4109_pc_FileNames, P4110_i_FileNameMaximumLength, P4111_i_FileMaximumCount, P4112_pi_FileCount);
#endif
}
#endif
