#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*/ free(char *);
char *malloc_nofail(scalar_t__);
int rmdir(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *strrchr(char *, char);
void remove_parents(const char *filename) {
  char *fn = malloc_nofail(strlen(filename) + 1), *f;
  strcpy(fn, filename);
  f = strrchr(fn, '/');
  if (f == NULL)
    goto out;
  do {
    *f = '\0';
    if (rmdir(fn) == -1)
      goto out;
  } while ((f = strrchr(fn, '/')) != NULL);
  rmdir(fn);
out:
  free(fn);
}


x86 assembly (clang, -O0):
<remove_parents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1030 <malloc_nofail@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <remove_parents+0x54>
jmp    1201 <remove_parents+0xa1>
jmp    11b9 <remove_parents+0x59>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <rmdir@plt>
cmp    $0xffffffff,%eax
jne    11d7 <remove_parents+0x77>
jmp    1201 <remove_parents+0xa1>
jmp    11dc <remove_parents+0x7c>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b9 <remove_parents+0x59>
mov    -0x10(%rbp),%rdi
call   1060 <rmdir@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_parents>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1070 <strlen@plt>
lea    0x1(%rax),%rdi
call   1030 <malloc_nofail@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
je     11ca <remove_parents+0x6a>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1060 <rmdir@plt>
cmp    $0xffffffff,%eax
je     11ca <remove_parents+0x6a>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
jne    11a0 <remove_parents+0x40>
mov    %rbx,%rdi
call   1060 <rmdir@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <free@plt>

LLVM IR (-O0):
define void @remove_parents(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = add nsw i64 %6, 1
%8 = call i8* @malloc_nofail(i64 %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = load i8*, i8** %2
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = load i8*, i8** %3
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %1
br label %32
17: ; preds = %1
br label %18
18: ; preds = %25, %17
%19 = load i8*, i8** %4
store i8 0, i8* %19
%20 = load i8*, i8** %3
%21 = call i32 @rmdir(i8* %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %18
br label %32
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i8*, i8** %3
%27 = call i8* @strrchr(i8* %26, i8 signext 47)
store i8* %27, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %18, label %29
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = call i32 @rmdir(i8* %30)
br label %32
32: ; preds = %29, %23, %16
%33 = load i8*, i8** %3
%34 = call i32 @free(i8* %33)
ret void
}

LLVM IR (-O2):
define void @remove_parents(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @malloc_nofail(i64 %3)
%5 = tail call i32 @strcpy(i8* %4, i8* %0)
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %4, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %1, %12
%9 = phi i8* [ %13, %12 ], [ %6, %1 ]
store i8 0, i8* %9
%10 = tail call i32 @rmdir(i8* %4)
%11 = icmp eq i32 %10, -1
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = tail call i8* @strrchr(i8* dereferenceable(1) %4, i8 signext 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %8
15: ; preds = %12
%16 = tail call i32 @rmdir(i8* %4)
br label %17
17: ; preds = %8, %1, %15
%18 = tail call i32 @free(i8* %4)
ret void
}