#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 */
long *calloc(long, int);
int /*<<< orphan*/ chngdir(char *);
int determine_size(long, long);
int /*<<< orphan*/ fill_this_directory(long, long, long);
int make_directory(char *);
long rand();
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
void do_subtree(long *sizes_start, long *sizes_end, long median_file_size,
                long maximum_file_size, long median_dir_branching,
                long max_dir_branching) {
  long *p;
  long *sub_start;
  long *sub_end;
  int index_subdirectory_to_add_directory_to;
  long *dirs_in_subtrees;
  char *subtree_name;
  long *sizes_index = sizes_start;
  char subtree_name_array[128];
  long this_directory_branching;
  static long this_directorys_number;
  subtree_name = subtree_name_array;
  fill_this_directory(*sizes_index, median_file_size, maximum_file_size);
  sizes_index++;
  this_directory_branching =
      determine_size(median_dir_branching, max_dir_branching) + 1;
  dirs_in_subtrees = calloc(this_directory_branching, sizeof(long));
  while (sizes_index <= sizes_end) {
    index_subdirectory_to_add_directory_to =
        (rand() % this_directory_branching);
    (*(dirs_in_subtrees + index_subdirectory_to_add_directory_to))++;
    sizes_index++;
  }
  sizes_index = sizes_start + 1;
  for (p = dirs_in_subtrees; p < (dirs_in_subtrees + this_directory_branching);
       p++) {
    if (*p) {
      int nocd;
      sprintf(subtree_name, "d%lu", this_directorys_number++);
      nocd = make_directory(subtree_name);
      if (!nocd)
        chngdir(subtree_name);
      sub_start = sizes_index;
      sub_end = (sizes_index + (*p - 1));
      do_subtree(sub_start, sub_end, median_file_size, maximum_file_size,
                 median_dir_branching, max_dir_branching);
      if (!nocd)
        chngdir("..");
    }
    sizes_index += *p;
  }
}


x86 assembly (clang, -O0):
<do_subtree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x68(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <fill_this_directory@plt>
mov    -0x68(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <determine_size@plt>
add    $0x1,%eax
cltq
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rdi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x68(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     124c <do_subtree+0xcc>
mov    $0x0,%al
call   10a0 <rand@plt>
cqto
idivq  -0xf8(%rbp)
mov    %edx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x58(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x1,%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x68(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x68(%rbp)
jmp    1204 <do_subtree+0x84>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    -0xf8(%rbp),%rdx
shl    $0x3,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    135a <do_subtree+0x1da>
mov    -0x38(%rbp),%rax
cmpq   $0x0,(%rax)
je     1336 <do_subtree+0x1b6>
mov    -0x60(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2dc2(%rip)
mov    %eax,%edx
lea    0xd51(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x60(%rbp),%rdi
call   1040 <make_directory@plt>
mov    %eax,-0xfc(%rbp)
cmpl   $0x0,-0xfc(%rbp)
jne    12d9 <do_subtree+0x159>
mov    -0x60(%rbp),%rdi
call   1030 <chngdir@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x68(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rcx),%rcx
sub    $0x1,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
call   1080 <do_subtree@plt>
cmpl   $0x0,-0xfc(%rbp)
jne    1331 <do_subtree+0x1b1>
lea    0xcd9(%rip),%rdi
call   1030 <chngdir@plt>
jmp    1336 <do_subtree+0x1b6>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
jmp    1260 <do_subtree+0xe0>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_subtree>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %r9,%rbx
mov    %r8,%rbp
mov    %rsi,%r14
mov    %rdi,%r13
mov    (%rdi),%rdi
mov    %rdx,0x8(%rsp)
mov    %rdx,%rsi
mov    %rcx,0x10(%rsp)
mov    %rcx,%rdx
call   1060 <fill_this_directory@plt>
mov    %rbp,0x20(%rsp)
mov    %rbp,%rdi
mov    %rbx,0x28(%rsp)
mov    %rbx,%rsi
call   1070 <determine_size@plt>
mov    %rax,0x18(%rsp)
lea    0x1(%rax),%r12d
movslq %r12d,%r15
mov    %r15,%rdi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%rbp
add    $0x8,%r13
cmp    %r14,%r13
jbe    12df <do_subtree+0x15f>
cmpl   $0x0,0x18(%rsp)
mov    0x28(%rsp),%r12
mov    0x20(%rsp),%rbx
js     12cd <do_subtree+0x14d>
lea    0x0(,%r15,8),%r15
add    %rbp,%r15
lea    0x30(%rsp),%r14
jmp    1259 <do_subtree+0xd9>
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rax
lea    -0x8(,%rax,8),%rsi
ff
add    %r13,%rsi
mov    %r13,%rdi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    %rbx,%r8
mov    %r12,%r9
call   1080 <do_subtree@plt>
mov    0x0(%rbp),%rax
lea    0x0(%r13,%rax,8),%r13
add    $0x8,%rbp
cmp    %r15,%rbp
jae    12cd <do_subtree+0x14d>
cmpq   $0x0,0x0(%rbp)
je     1247 <do_subtree+0xc7>
mov    0x2e01(%rip),%rdx
lea    0x1(%rdx),%rax
mov    %rax,0x2df6(%rip)
mov    %r14,%rdi
lea    0xd84(%rip),%rsi
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1040 <make_directory@plt>
test   %eax,%eax
jne    1220 <do_subtree+0xa0>
mov    %r14,%rdi
call   1030 <chngdir@plt>
mov    0x0(%rbp),%rax
lea    -0x8(,%rax,8),%rsi
ff
add    %r13,%rsi
mov    %r13,%rdi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    %rbx,%r8
mov    %r12,%r9
call   1080 <do_subtree@plt>
lea    0xd42(%rip),%rdi
call   1030 <chngdir@plt>
jmp    1247 <do_subtree+0xc7>
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rbx
jmp    130b <do_subtree+0x18b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cqto
idiv   %r15
movslq %edx,%rax
addq   $0x1,0x0(%rbp,%rax,8)
add    $0x8,%rbx
cmp    %r14,%rbx
ja     11f3 <do_subtree+0x73>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rax,%rcx
or     %r15,%rcx
shr    $0x20,%rcx
jne    12f0 <do_subtree+0x170>
xor    %edx,%edx
div    %r12d
jmp    12f5 <do_subtree+0x175>

LLVM IR (-O0):
@do_subtree.this_directorys_number = internal global i64 0
@.str = [5 x i8] c"d%lu\00"
@.str.1 = [3 x i8] c"..\00"
define void @do_subtree(i64* %0, i64* %1, i64 %2, i64 %3, i64 %4, i64 %5) {
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64*
%14 = alloca i64*
%15 = alloca i64*
%16 = alloca i32
%17 = alloca i64*
%18 = alloca i8*
%19 = alloca i64*
%20 = alloca [128 x i8]
%21 = alloca i64
%22 = alloca i32
store i64* %0, i64** %7
store i64* %1, i64** %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
store i64 %5, i64* %12
%23 = load i64*, i64** %7
store i64* %23, i64** %19
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %20, i64 0, i64 0
store i8* %24, i8** %18
%25 = load i64*, i64** %19
%26 = load i64, i64* %25
%27 = load i64, i64* %9
%28 = load i64, i64* %10
%29 = call i32 @fill_this_directory(i64 %26, i64 %27, i64 %28)
%30 = load i64*, i64** %19
%31 = getelementptr inbounds i64, i64* %30, i32 1
store i64* %31, i64** %19
%32 = load i64, i64* %11
%33 = load i64, i64* %12
%34 = call i32 @determine_size(i64 %32, i64 %33)
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
store i64 %36, i64* %21
%37 = load i64, i64* %21
%38 = call i64* @calloc(i64 %37, i32 8)
store i64* %38, i64** %17
br label %39
39: ; preds = %43, %6
%40 = load i64*, i64** %19
%41 = load i64*, i64** %8
%42 = icmp ule i64* %40, %41
br i1 %42, label %43, label %56
43: ; preds = %39
%44 = call i64 (...) @rand()
%45 = load i64, i64* %21
%46 = srem i64 %44, %45
%47 = trunc i64 %46 to i32
store i32 %47, i32* %16
%48 = load i64*, i64** %17
%49 = load i32, i32* %16
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i64, i64* %48, i64 %50
%52 = load i64, i64* %51
%53 = add nsw i64 %52, 1
store i64 %53, i64* %51
%54 = load i64*, i64** %19
%55 = getelementptr inbounds i64, i64* %54, i32 1
store i64* %55, i64** %19
br label %39
56: ; preds = %39
%57 = load i64*, i64** %7
%58 = getelementptr inbounds i64, i64* %57, i64 1
store i64* %58, i64** %19
%59 = load i64*, i64** %17
store i64* %59, i64** %13
br label %60
60: ; preds = %106, %56
%61 = load i64*, i64** %13
%62 = load i64*, i64** %17
%63 = load i64, i64* %21
%64 = getelementptr inbounds i64, i64* %62, i64 %63
%65 = icmp ult i64* %61, %64
br i1 %65, label %66, label %109
66: ; preds = %60
%67 = load i64*, i64** %13
%68 = load i64, i64* %67
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %101
70: ; preds = %66
%71 = load i8*, i8** %18
%72 = load i64, i64* @do_subtree.this_directorys_number
%73 = add nsw i64 %72, 1
store i64 %73, i64* @do_subtree.this_directorys_number
%74 = trunc i64 %72 to i32
%75 = call i32 @sprintf(i8* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %74)
%76 = load i8*, i8** %18
%77 = call i32 @make_directory(i8* %76)
store i32 %77, i32* %22
%78 = load i32, i32* %22
%79 = icmp ne i32 %78, 0
br i1 %79, label %83, label %80
80: ; preds = %70
%81 = load i8*, i8** %18
%82 = call i32 @chngdir(i8* %81)
br label %83
83: ; preds = %80, %70
%84 = load i64*, i64** %19
store i64* %84, i64** %14
%85 = load i64*, i64** %19
%86 = load i64*, i64** %13
%87 = load i64, i64* %86
%88 = sub nsw i64 %87, 1
%89 = getelementptr inbounds i64, i64* %85, i64 %88
store i64* %89, i64** %15
%90 = load i64*, i64** %14
%91 = load i64*, i64** %15
%92 = load i64, i64* %9
%93 = load i64, i64* %10
%94 = load i64, i64* %11
%95 = load i64, i64* %12
%96 = load i32, i32* %22
%97 = icmp ne i32 %96, 0
br i1 %97, label %100, label %98
98: ; preds = %83
%99 = call i32 @chngdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %100
100: ; preds = %98, %83
br label %101
101: ; preds = %100, %66
%102 = load i64*, i64** %13
%103 = load i64, i64* %102
%104 = load i64*, i64** %19
%105 = getelementptr inbounds i64, i64* %104, i64 %103
store i64* %105, i64** %19
br label %106
106: ; preds = %101
%107 = load i64*, i64** %13
%108 = getelementptr inbounds i64, i64* %107, i32 1
store i64* %108, i64** %13
br label %60
109: ; preds = %60
ret void
}

LLVM IR (-O2):
@do_subtree.this_directorys_number = internal unnamed_addr global i64 0
@.str = [5 x i8] c"d%lu\00"
@.str.1 = [3 x i8] c"..\00"
define void @do_subtree(i64* %0, i64* readnone %1, i64 %2, i64 %3, i64 %4, i64 %5) {
%7 = alloca [128 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%9 = load i64, i64* %0
%10 = tail call i32 @fill_this_directory(i64 %9, i64 %2, i64 %3)
%11 = tail call i32 @determine_size(i64 %4, i64 %5)
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = tail call i64* @calloc(i64 %13, i32 8)
%15 = getelementptr inbounds i64, i64* %0, i64 1
%16 = icmp ugt i64* %15, %1
br i1 %16, label %28, label %17
17: ; preds = %6, %17
%18 = phi i64* [ %26, %17 ], [ %15, %6 ]
%19 = tail call i64 (...) @rand()
%20 = srem i64 %19, %13
%21 = shl i64 %20, 32
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds i64, i64* %14, i64 %22
%24 = load i64, i64* %23
%25 = add nsw i64 %24, 1
store i64 %25, i64* %23
%26 = getelementptr inbounds i64, i64* %18, i64 1
%27 = icmp ugt i64* %26, %1
br i1 %27, label %28, label %17
28: ; preds = %17, %6
%29 = getelementptr inbounds i64, i64* %14, i64 %13
%30 = icmp sgt i32 %11, -1
br i1 %30, label %31, label %58
31: ; preds = %28, %53
%32 = phi i64* [ %56, %53 ], [ %14, %28 ]
%33 = phi i64* [ %55, %53 ], [ %15, %28 ]
%34 = load i64, i64* %32
%35 = icmp eq i64 %34, 0
br i1 %35, label %53, label %36
36: ; preds = %31
%37 = load i64, i64* @do_subtree.this_directorys_number
%38 = add nsw i64 %37, 1
store i64 %38, i64* @do_subtree.this_directorys_number
%39 = trunc i64 %37 to i32
%40 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = call i32 @make_directory(i8* %8)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %36
%44 = call i32 @chngdir(i8* %8)
%45 = load i64, i64* %32
%46 = add nsw i64 %45, -1
%47 = getelementptr inbounds i64, i64* %33, i64 %46
%48 = call i32 @chngdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %53
49: ; preds = %36
%50 = load i64, i64* %32
%51 = add nsw i64 %50, -1
%52 = getelementptr inbounds i64, i64* %33, i64 %51
br label %53
53: ; preds = %43, %49, %31
%54 = load i64, i64* %32
%55 = getelementptr inbounds i64, i64* %33, i64 %54
%56 = getelementptr inbounds i64, i64* %32, i64 1
%57 = icmp ult i64* %56, %29
br i1 %57, label %31, label %58
58: ; preds = %53, %28
ret void
}