#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*/ memcpy(char *, char const *, unsigned int);
unsigned int strlen(char const *);
scalar_t__ xmalloc(unsigned int);
char *CleanupPath(const char *Path) {
  unsigned Len;
  char *NewPath;
  Len = strlen(Path);
  if (Len > 0 && (Path[Len - 1] == '\\' || Path[Len - 1] == '/')) {
    --Len;
  }
  NewPath = (char *)xmalloc(Len + 1);
  memcpy(NewPath, Path, Len);
  NewPath[Len] = '\0';
  return NewPath;
}


x86 assembly (clang, -O0):
<CleanupPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jbe    118d <CleanupPath+0x5d>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     1184 <CleanupPath+0x54>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    118d <CleanupPath+0x5d>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CleanupPath>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     115b <CleanupPath+0x2b>
mov    %eax,%r15d
lea    -0x1(%r15),%eax
mov    (%r14,%rax,1),%cl
cmp    $0x5c,%cl
je     1156 <CleanupPath+0x26>
cmp    $0x2f,%cl
jne    115e <CleanupPath+0x2e>
mov    %eax,%r15d
jmp    115e <CleanupPath+0x2e>
xor    %r15d,%r15d
lea    0x1(%r15),%edi
call   1040 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
mov    %r15d,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @CleanupPath(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ugt i32 %7, 0
br i1 %8, label %9, label %30
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sub i32 %11, 1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 92
br i1 %17, label %27, label %18
18: ; preds = %9
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = sub i32 %20, 1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 47
br i1 %26, label %27, label %30
27: ; preds = %18, %9
%28 = load i32, i32* %3
%29 = add i32 %28, -1
store i32 %29, i32* %3
br label %30
30: ; preds = %27, %18, %1
%31 = load i32, i32* %3
%32 = add i32 %31, 1
%33 = call i64 @xmalloc(i32 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %4
%35 = load i8*, i8** %4
%36 = load i8*, i8** %2
%37 = load i32, i32* %3
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
%39 = load i8*, i8** %4
%40 = load i32, i32* %3
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %4
ret i8* %43
}

LLVM IR (-O2):
define i8* @CleanupPath(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = add i32 %2, -1
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %10 [
i8 92, label %9
i8 47, label %9
]
9: ; preds = %4, %4
br label %10
10: ; preds = %4, %9, %1
%11 = phi i32 [ %5, %9 ], [ 0, %1 ], [ %2, %4 ]
%12 = add i32 %11, 1
%13 = tail call i64 @xmalloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @memcpy(i8* %14, i8* %0, i32 %11)
%16 = zext i32 %11 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 0, i8* %17
ret i8* %14
}