// File: /workspace/github_c_makefile_star2_O2/tditlu[P]shadetabler/src/cwalk/cwalk.c
// Function: cwk_path_join_and_normalize_multiple
static size_t cwk_path_join_and_normalize_multiple(const char **paths,
  char *buffer, size_t buffer_size)
{
  size_t pos;
  bool absolute, has_segment_output;
  struct cwk_segment_joined sj;

  // We initialize the position after the root, which should get us started.
  cwk_path_get_root(paths[0], &pos);

  // Determine whether the path is absolute or not. We need that to determine
  // later on whether we can remove superfluous "../" or not.
  absolute = cwk_path_is_root_absolute(paths[0], pos);

  // First copy the root to the output. We will not modify the root.
  cwk_path_output_sized(buffer, buffer_size, 0, paths[0], pos);

  // So we just grab the first segment. If there is no segment we will always
  // output a "/", since we currently only support absolute paths here.
  if (!cwk_path_get_first_segment_joined(paths, &sj)) {
    goto done;
  }

  // Let's assume that we don't have any segment output for now. We will toggle
  // this flag once there is some output.
  has_segment_output = false;

  do {
    // Check whether we have to drop this segment because of resolving a
    // relative path or because it is a CWK_CURRENT segment.
    if (cwk_path_segment_will_be_removed(&sj, absolute)) {
      continue;
    }

    // We add a separator if we previously wrote a segment. The last segment
    // must not have a trailing separator. This must happen before the segment
    // output, since we would override the null terminating character with
    // reused buffers if this was done afterwards.
    if (has_segment_output) {
      pos += cwk_path_output_separator(buffer, buffer_size, pos);
    }

    // Remember that we have segment output, so we can handle the trailing slash
    // later on. This is necessary since we might have segments but they are all
    // removed.
    has_segment_output = true;

    // Write out the segment but keep in mind that we need to follow the
    // buffer size limitations. That's why we use the path output functions
    // here.
    pos += cwk_path_output_sized(buffer, buffer_size, pos, sj.segment.begin,
      sj.segment.size);
  } while (cwk_path_get_next_segment_joined(&sj));

  // Remove the trailing slash, but only if we have segment output. We don't
  // want to remove anything from the root.
  if (!has_segment_output && pos == 0) {
    // This may happen if the path is absolute and all segments have been
    // removed. We can not have an empty output - and empty output means we stay
    // in the current directory. So we will output a ".".
    assert(absolute == false);
    pos += cwk_path_output_current(buffer, buffer_size, pos);
  }

  // We must append a '\0' in any case, unless the buffer size is zero. If the
  // buffer size is zero, which means we can not.
done:
  cwk_path_terminate_output(buffer, buffer_size, pos);

  // And finally let our caller know about the total size of the normalized
  // path.
  return pos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
movq (%rdi), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xce34
movq (%r12), %r13
movq (%r15), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0xcedf
movb %al, 0x7(%rsp)
cmpq %rbx, %r15
movq %rbx, %rdx
cmovbq %r15, %rdx
testq %rdx, %rdx
je 0xcab5
movq %r14, %rdi
movq %r13, %rsi
callq 0x1170
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0xcef2
testb %al, %al
je 0xcb64
xorl %ebp, %ebp
movzbl 0x7(%rsp), %r12d
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movl %r12d, %esi
callq 0xdadd
testb %al, %al
jne 0xcb39
testb $0x1, %bpl
je 0xcb02
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0xcf6d
movq %rax, %rdi
addq %r15, %rdi
jmp 0xcb05
movq %r15, %rdi
movq 0x30(%rsp), %rax
leaq (%rax,%rdi), %r15
movq %rbx, %rcx
subq %rdi, %rcx
movl $0x0, %edx
cmovaeq %rcx, %rdx
cmpq %rbx, %r15
cmovbq %rax, %rdx
movb $0x1, %bpl
testq %rdx, %rdx
je 0xcb39
movq 0x20(%rsp), %rsi
addq %r14, %rdi
callq 0x1170
movq %r13, %rdi
callq 0xcfb1
testb %al, %al
jne 0xcad7
testb $0x1, %bpl
jne 0xcb64
testq %r15, %r15
jne 0xcb64
cmpb $0x0, 0x7(%rsp)
jne 0xcb8e
pushq $0x1
popq %r15
testq %rbx, %rbx
je 0xcb64
movb $0x2e, (%r14)
testq %rbx, %rbx
je 0xcb7c
leaq (%r14,%r15), %rax
cmpq %rbx, %r15
leaq -0x1(%r14,%rbx), %rcx
cmovbq %rax, %rcx
movb $0x0, (%rcx)
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4312(%rip), %rdi      # 0x10ea7
leaq 0x425d(%rip), %rsi      # 0x10df9
leaq 0x4316(%rip), %rcx      # 0x10eb9
movl $0x275, %edx            # imm = 0x275
callq 0x10d0