#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 */
char *remove_last_path_component(char *path) {
  char *current, *slash;
  slash = NULL;
  for (current = path; *current; current++)
    if (*current == '/')
      slash = current;
  if (slash > path)
    *slash = 0;
  else if (slash == path)
    slash[1] = 0;
  return path;
}


x86 assembly (clang, -O0):
<remove_last_path_component>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1153 <remove_last_path_component+0x53>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    113d <remove_last_path_component+0x3d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1142 <remove_last_path_component+0x42>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1118 <remove_last_path_component+0x18>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    116d <remove_last_path_component+0x6d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1188 <remove_last_path_component+0x88>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1183 <remove_last_path_component+0x83>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1188 <remove_last_path_component+0x88>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_last_path_component>:
mov    %rdi,%rax
xor    %esi,%esi
mov    %rdi,%rdx
jmp    1117 <remove_last_path_component+0x17>
nopw   0x0(%rax,%rax,1)
mov    %rdx,%rsi
add    $0x1,%rdx
movzbl (%rdx),%ecx
cmp    $0x2f,%cl
je     1110 <remove_last_path_component+0x10>
test   %cl,%cl
jne    1113 <remove_last_path_component+0x13>
cmp    %rax,%rsi
ja     112f <remove_last_path_component+0x2f>
je     112b <remove_last_path_component+0x2b>
ret
lea    0x1(%rax),%rsi
movb   $0x0,(%rsi)
ret

LLVM IR (-O0):
define i8* @remove_last_path_component(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %4
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %18, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 47
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i8*, i8** %3
store i8* %16, i8** %4
br label %17
17: ; preds = %15, %10
br label %18
18: ; preds = %17
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
br label %6
21: ; preds = %6
%22 = load i8*, i8** %4
%23 = load i8*, i8** %2
%24 = icmp ugt i8* %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i8*, i8** %4
store i8 0, i8* %26
br label %35
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = load i8*, i8** %2
%30 = icmp eq i8* %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 0, i8* %33
br label %34
34: ; preds = %31, %27
br label %35
35: ; preds = %34, %25
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
define i8* @remove_last_path_component(i8* returned %0) {
br label %2
2: ; preds = %7, %1
%3 = phi i8* [ %0, %1 ], [ %9, %7 ]
%4 = phi i8* [ null, %1 ], [ %8, %7 ]
%5 = load i8, i8* %3
switch i8 %5, label %7 [
i8 0, label %10
i8 47, label %6
]
6: ; preds = %2
br label %7
7: ; preds = %2, %6
%8 = phi i8* [ %3, %6 ], [ %4, %2 ]
%9 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
10: ; preds = %2
%11 = icmp ugt i8* %4, %0
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = icmp eq i8* %4, %0
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = getelementptr inbounds i8, i8* %0, i64 1
br label %16
16: ; preds = %10, %14
%17 = phi i8* [ %15, %14 ], [ %4, %10 ]
store i8 0, i8* %17
br label %18
18: ; preds = %16, %12
ret i8* %0
}