// File: /workspace/github_c_makefile_star2_O2/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, %rbx
testq %rdx, %rdx
movq %rsi, 0x20(%rsp)
je 0x11373
cmpb $0x2f, (%rax)
jne 0x11387
leaq 0x30(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
movq %rax, %rsi
callq 0xd0b0
jmp 0x113a9
movq %rdx, %rcx
leaq 0x1951e(%rip), %rdx     # 0x2a8af
leaq 0x30(%rsp), %rdi
pushq $0x2f
popq %r8
movl $0x400, %esi            # imm = 0x400
movq %rax, %r9
xorl %eax, %eax
callq 0xd260
leaq 0x30(%rsp), %r13
pushq $0x2f
popq %rsi
movq %r13, %rdi
callq 0xd270
testq %rax, %rax
movq %rax, 0x28(%rsp)
je 0x113f1
movq %rax, %r14
subq %r13, %r14
leaq 0x1(%r14), %rbp
leaq 0x3(%r14), %rdi
callq 0xd4c0
movq %rax, %r15
movq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xd0b0
movw $0x2e, 0x1(%r15,%r14)
jmp 0x11400
leaq 0x18e72(%rip), %rdi     # 0x2a26a
callq 0xd640
movq %rax, %r15
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x102dc
xorl %r14d, %r14d
movq 0x8(%rsp), %r13
cmpq %r13, %r14
jge 0x11481
movq 0x18(%rsp), %rax
cmpb $0x1, (%rax,%r14)
jne 0x1147c
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rbp
movl $0x400, %esi            # imm = 0x400
movq %rbp, %rdi
callq 0xd2c0
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x1147c
movq %rax, %r13
movq %rax, %rsi
addq $0x2, %rsi
movq %rbp, %rdi
callq 0xd520
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rax
movb $0x2f, (%rax,%r13)
movq 0x10(%rsp), %rax
movq (%rax,%r14,8), %rax
movb $0x0, 0x1(%rax,%r13)
incq %r14
jmp 0x11410
movq %r15, (%rsp)
movq 0x10(%rsp), %rbp
cmpq %r13, 0x8(%rbx)
jne 0x114c4
xorl %r14d, %r14d
testq %r13, %r13
movl $0x0, %r12d
cmovgq %r13, %r12
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x114d4
movq (%rbp,%r15,8), %rdi
movq (%rbx), %rax
movq (%rax,%r14), %rsi
callq 0xd390
incq %r15
addq $0x18, %r14
testl %eax, %eax
je 0x114a3
movq %rbx, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x18d58
leaq 0x8(%rsp), %rdi
callq 0x1039b
movq 0x28(%rsp), %rsi
testq %rsi, %rsi
je 0x114f0
incq %rsi
movq %rbx, %rdi
jmp 0x114f8
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x18e97
movq (%rsp), %rdi
callq 0xd090
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq