#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 *);
int /*<<< orphan*/ e(int);
scalar_t__ strcmp(char *, char *);
char *remove_last_path_component(char *path) {
  char *current, *last;
  assert(path);
  last = NULL;
  for (current = path; *current; current++)
    if (*current == '/')
      last = current;
  if (last) {
    if (strcmp(last + 1, ".") == 0)
      (e(62));
    if (strcmp(last + 1, "..") == 0)
      (e(63));
  }
  if (last <= path)
    return NULL;
  *last = 0;
  return path;
}


x86 assembly (clang, -O0):
<remove_last_path_component>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1190 <remove_last_path_component+0x60>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    117a <remove_last_path_component+0x4a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    117f <remove_last_path_component+0x4f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <remove_last_path_component+0x25>
cmpq   $0x0,-0x20(%rbp)
je     11f0 <remove_last_path_component+0xc0>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe57(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11c3 <remove_last_path_component+0x93>
mov    $0x3e,%edi
call   1050 <e@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
lea    0xe2e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11eb <remove_last_path_component+0xbb>
mov    $0x3f,%edi
call   1050 <e@plt>
jmp    11f0 <remove_last_path_component+0xc0>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     120b <remove_last_path_component+0xdb>
movq   $0x0,-0x8(%rbp)
jmp    121a <remove_last_path_component+0xea>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_last_path_component>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <assert@plt>
xor    %ebx,%ebx
mov    %r15,%rax
jmp    1157 <remove_last_path_component+0x27>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rbx
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x2f,%cl
je     1150 <remove_last_path_component+0x20>
test   %cl,%cl
jne    1153 <remove_last_path_component+0x23>
test   %rbx,%rbx
je     119e <remove_last_path_component+0x6e>
lea    0x1(%rbx),%r14
lea    0xe8e(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    118a <remove_last_path_component+0x5a>
mov    $0x3e,%edi
call   1050 <e@plt>
lea    0xe6f(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11a8 <remove_last_path_component+0x78>
cmp    %r15,%rbx
jbe    11b7 <remove_last_path_component+0x87>
movb   $0x0,(%rbx)
jmp    11ba <remove_last_path_component+0x8a>
mov    $0x3f,%edi
call   1050 <e@plt>
cmp    %r15,%rbx
ja     11a3 <remove_last_path_component+0x73>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i8* @remove_last_path_component(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
br label %3
3: ; preds = %8, %1
%4 = phi i8* [ %0, %1 ], [ %10, %8 ]
%5 = phi i8* [ null, %1 ], [ %9, %8 ]
%6 = load i8, i8* %4
switch i8 %6, label %8 [
i8 0, label %11
i8 47, label %7
]
7: ; preds = %3
br label %8
8: ; preds = %3, %7
%9 = phi i8* [ %4, %7 ], [ %5, %3 ]
%10 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
11: ; preds = %3
%12 = icmp eq i8* %5, null
br i1 %12, label %24, label %13
13: ; preds = %11
%14 = getelementptr inbounds i8, i8* %5, i64 1
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @e(i32 62)
br label %19
19: ; preds = %17, %13
%20 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @e(i32 63)
br label %24
24: ; preds = %19, %22, %11
%25 = icmp ugt i8* %5, %0
br i1 %25, label %26, label %27
26: ; preds = %24
store i8 0, i8* %5
br label %27
27: ; preds = %24, %26
%28 = phi i8* [ %0, %26 ], [ null, %24 ]
ret i8* %28
}