// File: /workspace/github_c_makefile_star2_O0/kobolt[P]curses-collection/difftree/tree.c
// Function: diff_tree_compare_dir
void diff_tree_compare_dir(char *path1, char *path2, diff_node_t *current)
{
  DIR *dh;
  struct dirent *entry;
  struct stat st1, st2;
  char fullpath1[PATH_MAX], fullpath2[PATH_MAX];
  diff_node_t *subnode;

  dh = opendir(path1);
  if (dh == NULL) {
    fprintf(stderr, "Warning: Unable to open directory: %s\n", path1);
    return;
  }

  while ((entry = readdir(dh))) {
    if (entry->d_name[0] == '.')
      continue; /* Ignore files with leading dot. */

    snprintf(fullpath1, PATH_MAX, "%s/%s", path1, entry->d_name);
    snprintf(fullpath2, PATH_MAX, "%s/%s", path2, entry->d_name);

    if (stat(fullpath1, &st1) == -1) {
      fprintf(stderr, "Warning: Unable to stat() path: %s\n", fullpath1);
      continue;
    }

    if (S_ISDIR(st1.st_mode)) {
      if (stat(fullpath2, &st2) == -1) {
        subnode = diff_node_add(current, entry->d_name, DIFF_TYPE_DIR_ADDED);
        diff_node_parents_differ(current);
        diff_tree_added_dir(fullpath1, subnode);
      } else {
        if (S_ISDIR(st2.st_mode)) {
          subnode = diff_node_add(current, entry->d_name, DIFF_TYPE_DIR_EQUAL);
          diff_tree_compare_dir(fullpath1, fullpath2, subnode);
        } else {
          subnode = diff_node_add(current, entry->d_name, DIFF_TYPE_DIR_ADDED);
          diff_node_parents_differ(current);
          diff_tree_added_dir(fullpath1, subnode);
        }
      }
      
    } else if (S_ISREG(st1.st_mode)) {
      if (stat(fullpath2, &st2) == -1) {
        diff_node_add(current, entry->d_name, DIFF_TYPE_FILE_ADDED);
        diff_node_parents_differ(current);
      } else {
        if (S_ISREG(st2.st_mode)) {
          if (st1.st_size == st2.st_size) {
            if (diff_tree_compare_file(fullpath1, fullpath2)) {
              diff_node_add(current, entry->d_name, DIFF_TYPE_FILE_DIFFERS);
              diff_node_parents_differ(current);
            } else {
              diff_node_add(current, entry->d_name, DIFF_TYPE_FILE_EQUAL);
            }
          } else {
            diff_node_add(current, entry->d_name, DIFF_TYPE_FILE_DIFFERS);
            diff_node_parents_differ(current);
          }
        } else {
          diff_node_add(current, entry->d_name, DIFF_TYPE_FILE_ADDED);
          diff_node_parents_differ(current);
        }
      }
    }
  }
  closedir(dh);

  dh = opendir(path2);
  if (dh == NULL) {
    fprintf(stderr, "Warning: Unable to open directory: %s\n", path2);
    return;
  }

  while ((entry = readdir(dh))) {
    if (entry->d_name[0] == '.')
      continue; /* Ignore files with leading dot. */

    snprintf(fullpath1, PATH_MAX, "%s/%s", path1, entry->d_name);
    snprintf(fullpath2, PATH_MAX, "%s/%s", path2, entry->d_name);

    if (stat(fullpath2, &st2) == -1) {
      fprintf(stderr, "Warning: Unable to stat() path: %s\n", fullpath2);
      continue;
    }

    if (S_ISDIR(st2.st_mode)) {
      if (stat(fullpath1, &st1) == -1) {
        subnode = diff_node_add(current, entry->d_name, DIFF_TYPE_DIR_MISSING);
        diff_node_parents_differ(current);
        diff_tree_missing_dir(fullpath2, subnode);
      } else {
        if (! S_ISDIR(st1.st_mode)) {
          subnode = diff_node_add(current, entry->d_name, DIFF_TYPE_DIR_MISSING);
          diff_node_parents_differ(current);
          diff_tree_missing_dir(fullpath2, subnode);
        }
      }
      
    } else if (S_ISREG(st2.st_mode)) {
      if (stat(fullpath1, &st1) == -1) {
        diff_node_add(current, entry->d_name, DIFF_TYPE_FILE_MISSING);
        diff_node_parents_differ(current);
      } else {
        if (! S_ISREG(st1.st_mode)) {
          diff_node_add(current, entry->d_name, DIFF_TYPE_FILE_MISSING);
          diff_node_parents_differ(current);
        }
      }
    }
  }
  closedir(dh);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2160, %rsp           # imm = 0x2160
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20e0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x298c
movq 0x4686(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x26b7(%rip), %rsi      # 0x5037
movb $0x0, %al
callq 0x21d0
jmp 0x2e80
jmp 0x298e
movq -0x20(%rbp), %rdi
callq 0x21f0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x2c47
movq -0x28(%rbp), %rax
movsbl 0x13(%rax), %eax
cmpl $0x2e, %eax
jne 0x29b4
jmp 0x298e
leaq -0x1150(%rbp), %rdi
movq -0x8(%rbp), %rcx
movq -0x28(%rbp), %r8
addq $0x13, %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x2651(%rip), %rdx      # 0x5024
movb $0x0, %al
callq 0x2130
leaq -0x2150(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %r8
addq $0x13, %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x262b(%rip), %rdx      # 0x5024
movb $0x0, %al
callq 0x2130
leaq -0x1150(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x21e0
cmpl $-0x1, %eax
jne 0x2a3c
movq 0x45d9(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq -0x1150(%rbp), %rdx
leaq 0x262e(%rip), %rsi      # 0x505e
movb $0x0, %al
callq 0x21d0
jmp 0x298e
movl -0xa0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x2b33
leaq -0x2150(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x21e0
cmpl $-0x1, %eax
jne 0x2aa8
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x7, %edx
callq 0x2490
movq %rax, -0x2158(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27d0
leaq -0x1150(%rbp), %rdi
movq -0x2158(%rbp), %rsi
callq 0x2e90
jmp 0x2b2e
movl -0x130(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x2af3
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x5, %edx
callq 0x2490
movq %rax, -0x2158(%rbp)
leaq -0x1150(%rbp), %rdi
leaq -0x2150(%rbp), %rsi
movq -0x2158(%rbp), %rdx
callq 0x2940
jmp 0x2b2c
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x7, %edx
callq 0x2490
movq %rax, -0x2158(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27d0
leaq -0x1150(%rbp), %rdi
movq -0x2158(%rbp), %rsi
callq 0x2e90
jmp 0x2b2e
jmp 0x2c42
movl -0xa0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x2c40
leaq -0x2150(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x21e0
cmpl $-0x1, %eax
jne 0x2b85
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x3, %edx
callq 0x2490
movq -0x18(%rbp), %rdi
callq 0x27d0
jmp 0x2c3e
movl -0x130(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x2c1d
movq -0x88(%rbp), %rax
cmpq -0x118(%rbp), %rax
jne 0x2bfc
leaq -0x1150(%rbp), %rdi
leaq -0x2150(%rbp), %rsi
callq 0x2ff0
cmpl $0x0, %eax
je 0x2be4
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x2, %edx
callq 0x2490
movq -0x18(%rbp), %rdi
callq 0x27d0
jmp 0x2bfa
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x1, %edx
callq 0x2490
jmp 0x2c1b
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x2, %edx
callq 0x2490
movq -0x18(%rbp), %rdi
callq 0x27d0
jmp 0x2c3c
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x3, %edx
callq 0x2490
movq -0x18(%rbp), %rdi
callq 0x27d0
jmp 0x2c3e
jmp 0x2c40
jmp 0x2c42
jmp 0x298e
movq -0x20(%rbp), %rdi
callq 0x2190
movq -0x10(%rbp), %rdi
callq 0x20e0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2c85
movq 0x438d(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x23be(%rip), %rsi      # 0x5037
movb $0x0, %al
callq 0x21d0
jmp 0x2e80
jmp 0x2c87
movq -0x20(%rbp), %rdi
callq 0x21f0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x2e77
movq -0x28(%rbp), %rax
movsbl 0x13(%rax), %eax
cmpl $0x2e, %eax
jne 0x2cad
jmp 0x2c87
leaq -0x1150(%rbp), %rdi
movq -0x8(%rbp), %rcx
movq -0x28(%rbp), %r8
addq $0x13, %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x2358(%rip), %rdx      # 0x5024
movb $0x0, %al
callq 0x2130
leaq -0x2150(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %r8
addq $0x13, %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x2332(%rip), %rdx      # 0x5024
movb $0x0, %al
callq 0x2130
leaq -0x2150(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x21e0
cmpl $-0x1, %eax
jne 0x2d35
movq 0x42e0(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq -0x2150(%rbp), %rdx
leaq 0x2335(%rip), %rsi      # 0x505e
movb $0x0, %al
callq 0x21d0
jmp 0x2c87
movl -0x130(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x2df0
leaq -0x1150(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x21e0
cmpl $-0x1, %eax
jne 0x2d9e
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x8, %edx
callq 0x2490
movq %rax, -0x2158(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27d0
leaq -0x2150(%rbp), %rdi
movq -0x2158(%rbp), %rsi
callq 0x30f0
jmp 0x2deb
movl -0xa0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
je 0x2de9
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x8, %edx
callq 0x2490
movq %rax, -0x2158(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27d0
leaq -0x2150(%rbp), %rdi
movq -0x2158(%rbp), %rsi
callq 0x30f0
jmp 0x2deb
jmp 0x2e72
movl -0x130(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x2e70
leaq -0x1150(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x21e0
cmpl $-0x1, %eax
jne 0x2e3b
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x4, %edx
callq 0x2490
movq -0x18(%rbp), %rdi
callq 0x27d0
jmp 0x2e6e
movl -0xa0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
je 0x2e6c
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x13, %rsi
movl $0x4, %edx
callq 0x2490
movq -0x18(%rbp), %rdi
callq 0x27d0
jmp 0x2e6e
jmp 0x2e70
jmp 0x2e72
jmp 0x2c87
movq -0x20(%rbp), %rdi
callq 0x2190
addq $0x2160, %rsp           # imm = 0x2160
popq %rbp
retq
nopl (%rax)