// File: /workspace/github_c_makefile_star2_O0/justy989[P]ce/ce_commands.c
// Function: command_discover_directory_files
CeCommandStatus_t command_discover_directory_files(CeCommand_t* command, void* user_data){
    CeApp_t* app = user_data;
    CommandContext_t command_context = {};

    if(!get_command_context(app, &command_context)) return CE_COMMAND_NO_ACTION;

    if(command->arg_count <= 0 ||
       command->args[0].type != CE_COMMAND_ARG_STRING){
        return CE_COMMAND_PRINT_HELP;
    }

    char base_directory[MAX_PATH_LEN];
#if defined(PLATFORM_WINDOWS)
    snprintf(base_directory, MAX_PATH_LEN, "%s\\*", command->args[0].string);
#else
    snprintf(base_directory, MAX_PATH_LEN, "%s", command->args[0].string);
#endif

    // setup our ignore dirs
    int ignore_dir_count = (command->arg_count - 1);
    char** ignore_dirs = malloc(sizeof(*ignore_dirs) * ignore_dir_count);
    for(int64_t i = 1; i < command->arg_count; i++){
        // TODO: this imposes a restriction that folders cannot be named numbers like 5
        if(command->args[i].type != CE_COMMAND_ARG_STRING){
            return CE_COMMAND_PRINT_HELP;
        }
        ignore_dirs[i - 1] = strdup(command->args[i].string);
    }

    int* ignore_dir_lens = malloc(sizeof(*ignore_dir_lens) * ignore_dir_count);
    for(int64_t i = 0; i < ignore_dir_count; i++){
        ignore_dir_lens[i] = strlen(ignore_dirs[i]);
    }

    // head is a dummy node that doesn't contain any info, just makes the find_files_in_directory_recursively()
    // interface better
    CeStrNode_t* head = calloc(sizeof(*head), 1);
    find_files_in_directory_recursively(base_directory, head, ignore_dirs, ignore_dir_lens, ignore_dir_count);

    // cleanup our ignore dirs
    for(int64_t i = 0; i < ignore_dir_count; i++){
        free(ignore_dirs[i]);
    }
    free(ignore_dirs);
    free(ignore_dir_lens);

    // Count the paths.
    int64_t filepath_count = 0;
    CeStrNode_t* itr = head;
    while(itr){
        if(itr->string){
            filepath_count++;
        }
        itr = itr->next;
    }

    // Build an array of strings for the paths.
    char** filepaths = malloc(filepath_count * sizeof(filepaths[0]));
    bool* filepaths_already_exists = calloc(filepath_count, sizeof(filepaths_already_exists[0]));

    int64_t filepath_index = 0;
    itr = head;
    while(itr){
        if(itr->string){
            filepaths[filepath_index] = strdup(itr->string);
            filepath_index++;
        }
        CeStrNode_t* node = itr;
        itr = itr->next;
        free(node->string);
        free(node);
    }

    // Sort the filepaths.
    qsort(filepaths,
          filepath_count,
          sizeof(filepaths[0]),
          _strstrcmp);

    // Since both lists are sorted, compare the elements in lock step.
    int64_t matching_filepath_count = 0;
    int64_t discovered_index = 0;
    filepath_index = 0;
    while(filepath_index < filepath_count &&
          discovered_index < app->discovered_filepath_count){
        int rc = strcmp(filepaths[filepath_index],
                        app->discovered_filepaths[discovered_index]);
        if(rc < 0){
            discovered_index++;
        }else if(rc > 0){
            filepath_index++;
        }else{
            filepaths_already_exists[filepath_index] = true;
            matching_filepath_count++;
            filepath_index++;
            discovered_index++;
        }
    }

    int64_t new_filepath_count = filepath_count - matching_filepath_count;
    if(new_filepath_count > 0){
        int64_t new_discovered_filepath_count = app->discovered_filepath_count + new_filepath_count;
        app->discovered_filepaths = realloc(
            app->discovered_filepaths,
            sizeof(*app->discovered_filepaths) * new_discovered_filepath_count);

        discovered_index = app->discovered_filepath_count;
        for(int64_t i = 0; i < filepath_count; i++){
            if(!filepaths_already_exists[i]){
                app->discovered_filepaths[discovered_index] = strdup(filepaths[i]);
                discovered_index++;
            }
        }

        app->discovered_filepath_count = new_discovered_filepath_count;

        // Sort the final list of paths.
        qsort(app->discovered_filepaths,
              app->discovered_filepath_count,
              sizeof(app->discovered_filepaths[0]),
              _strstrcmp);
    }

    for(int64_t i = 0; i < filepath_count; i++){
        free(filepaths[i]);
    }
    free(filepaths);
    free(filepaths_already_exists);

    // setup input and completion
    ce_app_input(app, "Load Discovered File", load_project_file_input_complete_func);
    ce_complete_init(&app->input_complete, (const char**)(app->discovered_filepaths), NULL, app->discovered_filepath_count);
    build_complete_list(app->complete_list_buffer, &app->input_complete);

    return CE_COMMAND_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4e0, %rsp            # imm = 0x4E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xd290
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1c5d0
testb $0x1, %al
jne 0x1e0f8
movl $0x3, -0x4(%rbp)
jmp 0x1e789
movq -0x10(%rbp), %rax
cmpq $0x0, 0x208(%rax)
jle 0x1e116
movq -0x10(%rbp), %rax
movq 0x200(%rax), %rax
cmpl $0x2, (%rax)
je 0x1e122
movl $0x2, -0x4(%rbp)
jmp 0x1e789
leaq -0x430(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x200(%rax), %rax
movq 0x8(%rax), %rcx
movl $0x400, %esi            # imm = 0x400
leaq 0x27a96(%rip), %rdx     # 0x45bda
movb $0x0, %al
callq 0xd250
movq -0x10(%rbp), %rax
movq 0x208(%rax), %rax
subq $0x1, %rax
movl %eax, -0x434(%rbp)
movslq -0x434(%rbp), %rdi
shlq $0x3, %rdi
callq 0xd4a0
movq %rax, -0x440(%rbp)
movq $0x1, -0x448(%rbp)
movq -0x448(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x208(%rcx), %rax
jge 0x1e212
movq -0x10(%rbp), %rax
movq 0x200(%rax), %rax
movq -0x448(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x2, (%rax)
je 0x1e1c0
movl $0x2, -0x4(%rbp)
jmp 0x1e789
movq -0x10(%rbp), %rax
movq 0x200(%rax), %rax
movq -0x448(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0xd620
movq %rax, %rdx
movq -0x440(%rbp), %rax
movq -0x448(%rbp), %rcx
subq $0x1, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x448(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x448(%rbp)
jmp 0x1e182
movslq -0x434(%rbp), %rdi
shlq $0x2, %rdi
callq 0xd4a0
movq %rax, -0x450(%rbp)
movq $0x0, -0x458(%rbp)
movq -0x458(%rbp), %rax
movslq -0x434(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1e285
movq -0x440(%rbp), %rax
movq -0x458(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xd200
movl %eax, %edx
movq -0x450(%rbp), %rax
movq -0x458(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x458(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x458(%rbp)
jmp 0x1e234
movl $0x10, %edi
movl $0x1, %esi
callq 0xd360
movq %rax, -0x460(%rbp)
leaq -0x430(%rbp), %rdi
movq -0x460(%rbp), %rsi
movq -0x440(%rbp), %rdx
movq -0x450(%rbp), %rcx
movslq -0x434(%rbp), %r8
callq 0x1dcf0
movq $0x0, -0x468(%rbp)
movq -0x468(%rbp), %rax
movslq -0x434(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1e30c
movq -0x440(%rbp), %rax
movq -0x468(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xd090
movq -0x468(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x468(%rbp)
jmp 0x1e2ce
movq -0x440(%rbp), %rdi
callq 0xd090
movq -0x450(%rbp), %rdi
callq 0xd090
movq $0x0, -0x470(%rbp)
movq -0x460(%rbp), %rax
movq %rax, -0x478(%rbp)
cmpq $0x0, -0x478(%rbp)
je 0x1e37a
movq -0x478(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1e366
movq -0x470(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x470(%rbp)
movq -0x478(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x478(%rbp)
jmp 0x1e33d
movq -0x470(%rbp), %rdi
shlq $0x3, %rdi
callq 0xd4a0
movq %rax, -0x480(%rbp)
movq -0x470(%rbp), %rdi
movl $0x1, %esi
callq 0xd360
movq %rax, -0x488(%rbp)
movq $0x0, -0x490(%rbp)
movq -0x460(%rbp), %rax
movq %rax, -0x478(%rbp)
cmpq $0x0, -0x478(%rbp)
je 0x1e453
movq -0x478(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1e413
movq -0x478(%rbp), %rax
movq (%rax), %rdi
callq 0xd620
movq %rax, %rdx
movq -0x480(%rbp), %rax
movq -0x490(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x490(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x490(%rbp)
movq -0x478(%rbp), %rax
movq %rax, -0x498(%rbp)
movq -0x478(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x478(%rbp)
movq -0x498(%rbp), %rax
movq (%rax), %rdi
callq 0xd090
movq -0x498(%rbp), %rdi
callq 0xd090
jmp 0x1e3c2
movq -0x480(%rbp), %rdi
movq -0x470(%rbp), %rsi
movl $0x8, %edx
leaq -0x3fd(%rip), %rcx      # 0x1e070
callq 0xd130
movq $0x0, -0x4a0(%rbp)
movq $0x0, -0x4a8(%rbp)
movq $0x0, -0x490(%rbp)
movq -0x490(%rbp), %rcx
xorl %eax, %eax
cmpq -0x470(%rbp), %rcx
movb %al, -0x4d1(%rbp)
jge 0x1e4c6
movq -0x4a8(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x2cb0(%rcx), %rax
setl %al
movb %al, -0x4d1(%rbp)
movb -0x4d1(%rbp), %al
testb $0x1, %al
jne 0x1e4d5
jmp 0x1e591
movq -0x480(%rbp), %rax
movq -0x490(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x20(%rbp), %rax
movq 0x2cb8(%rax), %rax
movq -0x4a8(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0xd370
movl %eax, -0x4ac(%rbp)
cmpl $0x0, -0x4ac(%rbp)
jge 0x1e525
movq -0x4a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4a8(%rbp)
jmp 0x1e58c
cmpl $0x0, -0x4ac(%rbp)
jle 0x1e542
movq -0x490(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x490(%rbp)
jmp 0x1e58a
movq -0x488(%rbp), %rax
movq -0x490(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movq -0x4a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4a0(%rbp)
movq -0x490(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x490(%rbp)
movq -0x4a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4a8(%rbp)
jmp 0x1e58c
jmp 0x1e493
movq -0x470(%rbp), %rax
subq -0x4a0(%rbp), %rax
movq %rax, -0x4b8(%rbp)
cmpq $0x0, -0x4b8(%rbp)
jle 0x1e6c8
movq -0x20(%rbp), %rax
movq 0x2cb0(%rax), %rax
addq -0x4b8(%rbp), %rax
movq %rax, -0x4c0(%rbp)
movq -0x20(%rbp), %rax
movq 0x2cb8(%rax), %rdi
movq -0x4c0(%rbp), %rsi
shlq $0x3, %rsi
callq 0xd500
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x2cb8(%rax)
movq -0x20(%rbp), %rax
movq 0x2cb0(%rax), %rax
movq %rax, -0x4a8(%rbp)
movq $0x0, -0x4c8(%rbp)
movq -0x4c8(%rbp), %rax
cmpq -0x470(%rbp), %rax
jge 0x1e68f
movq -0x488(%rbp), %rax
movq -0x4c8(%rbp), %rcx
testb $0x1, (%rax,%rcx)
jne 0x1e679
movq -0x480(%rbp), %rax
movq -0x4c8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xd620
movq %rax, %rdx
movq -0x20(%rbp), %rax
movq 0x2cb8(%rax), %rax
movq -0x4a8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x4a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4a8(%rbp)
jmp 0x1e67b
movq -0x4c8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4c8(%rbp)
jmp 0x1e613
movq -0x4c0(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x2cb0(%rax)
movq -0x20(%rbp), %rax
movq 0x2cb8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x2cb0(%rax), %rsi
movl $0x8, %edx
leaq -0x653(%rip), %rcx      # 0x1e070
callq 0xd130
movq $0x0, -0x4d0(%rbp)
movq -0x4d0(%rbp), %rax
cmpq -0x470(%rbp), %rax
jge 0x1e70e
movq -0x480(%rbp), %rax
movq -0x4d0(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xd090
movq -0x4d0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4d0(%rbp)
jmp 0x1e6d3
movq -0x480(%rbp), %rdi
callq 0xd090
movq -0x488(%rbp), %rdi
callq 0xd090
movq -0x20(%rbp), %rdi
leaq 0x25bd8(%rip), %rsi     # 0x44309
leaq -0x60e8(%rip), %rdx     # 0x18650
callq 0x15c60
movq -0x20(%rbp), %rdi
addq $0x28a0, %rdi           # imm = 0x28A0
movq -0x20(%rbp), %rax
movq 0x2cb8(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x2cb0(%rax), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x220d0
movq -0x20(%rbp), %rax
movq 0x2860(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x28a0, %rsi           # imm = 0x28A0
callq 0x14d80
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbp
retq
nopw %cs:(%rax,%rax)