// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq %rdx, 0x20(%rsp)
movq %rsi, %rbx
movl $0x400, %esi            # imm = 0x400
callq 0xf886
movq %rax, %r13
leaq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x1077f
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
callq 0xd2c0
cmpq $0x3, %rax
jl 0x171e0
movb -0x1(%r13,%rax), %cl
cmpb $0x2e, %cl
jne 0x171d2
movb $0x0, -0x1(%r13,%rax)
movb -0x2(%r13,%rax), %cl
decq %rax
cmpb $0x2f, %cl
jne 0x171f4
movb $0x0, -0x1(%r13,%rax)
decq %rax
cmpq $0x1, %rax
jne 0x171f4
cmpb $0x2e, (%r13)
sete %al
movl %eax, 0x4(%rsp)
jmp 0x171fc
movl $0x0, 0x4(%rsp)
cmpq $0x0, 0x28(%rsp)
jle 0x17356
xorl %ebp, %ebp
movq %r13, 0x8(%rsp)
movq 0x30(%rsp), %rax
movq (%rax,%rbp,8), %r9
cmpb $0x2e, (%r9)
jne 0x1723b
cmpb $0x0, 0x1(%r9)
je 0x17348
cmpb $0x2e, 0x1(%r9)
jne 0x1723b
cmpb $0x0, 0x2(%r9)
je 0x17348
cmpb $0x0, 0x4(%rsp)
je 0x1725f
movl $0x400, %esi            # imm = 0x400
leaq 0x40(%rsp), %rdi
leaq 0x19713(%rip), %rdx     # 0x30966
movq %r9, %rcx
xorl %eax, %eax
callq 0xd260
jmp 0x17280
movl $0x400, %esi            # imm = 0x400
leaq 0x40(%rsp), %rdi
leaq 0x1663f(%rip), %rdx     # 0x2d8af
movq %r13, %rcx
movl $0x2f, %r8d
xorl %eax, %eax
callq 0xd260
movl %eax, %r15d
cmpl $0x3fc, %eax            # imm = 0x3FC
jg 0x17313
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax,%rbp)
je 0x17313
movq %rbx, 0x10(%rsp)
movslq %r15d, %rax
movq %rax, 0x18(%rsp)
testq %r14, %r14
je 0x172e3
movq 0x18(%rsp), %rax
leaq (%rsp,%rax), %r13
addq $0x40, %r13
xorl %ebx, %ebx
movslq (%r12,%rbx,4), %rax
cmpl %eax, %r15d
jl 0x172db
movq %r13, %rdi
subq %rax, %rdi
movq 0x20(%rsp), %rax
movq (%rax,%rbx,8), %rsi
callq 0xd390
testl %eax, %eax
je 0x1733e
incq %rbx
cmpq %rbx, %r14
jne 0x172ba
movq 0x18(%rsp), %rax
movb $0x2f, 0x40(%rsp,%rax)
leaq 0x40(%rsp), %rdi
movw $0x2e, 0x1(%rax,%rdi)
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rcx
movq %r14, %r8
callq 0x1716e
movq %rax, %rbx
jmp 0x17343
movl $0x10, %edi
callq 0xd4c0
movq %rax, %r15
leaq 0x40(%rsp), %rdi
callq 0xd640
movq %rax, (%r15)
movq $0x0, 0x8(%r15)
movq %r15, 0x8(%rbx)
movq %r15, %rbx
jmp 0x17348
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %r13
incq %rbp
cmpq 0x28(%rsp), %rbp
jl 0x1720f
leaq 0x28(%rsp), %rdi
callq 0x1086a
movq %r13, %rdi
callq 0xd090
movq %rbx, %rax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq