// File: /workspace/github_c_makefile_star2_O0/tditlu[P]shadetabler/src/cwalk/cwalk.c
// Function: cwk_path_get_intersection
size_t cwk_path_get_intersection(const char *path_base, const char *path_other)
{
  bool absolute;
  size_t base_root_length, other_root_length;
  const char *end;
  const char *paths_base[2], *paths_other[2];
  struct cwk_segment_joined base, other;

  // We first compare the two roots. We just return zero if they are not equal.
  // This will also happen to return zero if the paths are mixed relative and
  // absolute.
  cwk_path_get_root(path_base, &base_root_length);
  cwk_path_get_root(path_other, &other_root_length);
  if (!cwk_path_is_string_equal(path_base, path_other, base_root_length)) {
    return 0;
  }

  // Configure our paths. We just have a single path in here for now.
  paths_base[0] = path_base;
  paths_base[1] = NULL;
  paths_other[0] = path_other;
  paths_other[1] = NULL;

  // So we get the first segment of both paths. If one of those paths don't have
  // any segment, we will return 0.
  if (!cwk_path_get_first_segment_joined(paths_base, &base) ||
      !cwk_path_get_first_segment_joined(paths_other, &other)) {
    return base_root_length;
  }

  // We now determine whether the path is absolute or not. This is required
  // because if will ignore removed segments, and this behaves differently if
  // the path is absolute. However, we only need to check the base path because
  // we are guaranteed that both paths are either relative or absolute.
  absolute = cwk_path_is_root_absolute(path_base, base_root_length);

  // We must keep track of the end of the previous segment. Initially, this is
  // set to the beginning of the path. This means that 0 is returned if the
  // first segment is not equal.
  end = path_base + base_root_length;

  // Now we loop over both segments until one of them reaches the end or their
  // contents are not equal.
  do {
    // We skip all segments which will be removed in each path, since we want to
    // know about the true path.
    if (!cwk_path_segment_joined_skip_invisible(&base, absolute) ||
        !cwk_path_segment_joined_skip_invisible(&other, absolute)) {
      break;
    }

    if (!cwk_path_is_string_equal(base.segment.begin, other.segment.begin,
          base.segment.size)) {
      // So the content of those two segments are not equal. We will return the
      // size up to the beginning.
      return (size_t)(end - path_base);
    }

    // Remember the end of the previous segment before we go to the next one.
    end = base.segment.end;
  } while (cwk_path_get_next_segment_joined(&base) &&
           cwk_path_get_next_segment_joined(&other));

  // Now we calculate the length up to the last point where our paths pointed to
  // the same place.
  return (size_t)(end - path_base);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x17620
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x17620
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x17660
testb $0x1, %al
jne 0x186af
movq $0x0, -0x8(%rbp)
jmp 0x187d8
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x177c0
testb $0x1, %al
jne 0x186e5
jmp 0x186f9
leaq -0x60(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x177c0
testb $0x1, %al
jne 0x18706
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x187d8
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x17770
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movb -0x19(%rbp), %al
leaq -0x98(%rbp), %rdi
andb $0x1, %al
movzbl %al, %esi
callq 0x17940
testb $0x1, %al
jne 0x1873e
jmp 0x18756
movb -0x19(%rbp), %al
leaq -0xd0(%rbp), %rdi
andb $0x1, %al
movzbl %al, %esi
callq 0x17940
testb $0x1, %al
jne 0x18758
jmp 0x187c9
movq -0x88(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x17660
testb $0x1, %al
jne 0x18784
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x187d8
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x17a20
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xd1(%rbp)
jne 0x187a9
jmp 0x187bb
leaq -0xd0(%rbp), %rdi
callq 0x17a20
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x18724
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)