// File: /workspace/github_c_makefile_star2_O1/atomlang[P]atomlang/cli/thirdparty/cwalk/cwalk.c
// Function: cwk_path_get_root_windows
static void cwk_path_get_root_windows(const char* path, size_t* length)
{
  const char* c;
  bool is_device_path;

  // We can not determine the root if this is an empty string. So we set the
  // root to NULL and the length to zero and cancel the whole thing.
  c = path;
  *length = 0;
  if (!*c) {
    return;
  }

  // Now we have to verify whether this is a windows network path (UNC), which
  // we will consider our root.
  if (cwk_path_is_separator(c)) {
    ++c;

    // Check whether the path starts with a single back slash, which means this
    // is not a network path - just a normal path starting with a backslash.
    if (!cwk_path_is_separator(c)) {
      // Okay, this is not a network path but we still use the backslash as a
      // root.
      ++(*length);
      return;
    }

    // A device path is a path which starts with "\\." or "\\?". A device path
    // can be a UNC path as well, in which case it will take up one more
    // segment. So, this is a network or device path. Skip the previous
    // separator. Now we need to determine whether this is a device path. We
    // might advance one character here if the server name starts with a '?' or
    // a '.', but that's fine since we will search for a separator afterwards
    // anyway.
    ++c;
    is_device_path = (*c == '?' || *c == '.') && cwk_path_is_separator(++c);
    if (is_device_path) {
      // That's a device path, and the root must be either "\\.\" or "\\?\"
      // which is 4 characters long. (at least that's how Windows
      // GetFullPathName behaves.)
      *length = 4;
      return;
    }

    // We will grab anything up to the next stop. The next stop might be a '\0'
    // or another separator. That will be the server name.
    c = cwk_path_find_next_stop(c);

    // If this is a separator and not the end of a string we wil have to include
    // it. However, if this is a '\0' we must not skip it.
    while (cwk_path_is_separator(c)) {
      ++c;
    }

    // We are now skipping the shared folder name, which will end after the
    // next stop.
    c = cwk_path_find_next_stop(c);

    // Then there might be a separator at the end. We will include that as well,
    // it will mark the path as absolute.
    if (cwk_path_is_separator(c)) {
      ++c;
    }

    // Finally, calculate the size of the root.
    *length = (size_t)(c - path);
    return;
  }

  // Move to the next and check whether this is a colon.
  if (*++c == ':') {
    *length = 2;

    // Now check whether this is a backslash (or slash). If it is not, we could
    // assume that the next character is a '\0' if it is a valid path. However,
    // we will not assume that - since ':' is not valid in a path it must be a
    // mistake by the caller than. We will try to understand it anyway.
    if (cwk_path_is_separator(++c)) {
      *length = 3;
    }
  }
}

// Assembly:
movq $0x0, (%rsi)
movb (%rdi), %al
testb %al, %al
je 0x1b6fe
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movl 0xf391(%rip), %ecx      # 0x2a8f0
leaq 0xe85a(%rip), %rdx      # 0x29dc0
movq (%rdx,%rcx,8), %r15
movb (%r15), %r12b
testb %r12b, %r12b
setne %bpl
movl %ebp, %ecx
je 0x1b597
cmpb %al, %r12b
je 0x1b59b
leaq 0x1(%r15), %rdx
movb (%rdx), %sil
testb %sil, %sil
setne %cl
cmpb %al, %sil
je 0x1b597
incq %rdx
testb %sil, %sil
jne 0x1b581
testb %cl, %cl
je 0x1b617
movl %ebp, %ecx
testb %r12b, %r12b
je 0x1b5c5
movb 0x1(%r14), %al
cmpb %al, %r12b
je 0x1b5d2
leaq 0x1(%r15), %rdx
movb (%rdx), %sil
testb %sil, %sil
setne %cl
cmpb %al, %sil
je 0x1b5c5
incq %rdx
testb %sil, %sil
jne 0x1b5af
movl $0x1, %eax
testb %cl, %cl
je 0x1b6f3
movzbl 0x2(%r14), %eax
cmpl $0x3f, %eax
je 0x1b5e5
cmpl $0x2e, %eax
jne 0x1b66e
leaq 0x3(%r14), %rdi
testb %r12b, %r12b
je 0x1b676
movb (%rdi), %al
movb $0x1, %cl
cmpb %al, %r12b
je 0x1b678
leaq 0x1(%r15), %rdx
movb (%rdx), %sil
testb %sil, %sil
setne %cl
cmpb %al, %sil
je 0x1b678
incq %rdx
testb %sil, %sil
jne 0x1b5ff
jmp 0x1b678
cmpb $0x3a, 0x1(%r14)
jne 0x1b6f6
movq $0x2, (%rbx)
movb (%r15), %sil
testb %sil, %sil
setne %dl
je 0x1b65c
movb 0x2(%r14), %cl
movl $0x3, %eax
cmpb %cl, %sil
je 0x1b6f3
incq %r15
movb (%r15), %al
testb %al, %al
setne %dl
cmpb %cl, %al
je 0x1b65c
incq %r15
testb %al, %al
jne 0x1b649
movl $0x3, %eax
testb %dl, %dl
jne 0x1b6f3
jmp 0x1b6f6
leaq 0x2(%r14), %rdi
xorl %ecx, %ecx
jmp 0x1b678
movl %ebp, %ecx
movl $0x4, %eax
testb %cl, %cl
jne 0x1b6f3
callq 0x1c136
leaq 0x1(%r15), %rcx
movq %rax, %rdi
movl %ebp, %edx
testb %r12b, %r12b
je 0x1b6b6
movb (%rdi), %al
movb $0x1, %dl
cmpb %al, %r12b
je 0x1b6b6
movq %rcx, %rsi
movb (%rsi), %r8b
testb %r8b, %r8b
setne %dl
cmpb %al, %r8b
je 0x1b6b6
incq %rsi
testb %r8b, %r8b
jne 0x1b6a0
leaq 0x1(%rdi), %rax
testb %dl, %dl
jne 0x1b68a
callq 0x1c136
testb %r12b, %r12b
je 0x1b6e9
movb (%rax), %cl
movb $0x1, %bpl
cmpb %cl, %r12b
je 0x1b6e9
incq %r15
movb (%r15), %dl
testb %dl, %dl
setne %bpl
cmpb %cl, %dl
je 0x1b6e9
incq %r15
testb %dl, %dl
jne 0x1b6d5
movzbl %bpl, %ecx
addq %rcx, %rax
subq %r14, %rax
movq %rax, (%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq