// File: /workspace/github_c_makefile_star2_O1/justy989[P]ce/ce_app.c
// Function: complete_files
void complete_files(CeComplete_t* complete, const char* line, const char* base_directory){
     char full_path[MAX_PATH_LEN];
     if(base_directory && *line != CE_PATH_SEPARATOR){
          snprintf(full_path, MAX_PATH_LEN, "%s%c%s", base_directory, CE_PATH_SEPARATOR, line);
     }else{
          strncpy(full_path, line, MAX_PATH_LEN);
     }

     // figure out the directory to complete
     const char* last_slash = strrchr(full_path, CE_PATH_SEPARATOR);
     char* directory = NULL;

     if(last_slash){
          int64_t parent_path_len = (last_slash - full_path) + 1;
          directory = malloc(parent_path_len + 2);
          strncpy(directory, full_path, parent_path_len);
          directory[parent_path_len] = CE_CURRENT_DIR_SEARCH;
          directory[parent_path_len + 1] = 0;
     }else{
          directory = strdup(CE_CURRENT_DIR_SEARCH_STR);
     }

     CeListDirResult_t list_dir_result = ce_list_dir(directory);

     // Post process to add a slash to the end of directories.
     for(int64_t i = 0; i < list_dir_result.count; i++){
          if(!list_dir_result.is_directories[i]){
               continue;
          }
          int64_t name_len = strnlen(list_dir_result.filenames[i], MAX_PATH_LEN);
          if (name_len >= MAX_PATH_LEN) {
               continue;
          }
          list_dir_result.filenames[i] = realloc(list_dir_result.filenames[i], name_len + 2);
          list_dir_result.filenames[i][name_len] = CE_PATH_SEPARATOR;
          list_dir_result.filenames[i][name_len + 1] = 0;
     }

     // check for exact match
     bool exact_match = true;
     if(complete->count != list_dir_result.count){
          exact_match = false;
     }else{
          for(int64_t i = 0; i < list_dir_result.count; i++){
               if(strcmp(list_dir_result.filenames[i], complete->elements[i].string) != 0){
                    exact_match = false;
                    break;
               }
          }
     }

     if(!exact_match){
          ce_complete_init(complete, (const char**)(list_dir_result.filenames), NULL, list_dir_result.count);
     }

     ce_free_list_dir_result(&list_dir_result);

     if(last_slash){
          ce_complete_match(complete, last_slash + 1);
     }else{
          ce_complete_match(complete, line);
     }

     free(directory);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rsi, %rax
movq %rdi, 0x8(%rsp)
testq %rdx, %rdx
movq %rsi, 0x28(%rsp)
je 0x11c89
cmpb $0x2f, (%rax)
jne 0x11c9d
leaq 0x30(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
movq %rax, %rsi
callq 0xd0b0
jmp 0x11cc1
movq %rdx, %rcx
leaq 0x1cc06(%rip), %rdx     # 0x2e8ad
leaq 0x30(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movl $0x2f, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0xd260
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movl $0x2f, %esi
callq 0xd270
movq %rax, %r15
testq %rax, %rax
je 0x11d09
movq %r15, %rbx
subq %r13, %rbx
leaq 0x1(%rbx), %rbp
leaq 0x3(%rbx), %rdi
callq 0xd4c0
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xd0b0
movw $0x2e, 0x1(%r12,%rbx)
jmp 0x11d18
leaq 0x1e674(%rip), %rdi     # 0x30384
callq 0xd640
movq %rax, %r12
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x1090a
movq (%r13), %r13
testq %r13, %r13
jle 0x11da3
xorl %r14d, %r14d
movq 0x20(%rsp), %rax
cmpb $0x1, (%rax,%r14)
jne 0x11d96
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rbp
movl $0x400, %esi            # imm = 0x400
movq %rbp, %rdi
callq 0xd2c0
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x11d96
movq %rax, %r13
movq %rax, %rsi
addq $0x2, %rsi
movq %rbp, %rdi
callq 0xd520
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rax
movb $0x2f, (%rax,%r13)
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rax
movb $0x0, 0x1(%rax,%r13)
incq %r14
movq 0x10(%rsp), %r13
cmpq %r13, %r14
jl 0x11d34
movq 0x8(%rsp), %rax
cmpq %r13, 0x8(%rax)
jne 0x11de1
testq %r13, %r13
jle 0x11df5
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %rax
movq (%rax), %rbp
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
movq (%rbp), %rsi
callq 0xd390
testl %eax, %eax
jne 0x11de1
incq %rbx
addq $0x18, %rbp
cmpq %rbx, %r13
jne 0x11dc2
jmp 0x11df5
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdi
xorl %edx, %edx
movq %r13, %rcx
callq 0x19fd4
leaq 0x10(%rsp), %rdi
callq 0x109f7
testq %r15, %r15
je 0x11e11
incq %r15
movq 0x8(%rsp), %rdi
movq %r15, %rsi
jmp 0x11e1b
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x1a14a
movq %r12, %rdi
callq 0xd090
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq