#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 */
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void remove_last_element_from_pathname(char *path) {
  size_t i;
  if (strncmp(path, "/", 1) == 0)
    return;
  for (i = strlen(path); i > 0; i--) {
    if (path[i] == '\\')
      break;
    path[i] = '\0';
  }
}


x86 assembly (clang, -O0):
<remove_last_element_from_pathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec9(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1150 <remove_last_element_from_pathname+0x30>
jmp    119f <remove_last_element_from_pathname+0x7f>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    119f <remove_last_element_from_pathname+0x7f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    1182 <remove_last_element_from_pathname+0x62>
jmp    119f <remove_last_element_from_pathname+0x7f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    115d <remove_last_element_from_pathname+0x3d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_last_element_from_pathname>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1160 <remove_last_element_from_pathname+0x40>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1160 <remove_last_element_from_pathname+0x40>
nopw   0x0(%rax,%rax,1)
cmpb   $0x5c,(%rbx,%rax,1)
je     1160 <remove_last_element_from_pathname+0x40>
movb   $0x0,(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
jne    1150 <remove_last_element_from_pathname+0x30>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define void @remove_last_element_from_pathname(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
br label %29
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %3
br label %11
11: ; preds = %26, %8
%12 = load i64, i64* %3
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = load i64, i64* %3
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 92
br i1 %20, label %21, label %22
21: ; preds = %14
br label %29
22: ; preds = %14
%23 = load i8*, i8** %2
%24 = load i64, i64* %3
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %22
%27 = load i64, i64* %3
%28 = add i64 %27, -1
store i64 %28, i64* %3
br label %11
29: ; preds = %7, %21, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @remove_last_element_from_pathname(i8* %0) {
%2 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %4, %12
%8 = phi i64 [ %13, %12 ], [ %5, %4 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 92
br i1 %11, label %15, label %12
12: ; preds = %7
store i8 0, i8* %9
%13 = add i64 %8, -1
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %12, %4, %1
ret void
}