#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, char);
char *getPathWithoutFinalSlash(char *const aoDestination,
                               char const *const aSource) {
  char const *lTmp;
  if (aSource) {
    lTmp = strrchr(aSource, '/');
    if (!lTmp) {
      lTmp = strrchr(aSource, '\\');
    }
    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     11b3 <getPathWithoutFinalSlash+0x93>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116a <getPathWithoutFinalSlash+0x4a>
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a7 <getPathWithoutFinalSlash+0x87>
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    11ae <getPathWithoutFinalSlash+0x8e>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11ba <getPathWithoutFinalSlash+0x9a>
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):
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 %39
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = call i8* @strrchr(i8* %9, i8 signext 47)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = call i8* @strrchr(i8* %14, i8 signext 92)
store i8* %15, i8** %5
br label %16
16: ; preds = %13, %8
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %36
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = load i8*, i8** %4
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
%28 = call i32 @strncpy(i8* %20, i8* %21, i32 %27)
%29 = load i8*, i8** %3
%30 = load i8*, i8** %5
%31 = load i8*, i8** %4
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = getelementptr inbounds i8, i8* %29, i64 %34
store i8 0, i8* %35
br label %38
36: ; preds = %16
%37 = load i8*, i8** %3
store i8 0, i8* %37
br label %38
38: ; preds = %36, %19
br label %41
39: ; preds = %2
%40 = load i8*, i8** %3
store i8 0, i8* %40
br label %41
41: ; preds = %39, %38
%42 = load i8*, i8** %3
ret i8* %42
}

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, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i8* @strrchr(i8* %1, i8 signext 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
}