// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq $0x0, (%rax)
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x273a3
jmp 0x2750d
movq 0x10(%rsp), %rdi
callq 0x27860
testb $0x1, %al
jne 0x273b6
jmp 0x274c0
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0x27860
testb $0x1, %al
jne 0x273e6
movq 0x18(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x2750d
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3f, %eax
je 0x27414
movq 0x10(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2e, %ecx
movb %al, 0xe(%rsp)
jne 0x2742b
movq 0x10(%rsp), %rdi
addq $0x1, %rdi
movq %rdi, 0x10(%rsp)
callq 0x27860
movb %al, 0xe(%rsp)
movb 0xe(%rsp), %al
andb $0x1, %al
movb %al, 0xf(%rsp)
testb $0x1, 0xf(%rsp)
je 0x2744d
movq 0x18(%rsp), %rax
movq $0x4, (%rax)
jmp 0x2750d
movq 0x10(%rsp), %rdi
callq 0x28280
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0x27860
testb $0x1, %al
jne 0x2746c
jmp 0x2747c
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x2745c
movq 0x10(%rsp), %rdi
callq 0x28280
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0x27860
testb $0x1, %al
jne 0x2749b
jmp 0x274a9
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
subq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
jmp 0x2750d
movq 0x10(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rsp)
movsbl 0x1(%rax), %eax
cmpl $0x3a, %eax
jne 0x2750d
movq 0x18(%rsp), %rax
movq $0x2, (%rax)
movq 0x10(%rsp), %rdi
addq $0x1, %rdi
movq %rdi, 0x10(%rsp)
callq 0x27860
testb $0x1, %al
jne 0x274ff
jmp 0x2750b
movq 0x18(%rsp), %rax
movq $0x3, (%rax)
jmp 0x2750d
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)