#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*/ assert(char *);
char *strchr(char *, char);
void trim_trailing_slash_or_dot(char *path) {
  assert(path);
  char *end = strchr(path, '\0');
  if ((end - path) > 1) {
    end--;
    while (*end == '/' || (*end == '.' && *(end - 1) == '/')) {
      *end = '\0';
      end--;
      if (end == path)
        break;
    }
  }
}


x86 assembly (clang, -O0):
<trim_trailing_slash_or_dot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x1,%rax
jle    11e6 <trim_trailing_slash_or_dot+0xc6>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2f,%ecx
mov    %al,-0x11(%rbp)
je     11a6 <trim_trailing_slash_or_dot+0x86>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x12(%rbp)
jne    11a0 <trim_trailing_slash_or_dot+0x80>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11b6 <trim_trailing_slash_or_dot+0x96>
jmp    11e1 <trim_trailing_slash_or_dot+0xc1>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11dc <trim_trailing_slash_or_dot+0xbc>
jmp    11e1 <trim_trailing_slash_or_dot+0xc1>
jmp    1165 <trim_trailing_slash_or_dot+0x45>
jmp    11e6 <trim_trailing_slash_or_dot+0xc6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_trailing_slash_or_dot>:
push   %rbx
mov    %rdi,%rbx
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%rax
jl     115f <trim_trailing_slash_or_dot+0x3f>
add    $0xffffffffffffffff,%rax
jmp    114a <trim_trailing_slash_or_dot+0x2a>
nopl   (%rax)
movb   $0x0,(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
je     115f <trim_trailing_slash_or_dot+0x3f>
movzbl (%rbx,%rax,1),%ecx
cmp    $0x2f,%cl
je     1140 <trim_trailing_slash_or_dot+0x20>
cmp    $0x2e,%cl
jne    115f <trim_trailing_slash_or_dot+0x3f>
cmpb   $0x2f,-0x1(%rbx,%rax,1)
je     1140 <trim_trailing_slash_or_dot+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @trim_trailing_slash_or_dot(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @assert(i8* %4)
%6 = load i8*, i8** %2
%7 = call i8* @strchr(i8* %6, i8 signext 0)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = load i8*, i8** %2
%10 = ptrtoint i8* %8 to i64
%11 = ptrtoint i8* %9 to i64
%12 = sub i64 %10, %11
%13 = icmp sgt i64 %12, 1
br i1 %13, label %14, label %47
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** %3
br label %17
17: ; preds = %45, %14
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 47
br i1 %21, label %35, label %22
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 46
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 -1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br label %33
33: ; preds = %27, %22
%34 = phi i1 [ false, %22 ], [ %32, %27 ]
br label %35
35: ; preds = %33, %17
%36 = phi i1 [ true, %17 ], [ %34, %33 ]
br i1 %36, label %37, label %46
37: ; preds = %35
%38 = load i8*, i8** %3
store i8 0, i8* %38
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i32 -1
store i8* %40, i8** %3
%41 = load i8*, i8** %3
%42 = load i8*, i8** %2
%43 = icmp eq i8* %41, %42
br i1 %43, label %44, label %45
44: ; preds = %37
br label %46
45: ; preds = %37
br label %17
46: ; preds = %44, %35
br label %47
47: ; preds = %46, %1
ret void
}

LLVM IR (-O2):
define void @trim_trailing_slash_or_dot(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp sgt i64 %3, 1
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = getelementptr i8, i8* %0, i64 %3
%7 = getelementptr inbounds i8, i8* %6, i64 -1
br label %8
8: ; preds = %15, %5
%9 = phi i8* [ %7, %5 ], [ %16, %15 ]
%10 = load i8, i8* %9
switch i8 %10, label %18 [
i8 47, label %15
i8 46, label %11
]
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 -1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %15, label %18
15: ; preds = %8, %11
store i8 0, i8* %9
%16 = getelementptr inbounds i8, i8* %9, i64 -1
%17 = icmp eq i8* %16, %0
br i1 %17, label %18, label %8
18: ; preds = %8, %11, %15, %1
ret void
}