#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;
  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,-0x38(%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,-0x30(%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    -0x30(%rbp),%rdi
mov    -0x38(%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    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    11f8 <fsobj_destroy+0xb8>
mov    -0x30(%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
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
store i32 0, i32* %9
br label %16
16: ; preds = %59, %3
%17 = load i32, i32* %9
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %62
20: ; preds = %16
store i32 0, i32* %10
br label %21
21: ; preds = %40, %20
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %21
%26 = trunc i64 %13 to i32
%27 = load i8**, i8*** %4
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* %9
%33 = load i32, i32* %10
%34 = call i32 @snprintf(i8* %15, i32 %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %31, i32 %32, i32 %33)
%35 = call i64 @unlink(i8* %15)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = call i32 @err_exit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %39
39: ; preds = %37, %25
br label %40
40: ; preds = %39
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %21
43: ; preds = %21
%44 = load i8**, i8*** %4
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i64 @rmdir(i8* %48)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %43
%52 = load i8**, i8*** %4
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %51, %43
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %16
62: ; preds = %16
%63 = 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
}