// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x14aa4
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x14aa4
leaq -0x420(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %r9
movl $0x400, %esi            # imm = 0x400
leaq 0x2ddcb(%rip), %rdx     # 0x42860
movl $0x2f, %r8d
movb $0x0, %al
callq 0xd250
jmp 0x14ab9
leaq -0x420(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0xd0b0
leaq -0x420(%rbp), %rdi
movl $0x2f, %esi
callq 0xd260
movq %rax, -0x428(%rbp)
movq $0x0, -0x430(%rbp)
cmpq $0x0, -0x428(%rbp)
je 0x14b5a
movq -0x428(%rbp), %rax
leaq -0x420(%rbp), %rcx
subq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x438(%rbp)
movq -0x438(%rbp), %rdi
addq $0x2, %rdi
callq 0xd4a0
movq %rax, -0x430(%rbp)
movq -0x430(%rbp), %rdi
leaq -0x420(%rbp), %rsi
movq -0x438(%rbp), %rdx
callq 0xd0b0
movq -0x430(%rbp), %rax
movq -0x438(%rbp), %rcx
movb $0x2e, (%rax,%rcx)
movq -0x430(%rbp), %rax
movq -0x438(%rbp), %rcx
movb $0x0, 0x1(%rax,%rcx)
jmp 0x14b6d
leaq 0x2f7a6(%rip), %rdi     # 0x44307
callq 0xd620
movq %rax, -0x430(%rbp)
movq -0x430(%rbp), %rsi
leaq -0x450(%rbp), %rdi
callq 0x12a50
movq $0x0, -0x458(%rbp)
movq -0x458(%rbp), %rax
cmpq -0x450(%rbp), %rax
jge 0x14c73
movq -0x440(%rbp), %rax
movq -0x458(%rbp), %rcx
testb $0x1, (%rax,%rcx)
jne 0x14bb8
jmp 0x14c5c
movq -0x448(%rbp), %rax
movq -0x458(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0xd2b0
movq %rax, -0x460(%rbp)
cmpq $0x400, -0x460(%rbp) # imm = 0x400
jl 0x14bea
jmp 0x14c5c
movq -0x448(%rbp), %rax
movq -0x458(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x460(%rbp), %rsi
addq $0x2, %rsi
callq 0xd500
movq %rax, %rdx
movq -0x448(%rbp), %rax
movq -0x458(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x448(%rbp), %rax
movq -0x458(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x460(%rbp), %rcx
movb $0x2f, (%rax,%rcx)
movq -0x448(%rbp), %rax
movq -0x458(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x460(%rbp), %rcx
movb $0x0, 0x1(%rax,%rcx)
movq -0x458(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x458(%rbp)
jmp 0x14b8b
movb $0x1, -0x461(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x450(%rbp), %rax
je 0x14c94
movb $0x0, -0x461(%rbp)
jmp 0x14d01
movq $0x0, -0x470(%rbp)
movq -0x470(%rbp), %rax
cmpq -0x450(%rbp), %rax
jge 0x14cff
movq -0x448(%rbp), %rax
movq -0x470(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x470(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0xd370
cmpl $0x0, %eax
je 0x14ce9
movb $0x0, -0x461(%rbp)
jmp 0x14cff
jmp 0x14ceb
movq -0x470(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x470(%rbp)
jmp 0x14c9f
jmp 0x14d01
testb $0x1, -0x461(%rbp)
jne 0x14d25
movq -0x8(%rbp), %rdi
movq -0x448(%rbp), %rsi
movq -0x450(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x220d0
leaq -0x450(%rbp), %rdi
callq 0x12b90
cmpq $0x0, -0x428(%rbp)
je 0x14d51
movq -0x8(%rbp), %rdi
movq -0x428(%rbp), %rsi
addq $0x1, %rsi
callq 0x222f0
jmp 0x14d5e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x222f0
movq -0x430(%rbp), %rdi
callq 0xd090
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
nopw %cs:(%rax,%rax)