// File: /workspace/github_c_makefile_star2_O3/tditlu[P]shadetabler/src/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;

  // 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.
  is_device_path = false;

  // 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;
    }

    // Yes, 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 0xf222
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0xa013(%rip), %ecx      # 0x19120
leaq 0x9b2c(%rip), %rdx      # 0x18c40
movq (%rdx,%rcx,8), %r15
movb (%r15), %bpl
testb %bpl, %bpl
je 0xf133
leaq 0x1(%r15), %rcx
movl %ebp, %edx
cmpb %al, %dl
je 0xf16a
movb (%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0xf126
cmpb $0x3a, 0x1(%r14)
jne 0xf218
movq $0x2, (%rbx)
movb (%r15), %al
testb %al, %al
je 0xf218
movb 0x2(%r14), %cl
incq %r15
cmpb %cl, %al
je 0xf1b7
movb (%r15), %al
incq %r15
testb %al, %al
jne 0xf157
jmp 0xf218
movb 0x1(%r14), %al
leaq 0x1(%r15), %rcx
movl %ebp, %edx
cmpb %al, %dl
je 0xf18b
movb (%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0xf174
movl $0x1, %eax
jmp 0xf215
movzbl 0x2(%r14), %eax
cmpl $0x3f, %eax
je 0xf19a
cmpl $0x2e, %eax
jne 0xf1c5
leaq 0x3(%r14), %rdi
movb 0x3(%r14), %al
leaq 0x1(%r15), %rcx
movl %ebp, %edx
cmpb %al, %dl
je 0xf1be
movb (%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0xf1a8
jmp 0xf1c9
movl $0x3, %eax
jmp 0xf215
movl $0x4, %eax
jmp 0xf215
leaq 0x2(%r14), %rdi
callq 0xfbcb
leaq 0x1(%r15), %rcx
movb (%rax), %dl
movq %rcx, %rsi
movl %ebp, %edi
cmpb %dl, %dil
je 0xf1eb
movb (%rsi), %dil
incq %rsi
testb %dil, %dil
jne 0xf1d9
jmp 0xf1f0
incq %rax
jmp 0xf1d2
movq %rax, %rdi
callq 0xfbcb
movb (%rax), %cl
incq %r15
cmpb %cl, %bpl
je 0xf20f
movb (%r15), %bpl
incq %r15
testb %bpl, %bpl
jne 0xf1fd
jmp 0xf212
incq %rax
subq %r14, %rax
movq %rax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq