#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 */
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ err_exit(char *, char *);
scalar_t__ rmdir(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, int);
scalar_t__ unlink(char *);
void fsobj_destroy(char **searchpath, int length, int files) {
  char path[PATH_MAX + 1];
  int i, j, fd;
  for (i = 0; i < length; i++) {
    for (j = 0; j < files; j++) {
      snprintf(path, sizeof(path), "%s/%d.%d", searchpath[i], i, j);
      if ((unlink(path)) < 0)
        err_exit("unlink %s", path);
    }
    if (rmdir(searchpath[i]) < 0)
      err_exit("mkdir %s", searchpath[i]);
  }
}


x86 assembly (clang, -O0):
<fsobj_destroy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1251 <fsobj_destroy+0x111>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    120b <fsobj_destroy+0xcb>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
lea    0xe30(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    11f8 <fsobj_destroy+0xb8>
mov    -0x38(%rbp),%rsi
lea    0xe16(%rip),%rdi
call   1060 <err_exit@plt>
jmp    11fd <fsobj_destroy+0xbd>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119f <fsobj_destroy+0x5f>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <rmdir@plt>
cmp    $0x0,%rax
jge    123e <fsobj_destroy+0xfe>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdda(%rip),%rdi
call   1060 <err_exit@plt>
jmp    1243 <fsobj_destroy+0x103>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118c <fsobj_destroy+0x4c>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsobj_destroy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,-0x2c(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%r13
mov    %rax,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
test   %esi,%esi
jle    1225 <fsobj_destroy+0xe5>
mov    %rdi,%r12
mov    %esi,%eax
mov    %rax,-0x38(%rbp)
xor    %ebx,%ebx
jmp    11a8 <fsobj_destroy+0x68>
nopl   0x0(%rax)
mov    (%r12,%rbx,8),%rdi
call   1040 <rmdir@plt>
test   %rax,%rax
js     1210 <fsobj_destroy+0xd0>
add    $0x1,%rbx
cmp    -0x38(%rbp),%rbx
je     1225 <fsobj_destroy+0xe5>
cmpl   $0x0,-0x2c(%rbp)
jle    1190 <fsobj_destroy+0x50>
xor    %r15d,%r15d
jmp    11ca <fsobj_destroy+0x8a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15d
cmp    %r15d,-0x2c(%rbp)
je     1190 <fsobj_destroy+0x50>
mov    (%r12,%rbx,8),%rcx
mov    %r13,%rdi
mov    %r14d,%esi
lea    0xe25(%rip),%rdx
mov    %ebx,%r8d
mov    %r15d,%r9d
call   1050 <snprintf@plt>
mov    %r13,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
jns    11c0 <fsobj_destroy+0x80>
lea    0xe0f(%rip),%rdi
mov    %r13,%rsi
call   1060 <err_exit@plt>
jmp    11c0 <fsobj_destroy+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbx,8),%rsi
lea    0xdf8(%rip),%rdi
call   1060 <err_exit@plt>
jmp    119e <fsobj_destroy+0x5e>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [9 x i8] c"%s/%d.%d\00"
@.str.1 = [10 x i8] c"unlink %s\00"
@.str.2 = [9 x i8] c"mkdir %s\00"
define void @fsobj_destroy(i8** %0, i32 %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* @PATH_MAX
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca i8, i64 %14
store i64 %14, i64* %8
store i32 0, i32* %9
br label %17
17: ; preds = %60, %3
%18 = load i32, i32* %9
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %63
21: ; preds = %17
store i32 0, i32* %10
br label %22
22: ; preds = %41, %21
%23 = load i32, i32* %10
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %44
26: ; preds = %22
%27 = trunc i64 %14 to i32
%28 = load i8**, i8*** %4
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = call i32 @snprintf(i8* %16, i32 %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %32, i32 %33, i32 %34)
%36 = call i64 @unlink(i8* %16)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %26
%39 = call i32 @err_exit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %40
40: ; preds = %38, %26
br label %41
41: ; preds = %40
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %22
44: ; preds = %22
%45 = load i8**, i8*** %4
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i64 @rmdir(i8* %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %59
52: ; preds = %44
%53 = load i8**, i8*** %4
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %52, %44
br label %60
60: ; preds = %59
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %17
63: ; preds = %17
%64 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [9 x i8] c"%s/%d.%d\00"
@.str.1 = [10 x i8] c"unlink %s\00"
@.str.2 = [9 x i8] c"mkdir %s\00"
define void @fsobj_destroy(i8** nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @PATH_MAX
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %39
9: ; preds = %3
%10 = icmp sgt i32 %2, 0
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %9, %36
%13 = phi i64 [ 0, %9 ], [ %37, %36 ]
br i1 %10, label %14, label %28
14: ; preds = %12
%15 = getelementptr inbounds i8*, i8** %0, i64 %13
%16 = trunc i64 %13 to i32
br label %17
17: ; preds = %14, %25
%18 = phi i32 [ 0, %14 ], [ %26, %25 ]
%19 = load i8*, i8** %15
%20 = call i32 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %16, i32 %18)
%21 = call i64 @unlink(i8* %7)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @err_exit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %25
25: ; preds = %17, %23
%26 = add nuw nsw i32 %18, 1
%27 = icmp eq i32 %26, %2
br i1 %27, label %28, label %17
28: ; preds = %25, %12
%29 = getelementptr inbounds i8*, i8** %0, i64 %13
%30 = load i8*, i8** %29
%31 = call i64 @rmdir(i8* %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i8*, i8** %29
%35 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %28, %33
%37 = add nuw nsw i64 %13, 1
%38 = icmp eq i64 %37, %11
br i1 %38, label %39, label %12
39: ; preds = %36, %3
ret void
}