// File: /workspace/github_c_makefile_star2_O0/tditlu[P]shadetabler/src/cwalk/cwalk.c
// Function: cwk_path_change_segment
size_t cwk_path_change_segment(struct cwk_segment *segment, const char *value,
  char *buffer, size_t buffer_size)
{
  size_t pos, value_size, tail_size;

  // First we have to output the head, which is the whole string up to the
  // beginning of the segment. This part of the path will just stay the same.
  pos = cwk_path_output_sized(buffer, buffer_size, 0, segment->path,
    (size_t)(segment->begin - segment->path));

  // In order to trip the submitted value, we will skip any separator at the
  // beginning of it and behave as if it was never there.
  while (cwk_path_is_separator(value)) {
    ++value;
  }

  // Now we determine the length of the value. In order to do that we first
  // locate the '\0'.
  value_size = 0;
  while (value[value_size]) {
    ++value_size;
  }

  // Since we trim separators at the beginning and in the end of the value we
  // have to subtract from the size until there are either no more characters
  // left or the last character is no separator.
  while (value_size > 0 && cwk_path_is_separator(&value[value_size - 1])) {
    --value_size;
  }

  // We also have to determine the tail size, which is the part of the string
  // following the current segment. This part will not change.
  tail_size = strlen(segment->end);

  // Now we output the tail. We have to do that, because if the buffer and the
  // source are overlapping we would override the tail if the value is
  // increasing in length.
  cwk_path_output_sized(buffer, buffer_size, pos + value_size, segment->end,
    tail_size);

  // Finally we can output the value in the middle of the head and the tail,
  // where we have enough space to fit the whole trimmed value.
  pos += cwk_path_output_sized(buffer, buffer_size, pos, value, value_size);

  // Now we add the tail size to the current position and terminate the output -
  // basically, ensure that there is a '\0' at the end of the buffer.
  pos += tail_size;
  cwk_path_terminate_output(buffer, buffer_size, pos);

  // And now tell the caller how long the whole path would be.
  return pos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
subq %rax, %r8
xorl %eax, %eax
movl %eax, %edx
callq 0x17af0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x18110
testb $0x1, %al
jne 0x181c5
jmp 0x181d3
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x181b6
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x181f7
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x181db
jmp 0x181f9
xorl %eax, %eax
cmpq $0x0, -0x30(%rbp)
movb %al, -0x39(%rbp)
jbe 0x1821c
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
subq $0x1, %rax
addq %rax, %rdi
callq 0x18110
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x18225
jmp 0x18233
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x181f9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1080
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
addq -0x30(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %r8
callq 0x17af0
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x17af0
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x17bb0
movq -0x28(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)