// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x17620
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x17770
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %r8
xorl %eax, %eax
movl %eax, %edx
callq 0x17af0
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x177c0
testb $0x1, %al
jne 0x1732b
jmp 0x173ef
movb $0x0, -0x22(%rbp)
movb -0x21(%rbp), %al
leaq -0x60(%rbp), %rdi
andb $0x1, %al
movzbl %al, %esi
callq 0x18d60
testb $0x1, %al
jne 0x17346
jmp 0x17348
jmp 0x1738c
testb $0x1, -0x22(%rbp)
je 0x17367
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x179d0
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movb $0x1, -0x22(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %r8
callq 0x17af0
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x17a20
testb $0x1, %al
jne 0x1732f
testb $0x1, -0x22(%rbp)
jne 0x173ed
cmpq $0x0, -0x20(%rbp)
jne 0x173ed
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x173b5
jmp 0x173d4
leaq 0x54c1(%rip), %rdi      # 0x1c87d
leaq 0x540c(%rip), %rsi      # 0x1c7cf
movl $0x275, %edx            # imm = 0x275
leaq 0x54c0(%rip), %rcx      # 0x1c88f
callq 0x10b0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x17b70
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x173ef
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x17bb0
movq -0x20(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)