// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce_commands.c
// Function: find_files_in_directory_recursively
CeStrNode_t* find_files_in_directory_recursively(const char* directory, CeStrNode_t* node, char** ignore_dirs,
                                                 int* ignore_dir_lens, uint64_t ignore_dir_count){
     char* path = ce_strndup((char*)directory, MAX_PATH_LEN);
     CeListDirResult_t list_dir_result = ce_list_dir(path);

     int64_t path_len = strnlen(path, MAX_PATH_LEN);

    // Strip the search characters at the end of the path if they exist.
#if defined(PLATFORM_WINDOWS)
     if(path_len > 0 && path_len < MAX_PATH_LEN){
         if(path[path_len - 1] == CE_CURRENT_DIR_SEARCH){
             path[path_len - 1] = 0;
             path_len--;
         }
         if(path_len > 0 && path[path_len - 1] == CE_PATH_SEPARATOR){
             path[path_len - 1] = 0;
             path_len--;
         }
     }
#else
     if(path_len > 2){
         if(path[path_len - 1] == CE_CURRENT_DIR_SEARCH){
             path[path_len - 1] = 0;
             path_len--;
         }
         if(path_len > 0 && path[path_len - 1] == CE_PATH_SEPARATOR){
             path[path_len - 1] = 0;
             path_len--;
         }
     }

#endif

     bool path_is_current_dir = false;
#if defined(PLATFORM_WINDOWS)
     path_is_current_dir = path_len == 2 &&
                           path[0] == '.' &&
                           path[1] == '\\';
#else
     path_is_current_dir = path_len == 1 &&
                           path[0] == '.';
#endif


     char full_path[MAX_PATH_LEN];
     for(int64_t i = 0; i < list_dir_result.count; i++){
          if(strcmp(list_dir_result.filenames[i], ".") == 0 ||
             strcmp(list_dir_result.filenames[i], "..") == 0){
              continue;
          }
          int full_path_len = 0;
          if (path_is_current_dir){
              full_path_len = snprintf(full_path, MAX_PATH_LEN, "%s", list_dir_result.filenames[i]);
          }else{
              full_path_len = snprintf(full_path, MAX_PATH_LEN, "%s%c%s", path,
                                       CE_PATH_SEPARATOR, list_dir_result.filenames[i]);
          }
          if(list_dir_result.is_directories[i] && full_path_len < (MAX_PATH_LEN - 3)){
               bool ignore_dir = false;
               for(uint64_t j = 0; j < ignore_dir_count; j++){
                    if(full_path_len >= ignore_dir_lens[j] &&
                       strcmp(full_path + full_path_len - ignore_dir_lens[j], ignore_dirs[j]) == 0){
                        ignore_dir = true;
                        break;
                    }
               }
               if(ignore_dir) continue;
               full_path[full_path_len] = CE_PATH_SEPARATOR;
               full_path[full_path_len + 1] = CE_CURRENT_DIR_SEARCH;
               full_path[full_path_len + 2] = 0;
               node = find_files_in_directory_recursively(full_path, node, ignore_dirs,
                                                          ignore_dir_lens, ignore_dir_count);
          }else{
               CeStrNode_t* new_node = malloc(sizeof(*new_node));
               new_node->string = strdup(full_path);
               new_node->next = NULL;
               node->next = new_node;
               node = new_node;
          }
     }
     ce_free_list_dir_result(&list_dir_result);
     free(path);

     return node;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %r8, %r14
movq %rcx, %r15
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movl $0x400, %esi            # imm = 0x400
callq 0xf56b
movq %rax, %r12
leaq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x102dc
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
callq 0xd2c0
cmpq $0x3, %rax
jl 0x167df
movb -0x1(%r12,%rax), %cl
cmpb $0x2e, %cl
jne 0x167d1
movb $0x0, -0x1(%r12,%rax)
movb -0x2(%r12,%rax), %cl
decq %rax
cmpb $0x2f, %cl
jne 0x167f3
movb $0x0, -0x1(%r12,%rax)
decq %rax
cmpq $0x1, %rax
jne 0x167f3
cmpb $0x2e, (%r12)
sete %al
movl %eax, 0x4(%rsp)
jmp 0x167fb
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movq %r12, 0x8(%rsp)
cmpq 0x28(%rsp), %rbp
jge 0x1693c
movq 0x30(%rsp), %rax
movq (%rax,%rbp,8), %r9
cmpb $0x2e, (%r9)
jne 0x16839
cmpb $0x0, 0x1(%r9)
je 0x16934
cmpb $0x2e, 0x1(%r9)
jne 0x16839
cmpb $0x0, 0x2(%r9)
je 0x16934
cmpb $0x0, 0x4(%rsp)
je 0x1685d
movl $0x400, %esi            # imm = 0x400
leaq 0x40(%rsp), %rdi
leaq 0x170b5(%rip), %rdx     # 0x2d906
movq %r9, %rcx
xorl %eax, %eax
callq 0xd260
jmp 0x1687c
movl $0x400, %esi            # imm = 0x400
leaq 0x40(%rsp), %rdi
leaq 0x14041(%rip), %rdx     # 0x2a8af
movq %r12, %rcx
pushq $0x2f
popq %r8
xorl %eax, %eax
callq 0xd260
movl %eax, %r13d
cmpl $0x3fc, %eax            # imm = 0x3FC
jg 0x168d3
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax,%rbp)
je 0x168d3
movq %rbx, 0x10(%rsp)
movslq %r13d, %rax
movq %rax, 0x20(%rsp)
leaq (%rsp,%rax), %r12
addq $0x40, %r12
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x168fa
movslq (%r15,%rbx,4), %rax
cmpl %eax, %r13d
jl 0x168ce
movq %r12, %rdi
subq %rax, %rdi
movq 0x18(%rsp), %rax
movq (%rax,%rbx,8), %rsi
callq 0xd390
testl %eax, %eax
je 0x1692a
incq %rbx
jmp 0x168a8
pushq $0x10
popq %rdi
callq 0xd4c0
movq %rax, %r13
leaq 0x40(%rsp), %rdi
callq 0xd640
movq %rax, (%r13)
andq $0x0, 0x8(%r13)
movq %r13, 0x8(%rbx)
movq %r13, %rbx
jmp 0x16934
movb $0x2f, (%r12)
leaq 0x40(%rsp), %rdi
movq 0x20(%rsp), %rax
movw $0x2e, 0x1(%rax,%rdi)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x1676d
movq %rax, %rbx
jmp 0x1692f
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %r12
incq %rbp
jmp 0x16802
leaq 0x28(%rsp), %rdi
callq 0x1039b
movq %r12, %rdi
callq 0xd090
movq %rbx, %rax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq