#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*/ op_chdir(unsigned int);
int /*<<< orphan*/ op_chdirup();
int /*<<< orphan*/ op_rmdir(unsigned int);
int /*<<< orphan*/ op_unlink(unsigned int);
int random();
void rmrandtree_sub(unsigned depth, unsigned *ct, unsigned numthings) {
  unsigned numhere;
  numhere = 0;
  while (*ct < numthings) {
    switch (random() % 4) {
    case 0:
      (*ct)++;
      op_chdir(numhere);
      rmrandtree_sub(depth + 1, ct, numthings);
      op_chdirup();
      op_rmdir(numhere);
      numhere++;
      break;
    case 1:
      if (depth > 0) {
        return;
      }
      break;
    case 2:
    case 3:
      op_unlink(numhere);
      (*ct)++;
      numhere++;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<rmrandtree_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jae    124a <rmrandtree_sub+0xea>
xor    %eax,%eax
call   1070 <random@plt>
mov    %eax,%edx
add    $0x3,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
je     11d3 <rmrandtree_sub+0x73>
jmp    11ae <rmrandtree_sub+0x4e>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     1215 <rmrandtree_sub+0xb5>
jmp    11bf <rmrandtree_sub+0x5f>
mov    -0x1c(%rbp),%eax
add    $0xfffffffe,%eax
sub    $0x2,%eax
jb     1229 <rmrandtree_sub+0xc9>
jmp    1245 <rmrandtree_sub+0xe5>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%edi
call   1080 <op_chdir@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <rmrandtree_sub@plt>
mov    $0x0,%al
call   1060 <op_chdirup@plt>
mov    -0x18(%rbp),%edi
call   1040 <op_rmdir@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1245 <rmrandtree_sub+0xe5>
cmpl   $0x0,-0x4(%rbp)
jbe    1224 <rmrandtree_sub+0xc4>
jmp    124a <rmrandtree_sub+0xea>
jmp    1245 <rmrandtree_sub+0xe5>
mov    -0x18(%rbp),%edi
call   1050 <op_unlink@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1179 <rmrandtree_sub+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmrandtree_sub>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    %edx,(%rsi)
jae    1205 <rmrandtree_sub+0xa5>
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0x1(%r14),%r15d
xor    %ebp,%ebp
jmp    11a2 <rmrandtree_sub+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1050 <op_unlink@plt>
addl   $0x1,(%rbx)
add    $0x1,%ebp
cmp    %r12d,(%rbx)
jae    1205 <rmrandtree_sub+0xa5>
xor    %eax,%eax
call   1070 <random@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
mov    %ecx,%edx
neg    %edx
add    %eax,%edx
add    $0xfffffffe,%edx
cmp    $0x2,%edx
jb     1190 <rmrandtree_sub+0x30>
sub    %ecx,%eax
cmp    $0x1,%eax
je     1200 <rmrandtree_sub+0xa0>
test   %eax,%eax
jne    119d <rmrandtree_sub+0x3d>
addl   $0x1,(%rbx)
mov    %ebp,%edi
call   1080 <op_chdir@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <rmrandtree_sub@plt>
xor    %eax,%eax
call   1060 <op_chdirup@plt>
mov    %ebp,%edi
call   1040 <op_rmdir@plt>
jmp    119a <rmrandtree_sub+0x3a>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r14d,%r14d
je     119d <rmrandtree_sub+0x3d>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @rmrandtree_sub(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %44, %3
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = load i32, i32* %6
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %45
13: ; preds = %8
%14 = call i32 (...) @random()
%15 = srem i32 %14, 4
switch i32 %15, label %44 [
i32 0, label %16
i32 1, label %31
i32 2, label %36
i32 3, label %36
]
16: ; preds = %13
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = add i32 %18, 1
store i32 %19, i32* %17
%20 = load i32, i32* %7
%21 = call i32 @op_chdir(i32 %20)
%22 = load i32, i32* %4
%23 = add i32 %22, 1
%24 = load i32*, i32** %5
%25 = load i32, i32* %6
%26 = call i32 (...) @op_chdirup()
%27 = load i32, i32* %7
%28 = call i32 @op_rmdir(i32 %27)
%29 = load i32, i32* %7
%30 = add i32 %29, 1
store i32 %30, i32* %7
br label %44
31: ; preds = %13
%32 = load i32, i32* %4
%33 = icmp ugt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
br label %45
35: ; preds = %31
br label %44
36: ; preds = %13, %13
%37 = load i32, i32* %7
%38 = call i32 @op_unlink(i32 %37)
%39 = load i32*, i32** %5
%40 = load i32, i32* %39
%41 = add i32 %40, 1
store i32 %41, i32* %39
%42 = load i32, i32* %7
%43 = add i32 %42, 1
store i32 %43, i32* %7
br label %44
44: ; preds = %13, %36, %35, %16
br label %8
45: ; preds = %34, %8
ret void
}

LLVM IR (-O2):
define void @rmrandtree_sub(i32 %0, i32* nocapture %1, i32 %2) {
%4 = load i32, i32* %1
%5 = icmp ult i32 %4, %2
br i1 %5, label %6, label %30
6: ; preds = %3
%7 = icmp eq i32 %0, 0
%8 = add i32 %0, 1
br label %9
9: ; preds = %6, %26
%10 = phi i32 [ 0, %6 ], [ %27, %26 ]
%11 = tail call i32 (...) @random()
%12 = srem i32 %11, 4
switch i32 %12, label %26 [
i32 0, label %13
i32 1, label %20
i32 2, label %21
i32 3, label %21
]
13: ; preds = %9
%14 = load i32, i32* %1
%15 = add i32 %14, 1
store i32 %15, i32* %1
%16 = tail call i32 @op_chdir(i32 %10)
tail call void @rmrandtree_sub(i32 %8, i32* %1, i32 %2)
%17 = tail call i32 (...) @op_chdirup()
%18 = tail call i32 @op_rmdir(i32 %10)
%19 = add i32 %10, 1
br label %26
20: ; preds = %9
br i1 %7, label %26, label %30
21: ; preds = %9, %9
%22 = tail call i32 @op_unlink(i32 %10)
%23 = load i32, i32* %1
%24 = add i32 %23, 1
store i32 %24, i32* %1
%25 = add i32 %10, 1
br label %26
26: ; preds = %20, %9, %21, %13
%27 = phi i32 [ %10, %9 ], [ %25, %21 ], [ %10, %20 ], [ %19, %13 ]
%28 = load i32, i32* %1
%29 = icmp ult i32 %28, %2
br i1 %29, label %9, label %30
30: ; preds = %20, %26, %3
ret void
}