// File: /workspace/github_c_makefile_star2_O1/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 0xf525
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movl 0x9d9a(%rip), %ecx      # 0x19120
leaq 0x98b3(%rip), %rdx      # 0x18c40
movq (%rdx,%rcx,8), %r15
movb (%r15), %r12b
testb %r12b, %r12b
setne %bpl
movl %ebp, %ecx
je 0xf3be
cmpb %al, %r12b
je 0xf3c2
leaq 0x1(%r15), %rdx
movb (%rdx), %sil
testb %sil, %sil
setne %cl
cmpb %al, %sil
je 0xf3be
incq %rdx
testb %sil, %sil
jne 0xf3a8
testb %cl, %cl
je 0xf43e
movl %ebp, %ecx
testb %r12b, %r12b
je 0xf3ec
movb 0x1(%r14), %al
cmpb %al, %r12b
je 0xf3f9
leaq 0x1(%r15), %rdx
movb (%rdx), %sil
testb %sil, %sil
setne %cl
cmpb %al, %sil
je 0xf3ec
incq %rdx
testb %sil, %sil
jne 0xf3d6
movl $0x1, %eax
testb %cl, %cl
je 0xf51a
movzbl 0x2(%r14), %eax
cmpl $0x3f, %eax
je 0xf40c
cmpl $0x2e, %eax
jne 0xf495
leaq 0x3(%r14), %rdi
testb %r12b, %r12b
je 0xf49d
movb (%rdi), %al
movb $0x1, %cl
cmpb %al, %r12b
je 0xf49f
leaq 0x1(%r15), %rdx
movb (%rdx), %sil
testb %sil, %sil
setne %cl
cmpb %al, %sil
je 0xf49f
incq %rdx
testb %sil, %sil
jne 0xf426
jmp 0xf49f
cmpb $0x3a, 0x1(%r14)
jne 0xf51d
movq $0x2, (%rbx)
movb (%r15), %sil
testb %sil, %sil
setne %dl
je 0xf483
movb 0x2(%r14), %cl
movl $0x3, %eax
cmpb %cl, %sil
je 0xf51a
incq %r15
movb (%r15), %al
testb %al, %al
setne %dl
cmpb %cl, %al
je 0xf483
incq %r15
testb %al, %al
jne 0xf470
movl $0x3, %eax
testb %dl, %dl
jne 0xf51a
jmp 0xf51d
leaq 0x2(%r14), %rdi
xorl %ecx, %ecx
jmp 0xf49f
movl %ebp, %ecx
movl $0x4, %eax
testb %cl, %cl
jne 0xf51a
callq 0xff4d
leaq 0x1(%r15), %rcx
movq %rax, %rdi
movl %ebp, %edx
testb %r12b, %r12b
je 0xf4dd
movb (%rdi), %al
movb $0x1, %dl
cmpb %al, %r12b
je 0xf4dd
movq %rcx, %rsi
movb (%rsi), %r8b
testb %r8b, %r8b
setne %dl
cmpb %al, %r8b
je 0xf4dd
incq %rsi
testb %r8b, %r8b
jne 0xf4c7
leaq 0x1(%rdi), %rax
testb %dl, %dl
jne 0xf4b1
callq 0xff4d
testb %r12b, %r12b
je 0xf510
movb (%rax), %cl
movb $0x1, %bpl
cmpb %cl, %r12b
je 0xf510
incq %r15
movb (%r15), %dl
testb %dl, %dl
setne %bpl
cmpb %cl, %dl
je 0xf510
incq %r15
testb %dl, %dl
jne 0xf4fc
movzbl %bpl, %ecx
addq %rcx, %rax
subq %r14, %rax
movq %rax, (%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq