#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__ disk_alloc_delete(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int disk_del(int i, char *arg_loc) {
  char *test_loc = (char *)malloc(sizeof(char) * 20);
  while (i > -1) {
    sprintf(test_loc, "%s%d/", arg_loc, i);
    printf("\nAttempting delete of %s.\n", test_loc);
    while (disk_alloc_delete(test_loc) < 0) {
      printf("couldn't delete %s, still trying...\n", test_loc);
      sleep(1);
    }
    printf("Disk allocation cleaned and removed.\n");
    i--;
  }
  free(test_loc);
  return 0;
}


x86 assembly (clang, -O0):
<disk_del>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jle    1200 <disk_del+0xa0>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    0xe67(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <disk_alloc_delete@plt>
cmp    $0x0,%rax
jge    11e4 <disk_del+0x84>
mov    -0x18(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11b0 <disk_del+0x50>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    117d <disk_del+0x1d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_del>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %r15d,%r15d
js     1216 <disk_del+0xa6>
lea    0xe68(%rip),%r13
lea    0xe7c(%rip),%rbp
lea    0xe9a(%rip),%r12
jmp    11c4 <disk_del+0x54>
xchg   %ax,%ax
mov    %r12,%rdi
call   1040 <puts@plt>
lea    -0x1(%r15),%eax
test   %r15d,%r15d
mov    %eax,%r15d
jle    1216 <disk_del+0xa6>
mov    %rbx,%rdi
lea    0xe32(%rip),%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1080 <sprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <disk_alloc_delete@plt>
test   %rax,%rax
jns    11b0 <disk_del+0x40>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    11f0 <disk_del+0x80>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s%d/\00"
@.str.1 = [27 x i8] c"\0AAttempting delete of %s.\0A\00"
@.str.2 = [37 x i8] c"couldn't delete %s, still trying...\0A\00"
@.str.3 = [38 x i8] c"Disk allocation cleaned and removed.\0A\00"
define i32 @disk_del(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = call i64 @malloc(i32 20)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %5
br label %8
8: ; preds = %26, %2
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %30
11: ; preds = %8
%12 = load i8*, i8** %5
%13 = load i8*, i8** %4
%14 = load i32, i32* %3
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14)
%16 = load i8*, i8** %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %22, %11
%19 = load i8*, i8** %5
%20 = call i64 @disk_alloc_delete(i8* %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @sleep(i32 1)
br label %18
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
br label %8
30: ; preds = %8
%31 = load i8*, i8** %5
%32 = call i32 @free(i8* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s%d/\00"
@.str.1 = [27 x i8] c"\0AAttempting delete of %s.\0A\00"
@.str.2 = [37 x i8] c"couldn't delete %s, still trying...\0A\00"
@str = [37 x i8] c"Disk allocation cleaned and removed.\00"
define i32 @disk_del(i32 %0, i8* %1) {
%3 = tail call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i8*
%5 = icmp sgt i32 %0, -1
br i1 %5, label %6, label %21
6: ; preds = %2, %17
%7 = phi i32 [ %19, %17 ], [ %0, %2 ]
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%10 = tail call i64 @disk_alloc_delete(i8* %4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %6, %12
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i64 @disk_alloc_delete(i8* %4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12, %6
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%19 = add nsw i32 %7, -1
%20 = icmp sgt i32 %7, 0
br i1 %20, label %6, label %21
21: ; preds = %17, %2
%22 = tail call i32 @free(i8* %4)
ret i32 0
}