#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 */
struct stat {
  int st_size;
  int st_ino;
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int stat(char *, struct stat *);
scalar_t__ strcmp(char *, char *);
void fsize(char *name, int level) {
  struct dirent *dir;
  DIR *d;
  printf("%s:\n", name);
  d = opendir(name);
  if (d != NULL) {
    while ((dir = readdir(d)) != NULL) {
      struct stat st;
      char fn[0x100];
      if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0)
        continue;
      for (int i = 0; i < level; i++)
        printf("   ");
      sprintf(fn, "%s/%s", name, dir->d_name);
      if (stat(fn, &st) == -1)
        exit(1);
      if (S_ISDIR(st.st_mode))
        fsize(fn, level + 1);
      else
        printf("%s(%d): %d\n", dir->d_name, st.st_size, st.st_ino);
    }
    closedir(d);
  }
}


x86 assembly (clang, -O0):
<fsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1305 <fsize+0x165>
jmp    11e1 <fsize+0x41>
mov    -0x20(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12fc <fsize+0x15c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe00(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1232 <fsize+0x92>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xde2(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1237 <fsize+0x97>
jmp    11e1 <fsize+0x41>
movl   $0x0,-0x134(%rbp)
mov    -0x134(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1272 <fsize+0xd2>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1241 <fsize+0xa1>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xd81(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x130(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    12b3 <fsize+0x113>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12dc <fsize+0x13c>
lea    -0x130(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
call   10a0 <fsize@plt>
jmp    12f7 <fsize+0x157>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e1 <fsize+0x41>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xe42(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     12da <fsize+0x13a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     12d2 <fsize+0x132>
mov    %rax,%r14
lea    0x1(%r15),%eax
mov    %eax,0x4(%rsp)
lea    0xe02(%rip),%r13
lea    0xdfd(%rip),%r12
jmp    1244 <fsize+0xa4>
mov    (%r14),%rsi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xdf3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     12d2 <fsize+0x132>
mov    (%r14),%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1230 <fsize+0x90>
mov    (%r14),%rdi
lea    0xda7(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1230 <fsize+0x90>
mov    %r15d,%ebp
test   %r15d,%r15d
jle    127f <fsize+0xdf>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1270 <fsize+0xd0>
mov    (%r14),%rcx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
lea    0xd7b(%rip),%rsi
mov    0x18(%rsp),%rdx
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     12ec <fsize+0x14c>
mov    0x10(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     120d <fsize+0x6d>
lea    0x20(%rsp),%rdi
mov    0x4(%rsp),%esi
call   10a0 <fsize@plt>
jmp    1230 <fsize+0x90>
mov    %rbx,%rdi
call   1060 <closedir@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32, i32, i32 }
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [12 x i8] c"%s(%d): %d\0A\00"
define void @fsize(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.dirent*
%6 = alloca i32*
%7 = alloca %struct.stat
%8 = alloca [256 x i8]
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
%13 = call i32* @opendir(i8* %12)
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %78
16: ; preds = %2
br label %17
17: ; preds = %74, %33, %16
%18 = load i32*, i32** %6
%19 = call %struct.dirent* @readdir(i32* %18)
store %struct.dirent* %19, %struct.dirent** %5
%20 = icmp ne %struct.dirent* %19, null
br i1 %20, label %21, label %75
21: ; preds = %17
%22 = load %struct.dirent*, %struct.dirent** %5
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %21
%28 = load %struct.dirent*, %struct.dirent** %5
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27, %21
br label %17
34: ; preds = %27
store i32 0, i32* %9
br label %35
35: ; preds = %41, %34
%36 = load i32, i32* %9
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %35
44: ; preds = %35
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%46 = load i8*, i8** %3
%47 = load %struct.dirent*, %struct.dirent** %5
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i8*, i8** %48
%50 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %46, i8* %49)
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%52 = call i32 @stat(i8* %51, %struct.stat* %7)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %44
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %44
%57 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 2
%58 = load i32, i32* %57
%59 = call i64 @S_ISDIR(i32 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
br label %74
65: ; preds = %56
%66 = load %struct.dirent*, %struct.dirent** %5
%67 = getelementptr inbounds %struct.dirent, %struct.dirent* %66, i32 0, i32 0
%68 = load i8*, i8** %67
%69 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%70 = load i32, i32* %69
%71 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %68, i32 %70, i32 %72)
br label %74
74: ; preds = %65, %61
br label %17
75: ; preds = %17
%76 = load i32*, i32** %6
%77 = call i32 @closedir(i32* %76)
br label %78
78: ; preds = %75, %2
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.dirent = type { i8* }
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [12 x i8] c"%s(%d): %d\0A\00"
define void @fsize(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = alloca [256 x i8]
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32* @opendir(i8* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %57, label %8
8: ; preds = %2
%9 = call %struct.dirent* @readdir(i32* %6)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %55, label %11
11: ; preds = %8
%12 = bitcast %struct.stat* %3 to i8*
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%14 = icmp sgt i32 %1, 0
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%16 = add nsw i32 %1, 1
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
br label %19
19: ; preds = %11, %52
%20 = phi %struct.dirent* [ %9, %11 ], [ %53, %52 ]
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %52, label %25
25: ; preds = %19
%26 = load i8*, i8** %21
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %52, label %29
29: ; preds = %25
br i1 %14, label %35, label %30
30: ; preds = %35, %29
%31 = load i8*, i8** %21
%32 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %31)
%33 = call i32 @stat(i8* %13, %struct.stat* %3)
%34 = icmp eq i32 %33, -1
br i1 %34, label %40, label %42
35: ; preds = %29, %35
%36 = phi i32 [ %38, %35 ], [ 0, %29 ]
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%38 = add nuw nsw i32 %36, 1
%39 = icmp eq i32 %38, %1
br i1 %39, label %30, label %35
40: ; preds = %30
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %30
%43 = load i32, i32* %15
%44 = call i64 @S_ISDIR(i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %42
br label %52
47: ; preds = %42
%48 = load i8*, i8** %21
%49 = load i32, i32* %17
%50 = load i32, i32* %18
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %48, i32 %49, i32 %50)
br label %52
52: ; preds = %46, %47, %19, %25
%53 = call %struct.dirent* @readdir(i32* %6)
%54 = icmp eq %struct.dirent* %53, null
br i1 %54, label %55, label %19
55: ; preds = %52, %8
%56 = call i32 @closedir(i32* %6)
br label %57
57: ; preds = %55, %2
ret void
}