// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq (%rdi), %rdi
leaq 0x18(%rsp), %r15
movq %r15, %rsi
callq 0xeee6
movq (%r12), %rsi
movq (%r15), %r15
testq %r15, %r15
je 0xea57
movl 0xa6f5(%rip), %eax      # 0x19120
leaq 0xa20e(%rip), %rcx      # 0x18c40
movq (%rcx,%rax,8), %rax
movb (%rax), %dl
testb %dl, %dl
je 0xea57
movb -0x1(%rsi,%r15), %cl
incq %rax
cmpb %cl, %dl
sete %bpl
je 0xea59
movb (%rax), %dl
incq %rax
testb %dl, %dl
jne 0xea44
jmp 0xea59
xorl %ebp, %ebp
cmpq %rbx, %r15
movq %rbx, %rdx
cmovbq %r15, %rdx
testq %rdx, %rdx
je 0xea72
movq 0x8(%rsp), %rdi
callq 0x1180
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0xefc4
testb %al, %al
je 0xeb64
xorl %r14d, %r14d
movl %ebp, 0x14(%rsp)
movzbl %bpl, %ebp
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0xfde2
testb %al, %al
jne 0xeb2f
testb $0x1, %r14b
je 0xeaf3
leaq 0x1(%r15), %r13
movq %rbx, %rax
subq %r15, %rax
movl $0x0, %edx
cmovaeq %rax, %rdx
cmpq %rbx, %r13
movl $0x1, %eax
cmovbq %rax, %rdx
testq %rdx, %rdx
je 0xeaf6
movl 0xa647(%rip), %eax      # 0x19120
leaq 0xa160(%rip), %rcx      # 0x18c40
movq (%rcx,%rax,8), %rsi
addq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x1180
jmp 0xeaf6
movq %r15, %r13
movq 0x40(%rsp), %rax
leaq (%rax,%r13), %r15
movq %rbx, %rcx
subq %r13, %rcx
movl $0x0, %edx
cmovaeq %rcx, %rdx
cmpq %rbx, %r15
cmovbq %rax, %rdx
movb $0x1, %r14b
testq %rdx, %rdx
je 0xeb2f
movq 0x30(%rsp), %rsi
addq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x1180
movq %r12, %rdi
callq 0xf064
testb %al, %al
jne 0xea97
testb $0x1, %r14b
jne 0xeb64
testq %r15, %r15
jne 0xeb64
cmpb $0x0, 0x14(%rsp)
jne 0xeb93
movl $0x1, %r15d
testq %rbx, %rbx
je 0xeb64
movq 0x8(%rsp), %rax
movb $0x2e, (%rax)
testq %rbx, %rbx
je 0xeb81
movq 0x8(%rsp), %rcx
leaq (%rcx,%r15), %rax
cmpq %rbx, %r15
leaq -0x1(%rcx,%rbx), %rcx
cmovbq %rax, %rcx
movb $0x0, (%rcx)
movq %r15, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x53fd(%rip), %rdi      # 0x13f97
leaq 0x5348(%rip), %rsi      # 0x13ee9
leaq 0x5401(%rip), %rcx      # 0x13fa9
movl $0x275, %edx            # imm = 0x275
callq 0x10d0