#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 */
int /*<<< orphan*/ strcat_s(char *, int, char const *);
int /*<<< orphan*/ strcpy_s(char *, int, char const *);
int strlen(char *);
void CatPath(char *BasePath, const char *FilePath) {
  int l;
  l = strlen(BasePath);
  if (FilePath[1] == ':') {
    l = 0;
  }
  if (FilePath[0] == '/' || FilePath[0] == '.' || l == 0) {
    strcpy_s(BasePath, 1024 * 2, FilePath);
    return;
  }
  if (BasePath[l - 1] != '/') {
    BasePath[l++] = '/';
    BasePath[l] = 0;
  }
  strcat_s(BasePath, 1024 * 2, FilePath);
}


x86 assembly (clang, -O0):
<CatPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3a,%eax
jne    1164 <CatPath+0x34>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     118e <CatPath+0x5e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     118e <CatPath+0x5e>
cmpl   $0x0,-0x14(%rbp)
jne    11a5 <CatPath+0x75>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1050 <strcpy_s@plt>
jmp    11f3 <CatPath+0xc3>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11e1 <CatPath+0xb1>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1040 <strcat_s@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CatPath>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
xor    %ecx,%ecx
cmpb   $0x3a,0x1(%rbx)
mov    (%rbx),%dl
cmovne %eax,%ecx
cmp    $0x2f,%dl
je     1181 <CatPath+0x51>
cmp    $0x2e,%dl
je     1181 <CatPath+0x51>
test   %ecx,%ecx
je     1181 <CatPath+0x51>
movslq %ecx,%rax
cmpb   $0x2f,-0x1(%rax,%r14,1)
je     116a <CatPath+0x3a>
movw   $0x2f,(%r14,%rax,1)
mov    %r14,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strcat_s@plt>
mov    %r14,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strcpy_s@plt>

LLVM IR (-O0):
define void @CatPath(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 58
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %5
br label %14
14: ; preds = %13, %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %29, label %20
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 46
br i1 %25, label %29, label %26
26: ; preds = %20
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26, %20, %14
%30 = load i8*, i8** %3
%31 = load i8*, i8** %4
%32 = call i32 @strcpy_s(i8* %30, i32 2048, i8* %31)
br label %56
33: ; preds = %26
%34 = load i8*, i8** %3
%35 = load i32, i32* %5
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 47
br i1 %41, label %42, label %52
42: ; preds = %33
%43 = load i8*, i8** %3
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8 47, i8* %47
%48 = load i8*, i8** %3
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %42, %33
%53 = load i8*, i8** %3
%54 = load i8*, i8** %4
%55 = call i32 @strcat_s(i8* %53, i32 2048, i8* %54)
br label %56
56: ; preds = %52, %29
ret void
}

LLVM IR (-O2):
define void @CatPath(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = getelementptr inbounds i8, i8* %1, i64 1
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 58
%7 = select i1 %6, i32 0, i32 %3
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 47
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = icmp eq i8 %8, 46
%12 = icmp eq i32 %7, 0
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %16
14: ; preds = %10, %2
%15 = tail call i32 @strcpy_s(i8* %0, i32 2048, i8* %1)
br label %30
16: ; preds = %10
%17 = add nsw i32 %7, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 47
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = add nsw i32 %7, 1
%24 = sext i32 %7 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 47, i8* %25
%26 = sext i32 %23 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %22, %16
%29 = tail call i32 @strcat_s(i8* %0, i32 2048, i8* %1)
br label %30
30: ; preds = %28, %14
ret void
}