#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 *basename(char *);
char *dirname(char *);
int /*<<< orphan*/ fail(char *);
int /*<<< orphan*/ free(char **);
char **malloc(int);
scalar_t__ rm_file(char const **, int, char *);
char *strdup(char *);
char **tokenize(char *, int *, char *);
void fs_rm(char *filepath) {
  char *dirc, *basec, *p, *f;
  dirc = strdup(filepath);
  basec = strdup(filepath);
  p = dirname(dirc);
  f = basename(basec);
  char **path = NULL;
  int depth = 0;
  if (p[0] == '.') {
    path = malloc(sizeof(char));
    path[0] = "";
  } else
    path = tokenize(p, &depth, "/\0");
  if (rm_file((const char **)path, depth, f) < 0)
    fail("'rm' failed!\n");
  free(path);
}


x86 assembly (clang, -O0):
<fs_rm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <dirname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <basename@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1200 <fs_rm+0x80>
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
lea    0xe15(%rip),%rcx
mov    %rcx,(%rax)
jmp    1218 <fs_rm+0x98>
mov    -0x20(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    0xdff(%rip),%rdx
call   1080 <tokenize@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1090 <rm_file@plt>
cmp    $0x0,%rax
jge    123e <fs_rm+0xbe>
lea    0xdc7(%rip),%rdi
call   1040 <fail@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_rm>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   10a0 <strdup@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   10a0 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <dirname@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <basename@plt>
mov    %rax,%r14
movl   $0x0,0xc(%rsp)
cmpb   $0x2e,(%r15)
jne    11de <fs_rm+0x5e>
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe36(%rip),%rax
mov    %rax,(%rbx)
xor    %esi,%esi
jmp    11f9 <fs_rm+0x79>
lea    0xe29(%rip),%rdx
lea    0xc(%rsp),%rsi
mov    %r15,%rdi
call   1080 <tokenize@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1090 <rm_file@plt>
test   %rax,%rax
jns    1215 <fs_rm+0x95>
lea    0xdf0(%rip),%rdi
call   1040 <fail@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"/\00\00"
@.str.2 = [14 x i8] c"'rm' failed!\0A\00"
define void @fs_rm(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %3
%14 = call i8* @dirname(i8* %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %4
%16 = call i8* @basename(i8* %15)
store i8* %16, i8** %6
store i8** null, i8*** %7
store i32 0, i32* %8
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 46
br i1 %21, label %22, label %26
22: ; preds = %1
%23 = call i8** @malloc(i32 1)
store i8** %23, i8*** %7
%24 = load i8**, i8*** %7
%25 = getelementptr inbounds i8*, i8** %24, i64 0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %25
br label %29
26: ; preds = %1
%27 = load i8*, i8** %5
%28 = call i8** @tokenize(i8* %27, i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8** %28, i8*** %7
br label %29
29: ; preds = %26, %22
%30 = load i8**, i8*** %7
%31 = load i32, i32* %8
%32 = load i8*, i8** %6
%33 = call i64 @rm_file(i8** %30, i32 %31, i8* %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @fail(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load i8**, i8*** %7
%39 = call i32 @free(i8** %38)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"/\00\00"
@.str.2 = [14 x i8] c"'rm' failed!\0A\00"
define void @fs_rm(i8* nocapture %0) {
%2 = alloca i32
%3 = tail call i8* @strdup(i8* %0)
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i8* @dirname(i8* %3)
%6 = tail call i8* @basename(i8* %4)
%7 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 46
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i8** @malloc(i32 1)
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %11
br label %15
12: ; preds = %1
%13 = call i8** @tokenize(i8* %5, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %2
br label %15
15: ; preds = %12, %10
%16 = phi i32 [ 0, %10 ], [ %14, %12 ]
%17 = phi i8** [ %11, %10 ], [ %13, %12 ]
%18 = call i64 @rm_file(i8** %17, i32 %16, i8* %6)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @fail(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = call i32 @free(i8** %17)
ret void
}