#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 */
scalar_t__ rmdir(char *);
char *strrchr(char *, char);
int /*<<< orphan*/ warn(char *, char *);
int rm_path(char *path) {
  char *p;
  while ((p = strrchr(path, '/')) != NULL) {
    *p = 0;
    if (p[1] == 0)
      continue;
    if (*path == 0)
      break;
    if (rmdir(path) < 0) {
      warn("%s", path);
      return (1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<rm_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11be <rm_path+0x8e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1175 <rm_path+0x45>
jmp    113c <rm_path+0xc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    118a <rm_path+0x5a>
jmp    11be <rm_path+0x8e>
mov    -0x10(%rbp),%rdi
call   1040 <rmdir@plt>
cmp    $0x0,%rax
jge    11b9 <rm_path+0x89>
mov    -0x10(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1030 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <rm_path+0x95>
jmp    113c <rm_path+0xc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_path>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
xor    %ebp,%ebp
jmp    115d <rm_path+0x2d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1191 <rm_path+0x61>
movb   $0x0,(%rax)
cmpb   $0x0,0x1(%rax)
je     1150 <rm_path+0x20>
cmpb   $0x0,(%rbx)
je     1191 <rm_path+0x61>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
test   %rax,%rax
jns    1150 <rm_path+0x20>
lea    0xe7c(%rip),%rdi
mov    %rbx,%rsi
call   1030 <warn@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @rm_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
br label %5
5: ; preds = %30, %16, %1
%6 = load i8*, i8** %3
%7 = call i8* @strrchr(i8* %6, i8 signext 47)
store i8* %7, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %31
9: ; preds = %5
%10 = load i8*, i8** %4
store i8 0, i8* %10
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
br label %5
17: ; preds = %9
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %31
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = call i64 @rmdir(i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = call i32 @warn(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %28)
store i32 1, i32* %2
br label %32
30: ; preds = %23
br label %5
31: ; preds = %22, %5
store i32 0, i32* %2
br label %32
32: ; preds = %31, %27
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @rm_path(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %20, label %4
4: ; preds = %1, %9
%5 = phi i8* [ %10, %9 ], [ %2, %1 ]
store i8 0, i8* %5
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4, %15
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %20, label %4
12: ; preds = %4
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = tail call i64 @rmdir(i8* %0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %9
18: ; preds = %15
%19 = tail call i32 @warn(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %20
20: ; preds = %12, %9, %1, %18
%21 = phi i32 [ 1, %18 ], [ 0, %1 ], [ 0, %9 ], [ 0, %12 ]
ret i32 %21
}