#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*/ cwd;

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ link(char *, char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ symlink(char *, char *);
int /*<<< orphan*/ unlink(char *);
int k_tree_trav(int lvl, int node_nr) {
  int cnt;
  char dir[8192], cwd[8192], f1[8192], f2[8192], ln[8192];
  if (lvl <= 0)
    return 0;
  for (cnt = 0; cnt < node_nr; cnt++) {
    sprintf(dir, "%d-d", cnt);
    sprintf(f1, "%d-f", cnt);
    sprintf(f2, "%d-f-t", cnt);
    sprintf(ln, "%d-l", cnt);
    link(f1, f2);
    unlink(f1);
    rename(f2, f1);
    symlink(ln, f1);
    unlink(ln);
    getcwd(cwd, sizeof(cwd));
    chmod(dir, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    chdir(dir);
    k_tree_trav(lvl - 1, node_nr);
    chdir(cwd);
  }
  return 1;
}


x86 assembly (clang, -O0):
<k_tree_trav>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa010,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     11b7 <k_tree_trav+0x27>
movl   $0x0,-0x4(%rbp)
jmp    12ef <k_tree_trav+0x15f>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12e8 <k_tree_trav+0x158>
lea    -0x2010(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe25(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x6010(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe14(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x8010(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe03(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xa010(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xdf4(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x6010(%rbp),%rdi
lea    -0x8010(%rbp),%rsi
call   10b0 <link@plt>
lea    -0x6010(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x8010(%rbp),%rdi
lea    -0x6010(%rbp),%rsi
call   1090 <rename@plt>
lea    -0xa010(%rbp),%rdi
lea    -0x6010(%rbp),%rsi
call   1060 <symlink@plt>
lea    -0xa010(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x4010(%rbp),%rdi
mov    $0x2000,%esi
call   1070 <getcwd@plt>
lea    -0x2010(%rbp),%rdi
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
mov    0x2d4d(%rip),%rax
or     (%rax),%esi
mov    0x2d34(%rip),%rax
or     (%rax),%esi
mov    0x2d23(%rip),%rax
or     (%rax),%esi
call   1080 <chmod@plt>
lea    -0x2010(%rbp),%rdi
call   1050 <chdir@plt>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0xc(%rbp),%esi
call   1040 <k_tree_trav@plt>
lea    -0x4010(%rbp),%rdi
call   1050 <chdir@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11be <k_tree_trav+0x2e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<k_tree_trav>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa018,%rsp
test   %edi,%edi
jle    12ca <k_tree_trav+0x13a>
mov    %esi,%r15d
mov    $0x1,%eax
test   %esi,%esi
jle    12cc <k_tree_trav+0x13c>
add    $0xffffffff,%edi
mov    %edi,0xc(%rsp)
xor    %ebx,%ebx
lea    0x4010(%rsp),%r12
nopw   0x0(%rax,%rax,1)
lea    0x8010(%rsp),%r14
mov    %r14,%rdi
lea    0xe1e(%rip),%rsi
mov    %ebx,%edx
call   10a0 <sprintf@plt>
mov    %r12,%rdi
lea    0xe12(%rip),%rsi
mov    %ebx,%edx
call   10a0 <sprintf@plt>
lea    0x2010(%rsp),%rbp
mov    %rbp,%rdi
lea    0xdfe(%rip),%rsi
mov    %ebx,%edx
call   10a0 <sprintf@plt>
lea    0x10(%rsp),%r13
mov    %r13,%rdi
lea    0xdef(%rip),%rsi
mov    %ebx,%edx
call   10a0 <sprintf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   10b0 <link@plt>
mov    %r12,%rdi
call   1030 <unlink@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1090 <rename@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <symlink@plt>
mov    %r13,%rdi
call   1030 <unlink@plt>
lea    0x6010(%rsp),%r13
mov    %r13,%rdi
mov    $0x2000,%esi
call   1070 <getcwd@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
mov    0x2d49(%rip),%rax
or     (%rax),%esi
mov    0x2d50(%rip),%rax
or     (%rax),%esi
mov    0x2d3f(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
call   1080 <chmod@plt>
mov    %r14,%rdi
call   1050 <chdir@plt>
mov    0xc(%rsp),%edi
mov    %r15d,%esi
call   1040 <k_tree_trav@plt>
mov    %r13,%rdi
call   1050 <chdir@plt>
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    11d0 <k_tree_trav+0x40>
mov    $0x1,%eax
jmp    12cc <k_tree_trav+0x13c>
xor    %eax,%eax
add    $0xa018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d-d\00"
@.str.1 = [5 x i8] c"%d-f\00"
@.str.2 = [7 x i8] c"%d-f-t\00"
@.str.3 = [5 x i8] c"%d-l\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
define i32 @k_tree_trav(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [8192 x i8]
%8 = alloca [8192 x i8]
%9 = alloca [8192 x i8]
%10 = alloca [8192 x i8]
%11 = alloca [8192 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %69
15: ; preds = %2
store i32 0, i32* %6
br label %16
16: ; preds = %65, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %68
20: ; preds = %16
%21 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%22 = load i32, i32* %6
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%25 = load i32, i32* %6
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [8192 x i8], [8192 x i8]* %10, i64 0, i64 0
%28 = load i32, i32* %6
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [8192 x i8], [8192 x i8]* %11, i64 0, i64 0
%31 = load i32, i32* %6
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%34 = getelementptr inbounds [8192 x i8], [8192 x i8]* %10, i64 0, i64 0
%35 = call i32 @link(i8* %33, i8* %34)
%36 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%37 = call i32 @unlink(i8* %36)
%38 = getelementptr inbounds [8192 x i8], [8192 x i8]* %10, i64 0, i64 0
%39 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%40 = call i32 @rename(i8* %38, i8* %39)
%41 = getelementptr inbounds [8192 x i8], [8192 x i8]* %11, i64 0, i64 0
%42 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%43 = call i32 @symlink(i8* %41, i8* %42)
%44 = getelementptr inbounds [8192 x i8], [8192 x i8]* %11, i64 0, i64 0
%45 = call i32 @unlink(i8* %44)
%46 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%47 = call i32 @getcwd(i8* %46, i32 8192)
%48 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%49 = load i32, i32* @S_IRUSR
%50 = load i32, i32* @S_IWUSR
%51 = or i32 %49, %50
%52 = load i32, i32* @S_IRGRP
%53 = or i32 %51, %52
%54 = load i32, i32* @S_IROTH
%55 = or i32 %53, %54
%56 = call i32 @chmod(i8* %48, i32 %55)
%57 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%58 = call i32 @chdir(i8* %57)
%59 = load i32, i32* %4
%60 = sub nsw i32 %59, 1
%61 = load i32, i32* %5
%62 = call i32 @k_tree_trav(i32 %60, i32 %61)
%63 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%64 = call i32 @chdir(i8* %63)
br label %65
65: ; preds = %20
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %16
68: ; preds = %16
store i32 1, i32* %3
br label %69
69: ; preds = %68, %14
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d-d\00"
@.str.1 = [5 x i8] c"%d-f\00"
@.str.2 = [7 x i8] c"%d-f-t\00"
@.str.3 = [5 x i8] c"%d-l\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
define i32 @k_tree_trav(i32 %0, i32 %1) {
%3 = alloca [8192 x i8]
%4 = alloca [8192 x i8]
%5 = alloca [8192 x i8]
%6 = alloca [8192 x i8]
%7 = alloca [8192 x i8]
%8 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%13 = icmp slt i32 %0, 1
br i1 %13, label %43, label %14
14: ; preds = %2
%15 = icmp sgt i32 %1, 0
br i1 %15, label %16, label %43
16: ; preds = %14
%17 = add nsw i32 %0, -1
br label %18
18: ; preds = %16, %18
%19 = phi i32 [ 0, %16 ], [ %41, %18 ]
%20 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%22 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%23 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%24 = call i32 @link(i8* %10, i8* %11)
%25 = call i32 @unlink(i8* %10)
%26 = call i32 @rename(i8* %11, i8* %10)
%27 = call i32 @symlink(i8* %12, i8* %10)
%28 = call i32 @unlink(i8* %12)
%29 = call i32 @getcwd(i8* %9, i32 8192)
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %31, %30
%33 = load i32, i32* @S_IRGRP
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IROTH
%36 = or i32 %34, %35
%37 = call i32 @chmod(i8* %8, i32 %36)
%38 = call i32 @chdir(i8* %8)
%39 = call i32 @k_tree_trav(i32 %17, i32 %1)
%40 = call i32 @chdir(i8* %9)
%41 = add nuw nsw i32 %19, 1
%42 = icmp eq i32 %41, %1
br i1 %42, label %43, label %18
43: ; preds = %18, %14, %2
%44 = phi i32 [ 0, %2 ], [ 1, %14 ], [ 1, %18 ]
ret i32 %44
}