// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
movq %rdi, %r15
movq (%rdi), %rdi
leaq 0x10(%rsp), %r12
movq %r12, %rsi
callq 0xf131
movq (%r15), %rsi
movq (%r12), %rdx
testq %rdx, %rdx
je 0xec7b
movl 0xa4e4(%rip), %eax      # 0x19120
leaq 0x9ffd(%rip), %rcx      # 0x18c40
movq (%rcx,%rax,8), %rax
movb (%rax), %dil
testb %dil, %dil
setne %bpl
je 0xec7d
movb -0x1(%rsi,%rdx), %cl
movb $0x1, %bpl
cmpb %cl, %dil
je 0xec7d
incq %rax
movb (%rax), %dil
testb %dil, %dil
setne %bpl
cmpb %cl, %dil
je 0xec7d
incq %rax
testb %dil, %dil
jne 0xec62
jmp 0xec7d
xorl %ebp, %ebp
cmpq %rbx, %rdx
cmovaeq %rbx, %rdx
testq %rdx, %rdx
je 0xec93
movq 0x8(%rsp), %rdi
callq 0x1180
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xf22a
testb %al, %al
je 0xeda3
movq 0x10(%rsp), %r12
xorl %r14d, %r14d
movl %ebp, 0x1c(%rsp)
movzbl %bpl, %ebp
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
callq 0x101c1
testb %al, %al
jne 0xed56
testb $0x1, %r14b
je 0xed1a
leaq 0x1(%r12), %r13
movq %rbx, %rax
subq %r12, %rax
movl $0x0, %edx
cmovaeq %rax, %rdx
cmpq %rbx, %r13
movl $0x1, %eax
cmovbq %rax, %rdx
testq %rdx, %rdx
je 0xed1d
movl 0xa420(%rip), %eax      # 0x19120
leaq 0x9f39(%rip), %rcx      # 0x18c40
movq (%rcx,%rax,8), %rsi
addq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x1180
jmp 0xed1d
movq %r12, %r13
movq 0x40(%rsp), %rax
leaq (%rax,%r13), %r12
movq %rbx, %rcx
subq %r13, %rcx
movl $0x0, %edx
cmovaeq %rcx, %rdx
cmpq %rbx, %r12
cmovbq %rax, %rdx
movb $0x1, %r14b
testq %rdx, %rdx
je 0xed56
movq 0x30(%rsp), %rsi
addq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x1180
movq %r15, %rdi
callq 0xf2ca
testb %al, %al
jne 0xecbd
movq %r12, 0x10(%rsp)
testb $0x1, %r14b
movl 0x1c(%rsp), %eax
jne 0xeda3
testq %r12, %r12
jne 0xeda3
testb %al, %al
jne 0xedd4
testq %rbx, %rbx
je 0xed9a
setne %al
movzbl %al, %edx
leaq 0x5364(%rip), %rsi      # 0x140f4
movq 0x8(%rsp), %rdi
callq 0x1130
movq $0x1, 0x10(%rsp)
movq 0x10(%rsp), %rax
testq %rbx, %rbx
je 0xedc5
movq 0x8(%rsp), %rdx
leaq (%rdx,%rax), %rcx
cmpq %rbx, %rax
leaq -0x1(%rdx,%rbx), %rdx
cmovbq %rcx, %rdx
movb $0x0, (%rdx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x50bc(%rip), %rdi      # 0x13e97
leaq 0x5007(%rip), %rsi      # 0x13de9
leaq 0x50c0(%rip), %rcx      # 0x13ea9
movl $0x275, %edx            # imm = 0x275
callq 0x10d0