// File: /workspace/github_c_makefile_star2_O3/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 0x11a74
cmpb $0x2f, (%rax)
jne 0x11a88
leaq 0x30(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
movq %rax, %rsi
callq 0xd0b0
jmp 0x11aac
movq %rdx, %rcx
leaq 0x1be1d(%rip), %rdx     # 0x2d8af
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 0x11af4
movq %r15, %rbx
subq %r13, %rbx
leaq 0x1(%rbx), %r14
leaq 0x3(%rbx), %rdi
callq 0xd4c0
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xd0b0
movw $0x2e, 0x1(%r12,%rbx)
jmp 0x11b03
leaq 0x1b76f(%rip), %rdi     # 0x2d26a
callq 0xd640
movq %rax, %r12
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x1077f
movq (%r14), %r13
testq %r13, %r13
jle 0x11b89
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
cmpb $0x1, (%rax,%rbx)
jne 0x11b81
movq 0x18(%rsp), %rax
movq (%rax,%rbx,8), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
callq 0xd2c0
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x11b81
movq %rax, %rbp
movq %rax, %rsi
addq $0x2, %rsi
movq %r14, %rdi
callq 0xd520
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x18(%rsp), %rax
movq (%rax,%rbx,8), %rax
movb $0x2f, (%rax,%rbp)
movq 0x18(%rsp), %rax
movq (%rax,%rbx,8), %rax
movb $0x0, 0x1(%rax,%rbp)
movq 0x10(%rsp), %r13
incq %rbx
cmpq %r13, %rbx
jl 0x11b1d
movq 0x8(%rsp), %rax
cmpq %r13, 0x8(%rax)
jne 0x11bc8
testq %r13, %r13
jle 0x11bdf
movq 0x18(%rsp), %rbp
movq 0x8(%rsp), %rax
movq (%rax), %rbx
xorl %r14d, %r14d
movq (%rbp,%r14,8), %rdi
movq (%rbx), %rsi
callq 0xd390
testl %eax, %eax
jne 0x11bcd
incq %r14
addq $0x18, %rbx
cmpq %r14, %r13
jne 0x11ba9
jmp 0x11bdf
movq 0x18(%rsp), %rbp
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x1994c
leaq 0x10(%rsp), %rdi
callq 0x1086a
testq %r15, %r15
je 0x11bfb
incq %r15
movq 0x8(%rsp), %rdi
movq %r15, %rsi
jmp 0x11c05
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x19fcd
movq %r12, %rdi
callq 0xd090
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq