#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 */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, ...);
int rmdir(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i, rc = 0, count;
  char dirname[4096];
  if (argc < 3) {
    printf("Usage %s dirnamebase count\n", argv[0]);
    return 1;
  }
  if (strlen(argv[1]) > 4080) {
    printf("name too long\n");
    return 1;
  }
  count = strtoul(argv[2], NULL, 0);
  for (i = 0; i < count; i++) {
    sprintf(dirname, "%s-%d", argv[1], i);
    rc = rmdir(dirname);
    if (rc) {
      printf("rmdir(%s) error: %s\n", dirname, strerror(errno));
      break;
    }
    if ((i % 10000) == 0)
      printf(" - deleted %d (time %ld)\n", i, time(0));
  }
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bb <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d9 <main+0x169>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0xff0,%eax
jle    11ed <main+0x7d>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d9 <main+0x169>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12d3 <main+0x163>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x14(%rbp),%ecx
lea    0xdfc(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x1020(%rbp),%rdi
call   1030 <rmdir@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1286 <main+0x116>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1028(%rbp),%rsi
mov    %rax,%rdx
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d3 <main+0x163>
mov    -0x14(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12c0 <main+0x150>
mov    -0x14(%rbp),%eax
mov    %eax,-0x102c(%rbp)
xor    %edi,%edi
call   1060 <time@plt>
mov    -0x102c(%rbp),%esi
mov    %eax,%edx
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c5 <main+0x155>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120a <main+0x9a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     11b5 <main+0x35>
mov    (%rbx),%rsi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r12d
jmp    1293 <main+0x113>
mov    0x8(%rbx),%rdi
call   1050 <strlen@plt>
cmp    $0xff1,%eax
jl     11dc <main+0x5c>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r12d
jmp    1293 <main+0x113>
mov    0x10(%rbx),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
test   %eax,%eax
jle    1293 <main+0x113>
mov    %eax,%r13d
lea    0xe1e(%rip),%r14
mov    %rsp,%r15
xor    %ebp,%ebp
jmp    1218 <main+0x98>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
cmp    %ebp,%r13d
je     1269 <main+0xe9>
mov    0x8(%rbx),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%ecx
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   1040 <rmdir@plt>
test   %eax,%eax
jne    126e <main+0xee>
mov    %ebp,%eax
mov    $0xd1b71759,%ecx
imul   %rcx,%rax
shr    $0x2d,%rax
imul   $0x2710,%eax,%eax
cmp    %ebp,%eax
jne    1210 <main+0x90>
xor    %edi,%edi
call   1070 <time@plt>
lea    0xddb(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1210 <main+0x90>
xor    %r12d,%r12d
jmp    1293 <main+0x113>
mov    %eax,%r12d
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd9c(%rip),%rdi
mov    %rsp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12d,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Usage %s dirnamebase count\0A\00"
@.str.1 = [15 x i8] c"name too long\0A\00"
@.str.2 = [6 x i8] c"%s-%d\00"
@.str.3 = [21 x i8] c"rmdir(%s) error: %s\0A\00"
@errno = global i32 0
@.str.4 = [26 x i8] c" - deleted %d (time %ld)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %64
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
%22 = icmp sgt i32 %21, 4080
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %64
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @strtoul(i8* %28, i32* null, i32 0)
store i32 %29, i32* %8
store i32 0, i32* %6
br label %30
30: ; preds = %59, %25
%31 = load i32, i32* %6
%32 = load i32, i32* %8
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %62
34: ; preds = %30
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = load i32, i32* %6
%40 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %39)
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%42 = call i32 @rmdir(i8* %41)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %34
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %46, i8* %48)
br label %62
50: ; preds = %34
%51 = load i32, i32* %6
%52 = srem i32 %51, 10000
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i32, i32* %6
%56 = call i32 @time(i32 0)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %55, i32 %56)
br label %58
58: ; preds = %54, %50
br label %59
59: ; preds = %58
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %30
62: ; preds = %45, %30
%63 = load i32, i32* %7
store i32 %63, i32* %3
br label %64
64: ; preds = %62, %23, %12
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [28 x i8] c"Usage %s dirnamebase count\0A\00"
@.str.2 = [6 x i8] c"%s-%d\00"
@.str.3 = [21 x i8] c"rmdir(%s) error: %s\0A\00"
@errno = global i32 0
@.str.4 = [26 x i8] c" - deleted %d (time %ld)\0A\00"
@str = [14 x i8] c"name too long\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %40
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp sgt i32 %12, 4080
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %40
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @strtoul(i8* nocapture %18, i32* null, i32 0)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %16, %37
%22 = phi i32 [ %38, %37 ], [ 0, %16 ]
%23 = load i8*, i8** %10
%24 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32 %22)
%25 = call i32 @rmdir(i8* %4)
%26 = icmp eq i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %21
%28 = load i32, i32* @errno
%29 = tail call i8* @strerror(i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %29)
br label %40
31: ; preds = %21
%32 = urem i32 %22, 10000
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = tail call i32 @time(i32 0)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %35)
br label %37
37: ; preds = %31, %34
%38 = add nuw nsw i32 %22, 1
%39 = icmp eq i32 %38, %19
br i1 %39, label %40, label %21
40: ; preds = %37, %16, %27, %14, %6
%41 = phi i32 [ 1, %6 ], [ 1, %14 ], [ %25, %27 ], [ 0, %16 ], [ 0, %37 ]
ret i32 %41
}