#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ fileExists(char const *);
int /*<<< orphan*/ memmove(char *, char const *, size_t);
char *strchr(char const *, char);
size_t strlen(char const *);
char *ensureFilesExist(char *aDestination, char const *aSourcePathsAndNames) {
  char *lDestination = aDestination;
  char const *p;
  char const *p2;
  size_t lLen;
  if (!aSourcePathsAndNames) {
    return NULL;
  }
  lLen = strlen(aSourcePathsAndNames);
  if (!lLen) {
    return NULL;
  }
  p = aSourcePathsAndNames;
  while ((p2 = strchr(p, '|')) != NULL) {
    lLen = p2 - p;
    memmove(lDestination, p, lLen);
    lDestination[lLen] = '\0';
    if (fileExists(lDestination)) {
      lDestination += lLen;
      *lDestination = '|';
      lDestination++;
    }
    p = p2 + 1;
  }
  if (fileExists(p)) {
    lLen = strlen(p);
    memmove(lDestination, p, lLen);
    lDestination[lLen] = '\0';
  } else {
    *(lDestination - 1) = '\0';
  }
  return aDestination;
}


x86 assembly (clang, -O0):
<ensureFilesExist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1170 <ensureFilesExist+0x30>
movq   $0x0,-0x8(%rbp)
jmp    127a <ensureFilesExist+0x13a>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1195 <ensureFilesExist+0x55>
movq   $0x0,-0x8(%rbp)
jmp    127a <ensureFilesExist+0x13a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1228 <ensureFilesExist+0xe8>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1060 <memmove@plt>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <fileExists@plt>
cmp    $0x0,%rax
je     1217 <ensureFilesExist+0xd7>
mov    -0x38(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x7c,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    119d <ensureFilesExist+0x5d>
mov    -0x28(%rbp),%rdi
call   1030 <fileExists@plt>
cmp    $0x0,%rax
je     126a <ensureFilesExist+0x12a>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1060 <memmove@plt>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1272 <ensureFilesExist+0x132>
mov    -0x20(%rbp),%rax
movb   $0x0,-0x1(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ensureFilesExist>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     11cf <ensureFilesExist+0x8f>
mov    %rsi,%r13
cmpb   $0x0,(%rsi)
je     11cf <ensureFilesExist+0x8f>
mov    %rdi,%r14
mov    %r13,%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11d4 <ensureFilesExist+0x94>
mov    %rax,%r12
mov    %r14,%r15
jmp    119c <ensureFilesExist+0x5c>
nopw   0x0(%rax,%rax,1)
mov    %r12,%r13
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
je     11d7 <ensureFilesExist+0x97>
mov    %r12,%rbx
sub    %r13,%rbx
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <memmove@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
call   1030 <fileExists@plt>
test   %rax,%rax
je     1180 <ensureFilesExist+0x40>
add    %rbx,%r15
movb   $0x7c,(%r15)
add    $0x1,%r15
jmp    1180 <ensureFilesExist+0x40>
xor    %r14d,%r14d
jmp    120b <ensureFilesExist+0xcb>
mov    %r14,%r15
mov    %r13,%rdi
call   1030 <fileExists@plt>
test   %rax,%rax
je     11ff <ensureFilesExist+0xbf>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1060 <memmove@plt>
jmp    1206 <ensureFilesExist+0xc6>
mov    $0xffffffffffffffff,%rbx
movb   $0x0,(%r15,%rbx,1)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ensureFilesExist(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
store i8* %10, i8** %6
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i8* null, i8** %3
br label %71
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %9
%17 = load i64, i64* %9
%18 = icmp ne i64 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %14
store i8* null, i8** %3
br label %71
20: ; preds = %14
%21 = load i8*, i8** %5
store i8* %21, i8** %7
br label %22
22: ; preds = %49, %20
%23 = load i8*, i8** %7
%24 = call i8* @strchr(i8* %23, i8 signext 124)
store i8* %24, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %52
26: ; preds = %22
%27 = load i8*, i8** %8
%28 = load i8*, i8** %7
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
store i64 %31, i64* %9
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = load i64, i64* %9
%35 = call i32 @memmove(i8* %32, i8* %33, i64 %34)
%36 = load i8*, i8** %6
%37 = load i64, i64* %9
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %6
%40 = call i64 @fileExists(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %26
%43 = load i64, i64* %9
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 %43
store i8* %45, i8** %6
%46 = load i8*, i8** %6
store i8 124, i8* %46
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %6
br label %49
49: ; preds = %42, %26
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i64 1
store i8* %51, i8** %7
br label %22
52: ; preds = %22
%53 = load i8*, i8** %7
%54 = call i64 @fileExists(i8* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %52
%57 = load i8*, i8** %7
%58 = call i64 @strlen(i8* %57)
store i64 %58, i64* %9
%59 = load i8*, i8** %6
%60 = load i8*, i8** %7
%61 = load i64, i64* %9
%62 = call i32 @memmove(i8* %59, i8* %60, i64 %61)
%63 = load i8*, i8** %6
%64 = load i64, i64* %9
%65 = getelementptr inbounds i8, i8* %63, i64 %64
store i8 0, i8* %65
br label %69
66: ; preds = %52
%67 = load i8*, i8** %6
%68 = getelementptr inbounds i8, i8* %67, i64 -1
store i8 0, i8* %68
br label %69
69: ; preds = %66, %56
%70 = load i8*, i8** %4
store i8* %70, i8** %3
br label %71
71: ; preds = %69, %19, %13
%72 = load i8*, i8** %3
ret i8* %72
}

LLVM IR (-O2):
define i8* @ensureFilesExist(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %39, label %4
4: ; preds = %2
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %39, label %7
7: ; preds = %4
%8 = tail call i8* @strchr(i8* %1, i8 signext 124)
%9 = icmp eq i8* %8, null
br i1 %9, label %28, label %10
10: ; preds = %7, %23
%11 = phi i8* [ %26, %23 ], [ %8, %7 ]
%12 = phi i8* [ %25, %23 ], [ %1, %7 ]
%13 = phi i8* [ %24, %23 ], [ %0, %7 ]
%14 = ptrtoint i8* %11 to i64
%15 = ptrtoint i8* %12 to i64
%16 = sub i64 %14, %15
%17 = tail call i32 @memmove(i8* %13, i8* %12, i64 %16)
%18 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %18
%19 = tail call i64 @fileExists(i8* %13)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %10
store i8 124, i8* %18
%22 = getelementptr inbounds i8, i8* %18, i64 1
br label %23
23: ; preds = %21, %10
%24 = phi i8* [ %22, %21 ], [ %13, %10 ]
%25 = getelementptr inbounds i8, i8* %11, i64 1
%26 = tail call i8* @strchr(i8* %25, i8 signext 124)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %10
28: ; preds = %23, %7
%29 = phi i8* [ %0, %7 ], [ %24, %23 ]
%30 = phi i8* [ %1, %7 ], [ %25, %23 ]
%31 = tail call i64 @fileExists(i8* %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = tail call i64 @strlen(i8* %30)
%35 = tail call i32 @memmove(i8* %29, i8* %30, i64 %34)
br label %36
36: ; preds = %28, %33
%37 = phi i64 [ %34, %33 ], [ -1, %28 ]
%38 = getelementptr inbounds i8, i8* %29, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %36, %4, %2
%40 = phi i8* [ null, %2 ], [ null, %4 ], [ %0, %36 ]
ret i8* %40
}