// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/PathUtil.cpp
// Function: t2::PathInit(t2::PathBuffer*, char const*, t2::PathType::Enum)
void PathInit(PathBuffer* buffer, const char* path, PathType::Enum type)
{
  // Initialize
  buffer->m_Type  = type;
  buffer->m_Flags = 0;

  // Check to see if the path is absolute
  switch (type)
  {
    case PathType::kUnix:
      if ('/' == path[0])
      {
        buffer->m_Flags |= PathBuffer::kFlagAbsolute;
        path++;
      }
      break;

    case PathType::kWindows:
      // Check for absolute path w/o device name
      if ('\\' == path[0] || '/' == path[0])
      {
        buffer->m_Flags |= PathBuffer::kFlagAbsolute;
        path++;
      }
      // Check for X:\ style path
      else if (isalpha(path[0]) && ':' == path[1] && ('\\' == path[2] || '/' == path[2]))
      {
        buffer->m_Flags |= PathBuffer::kFlagAbsolute | PathBuffer::kFlagWindowsDevicePath;
      }
      // FIXME: network paths
      break;

    default:
      Croak("bad path type");
      break;
  }

  // Initialize segment data
  PathSeg segments[kMaxPathSegments];

  int raw_seg_count = PathGetSegments(path, segments);
  uint16_t dotdot_drops = 0;

  // Drop segments based on .. following them
  for (int i = raw_seg_count - 1; i >= 0; --i)
  {
    if (segments[i].drop)
      continue;

    if (segments[i].dotdot)
    {
      ++dotdot_drops;
      segments[i].drop = 1;
    }
    else if (dotdot_drops > 0)
    {
      --dotdot_drops;
      segments[i].drop = 1;
    }
  }

  buffer->m_LeadingDotDots = dotdot_drops;

  // Copy retained segments to output array
  uint16_t output_seg_count = 0;
  uint16_t output_pos = 0;
  for (int i = 0; i < raw_seg_count; ++i)
  {
    if (segments[i].drop)
      continue;

    if (output_pos >= kMaxPathLength)
      Croak("Path too long: %s", path);

    memcpy(buffer->m_Data + output_pos, path + segments[i].offset, segments[i].len);
    output_pos += segments[i].len;
    buffer->m_SegEnds[output_seg_count] = output_pos;
    ++output_seg_count;
  }

  buffer->m_SegCount = output_seg_count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movw $0x0, 0x4(%rax)
movl -0x14(%rbp), %eax
movl %eax, -0x1b8(%rbp)
testl %eax, %eax
je 0x18eb8
jmp 0x18ea8
movl -0x1b8(%rbp), %eax
subl $0x1, %eax
je 0x18ee8
jmp 0x18f7c
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
movl $0x2f, %eax
cmpl %ecx, %eax
jne 0x18ee3
movq -0x8(%rbp), %rax
movzwl 0x4(%rax), %ecx
orl $0x1, %ecx
movw %cx, 0x4(%rax)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x18f8a
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
movl $0x5c, %eax
cmpl %ecx, %eax
je 0x18f08
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
movl $0x2f, %eax
cmpl %ecx, %eax
jne 0x18f25
movq -0x8(%rbp), %rax
movzwl 0x4(%rax), %ecx
orl $0x1, %ecx
movw %cx, 0x4(%rax)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x18f7a
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x3550
cmpl $0x0, %eax
je 0x18f78
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %ecx
movl $0x3a, %eax
cmpl %ecx, %eax
jne 0x18f78
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %ecx
movl $0x5c, %eax
cmpl %ecx, %eax
je 0x18f69
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %ecx
movl $0x2f, %eax
cmpl %ecx, %eax
jne 0x18f78
movq -0x8(%rbp), %rax
movzwl 0x4(%rax), %ecx
orl $0x3, %ecx
movw %cx, 0x4(%rax)
jmp 0x18f7a
jmp 0x18f8a
leaq 0xc202(%rip), %rdi      # 0x25185
movb $0x0, %al
callq 0x75a0
movq -0x10(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x191d0
movl %eax, -0x1a4(%rbp)
movw $0x0, -0x1a6(%rbp)
movl -0x1a4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1ac(%rbp)
cmpl $0x0, -0x1ac(%rbp)
jl 0x1907c
movslq -0x1ac(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x5(%rax)
je 0x18fe5
jmp 0x19068
movslq -0x1ac(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x4(%rax)
je 0x1902d
movw -0x1a6(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1a6(%rbp)
movslq -0x1ac(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movb $0x1, 0x5(%rax)
jmp 0x19066
movzwl -0x1a6(%rbp), %eax
cmpl $0x0, %eax
jle 0x19064
movw -0x1a6(%rbp), %ax
addw $-0x1, %ax
movw %ax, -0x1a6(%rbp)
movslq -0x1ac(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movb $0x1, 0x5(%rax)
jmp 0x19066
jmp 0x19068
movl -0x1ac(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x18fb8
movw -0x1a6(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movw $0x0, -0x1ae(%rbp)
movw $0x0, -0x1b0(%rbp)
movl $0x0, -0x1b4(%rbp)
movl -0x1b4(%rbp), %eax
cmpl -0x1a4(%rbp), %eax
jge 0x191b7
movslq -0x1b4(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x5(%rax)
je 0x190d9
jmp 0x191a3
movzwl -0x1b0(%rbp), %eax
cmpl $0x200, %eax            # imm = 0x200
jl 0x190f9
movq -0x10(%rbp), %rsi
leaq 0xc0a1(%rip), %rdi      # 0x25193
movb $0x0, %al
callq 0x75a0
movq -0x8(%rbp), %rdi
addq $0x8a, %rdi
movzwl -0x1b0(%rbp), %eax
cltq
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movslq -0x1b4(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movzwl (%rax), %eax
cltq
addq %rax, %rsi
movslq -0x1b4(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %eax
movl %eax, %edx
callq 0x32a0
movslq -0x1b4(%rbp), %rcx
leaq -0x1a0(%rbp), %rax
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %ecx
movzwl -0x1b0(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x1b0(%rbp)
movw -0x1b0(%rbp), %dx
movq -0x8(%rbp), %rax
movzwl -0x1ae(%rbp), %ecx
movw %dx, 0xa(%rax,%rcx,2)
movw -0x1ae(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1ae(%rbp)
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b4(%rbp)
jmp 0x190a7
movw -0x1ae(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
nop