#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*/ strncpy(char *const, char const *const, int);
char *strrchr(char const *const, int);
char *getPathWithoutFinalSlash(char *const aoDestination,
                               char const *const aSource) {
  char const *lTmp;
  if (aSource) {
    lTmp = strrchr(aSource, (int)*"/");
    if (!lTmp) {
      lTmp = strrchr(aSource, (int)*"\\");
    }
    if (lTmp) {
      strncpy(aoDestination, aSource, lTmp - aSource);
      aoDestination[lTmp - aSource] = '\0';
    } else {
      *aoDestination = '\0';
    }
  } else {
    *aoDestination = '\0';
  }
  return aoDestination;
}


x86 assembly (clang, -O0):
<getPathWithoutFinalSlash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b7 <getPathWithoutFinalSlash+0x97>
mov    -0x10(%rbp),%rdi
movsbl 0xeba(%rip),%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116e <getPathWithoutFinalSlash+0x4e>
mov    -0x10(%rbp),%rdi
movsbl 0xe9d(%rip),%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ab <getPathWithoutFinalSlash+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11b2 <getPathWithoutFinalSlash+0x92>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11be <getPathWithoutFinalSlash+0x9e>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPathWithoutFinalSlash>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %rdi,%rax
test   %rsi,%rsi
je     1176 <getPathWithoutFinalSlash+0x56>
mov    %rsi,%r15
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <getPathWithoutFinalSlash+0x40>
mov    %r15,%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
mov    %r14,%rax
test   %rbx,%rbx
je     1176 <getPathWithoutFinalSlash+0x56>
sub    %r15,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
add    %r14,%rbx
mov    %rbx,%rax
movb   $0x0,(%rax)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c"\\\00"
define i8* @getPathWithoutFinalSlash(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %43
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%11 = sext i8 %10 to i32
%12 = call i8* @strrchr(i8* %9, i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %8
%16 = load i8*, i8** %4
%17 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%18 = sext i8 %17 to i32
%19 = call i8* @strrchr(i8* %16, i32 %18)
store i8* %19, i8** %5
br label %20
20: ; preds = %15, %8
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = load i8*, i8** %4
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
%32 = call i32 @strncpy(i8* %24, i8* %25, i32 %31)
%33 = load i8*, i8** %3
%34 = load i8*, i8** %5
%35 = load i8*, i8** %4
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = getelementptr inbounds i8, i8* %33, i64 %38
store i8 0, i8* %39
br label %42
40: ; preds = %20
%41 = load i8*, i8** %3
store i8 0, i8* %41
br label %42
42: ; preds = %40, %23
br label %45
43: ; preds = %2
%44 = load i8*, i8** %3
store i8 0, i8* %44
br label %45
45: ; preds = %43, %42
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
define i8* @getPathWithoutFinalSlash(i8* returned %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %18, label %4
4: ; preds = %2
%5 = tail call i8* @strrchr(i8* %1, i32 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i8* @strrchr(i8* %1, i32 92)
%9 = icmp eq i8* %8, null
br i1 %9, label %18, label %10
10: ; preds = %4, %7
%11 = phi i8* [ %8, %7 ], [ %5, %4 ]
%12 = ptrtoint i8* %11 to i64
%13 = ptrtoint i8* %1 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %15)
%17 = getelementptr inbounds i8, i8* %0, i64 %14
br label %18
18: ; preds = %2, %7, %10
%19 = phi i8* [ %17, %10 ], [ %0, %7 ], [ %0, %2 ]
store i8 0, i8* %19
ret i8* %0
}