// File: /workspace/github_c_makefile_star2_O3/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 0x1a957
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0xf0ae(%rip), %ecx      # 0x298f0
leaq 0xe577(%rip), %rdx      # 0x28dc0
movq (%rdx,%rcx,8), %r15
movb (%r15), %bpl
testb %bpl, %bpl
je 0x1a868
leaq 0x1(%r15), %rcx
movl %ebp, %edx
cmpb %al, %dl
je 0x1a89f
movb (%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0x1a85b
cmpb $0x3a, 0x1(%r14)
jne 0x1a94d
movq $0x2, (%rbx)
movb (%r15), %al
testb %al, %al
je 0x1a94d
movb 0x2(%r14), %cl
incq %r15
cmpb %cl, %al
je 0x1a8ec
movb (%r15), %al
incq %r15
testb %al, %al
jne 0x1a88c
jmp 0x1a94d
movb 0x1(%r14), %al
leaq 0x1(%r15), %rcx
movl %ebp, %edx
cmpb %al, %dl
je 0x1a8c0
movb (%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0x1a8a9
movl $0x1, %eax
jmp 0x1a94a
movzbl 0x2(%r14), %eax
cmpl $0x3f, %eax
je 0x1a8cf
cmpl $0x2e, %eax
jne 0x1a8fa
leaq 0x3(%r14), %rdi
movb 0x3(%r14), %al
leaq 0x1(%r15), %rcx
movl %ebp, %edx
cmpb %al, %dl
je 0x1a8f3
movb (%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0x1a8dd
jmp 0x1a8fe
movl $0x3, %eax
jmp 0x1a94a
movl $0x4, %eax
jmp 0x1a94a
leaq 0x2(%r14), %rdi
callq 0x1b310
leaq 0x1(%r15), %rcx
movb (%rax), %dl
movq %rcx, %rsi
movl %ebp, %edi
cmpb %dl, %dil
je 0x1a920
movb (%rsi), %dil
incq %rsi
testb %dil, %dil
jne 0x1a90e
jmp 0x1a925
incq %rax
jmp 0x1a907
movq %rax, %rdi
callq 0x1b310
movb (%rax), %cl
incq %r15
cmpb %cl, %bpl
je 0x1a944
movb (%r15), %bpl
incq %r15
testb %bpl, %bpl
jne 0x1a932
jmp 0x1a947
incq %rax
subq %r14, %rax
movq %rax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq