#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 */
unsigned int file_LatestSlash(char *);
int /*<<< orphan*/ file_MakeSlashesNative(char *);
int strlen(char *);
void file_StripComponentFromPath(char *path) {
  file_MakeSlashesNative(path);
  int repeat = 1;
  while (repeat) {
    repeat = 0;
    if (strlen(path) > 0) {
      unsigned int slashpos = file_LatestSlash(path);
      if (slashpos > 0) {
        if (slashpos >= strlen(path) - 1) {
          repeat = 1;
        }
        path[slashpos] = 0;
      } else {
        path[0] = 0;
      }
    }
  }
}


x86 assembly (clang, -O0):
<file_StripComponentFromPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <file_MakeSlashesNative@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11cc <file_StripComponentFromPath+0x9c>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    11c7 <file_StripComponentFromPath+0x97>
mov    -0x8(%rbp),%rdi
call   1030 <file_LatestSlash@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jbe    11bb <file_StripComponentFromPath+0x8b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jb     11ab <file_StripComponentFromPath+0x7b>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    11c2 <file_StripComponentFromPath+0x92>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11c7 <file_StripComponentFromPath+0x97>
jmp    114c <file_StripComponentFromPath+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_StripComponentFromPath>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <file_MakeSlashesNative@plt>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1174 <file_StripComponentFromPath+0x44>
mov    %rbx,%rdi
call   1030 <file_LatestSlash@plt>
test   %eax,%eax
je     1171 <file_StripComponentFromPath+0x41>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%eax
mov    %ebp,%ecx
movb   $0x0,(%rbx,%rcx,1)
cmp    %eax,%ebp
jae    1140 <file_StripComponentFromPath+0x10>
jmp    1174 <file_StripComponentFromPath+0x44>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @file_StripComponentFromPath(i8* %0) {
%2 = tail call i32 @file_MakeSlashesNative(i8* %0)
br label %3
3: ; preds = %1, %10
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = tail call i32 @file_LatestSlash(i8* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %6
store i8 0, i8* %0
br label %16
10: ; preds = %6
%11 = tail call i32 @strlen(i8* %0)
%12 = add nsw i32 %11, -1
%13 = icmp ult i32 %7, %12
%14 = zext i32 %7 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
br i1 %13, label %16, label %3
16: ; preds = %3, %10, %9
ret void
}