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

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
unsigned long directoryOnFileSize(DIR *dp, char *path) {
  struct dirent *d;
  struct stat st;
  char path_temp[BUFSIZ + 1];
  unsigned long sum_size = 0;
  unsigned long temp = 0;
  if (dp == NULL)
    return 0;
  while ((d = readdir(dp)) != NULL) {
    sprintf(path_temp, "%s/%s", path, d->d_name);
    printf("%-15s", path_temp);
    if (lstat(path_temp, &st) < 0)
      return 0;
    if (S_ISDIR(st.st_mode)) {
      printf(" D");
      if ((d->d_name[0]) == '.' &&
          ((d->d_name[1]) == '.' || (d->d_name[1]) == '\0'))
        printf(" not Found");
      else {
        printf("\n");
        sum_size += directoryOnFileSize(opendir(path_temp), path_temp);
        printf("%27s", "");
      }
    } else {
      printf("%12s", "");
    }
    sum_size += st.st_size;
    printf(" %10zu", st.st_size);
    printf(" %10zu\n", sum_size);
  }
  closedir(dp);
  return sum_size;
}


x86 assembly (clang, -O0):
<directoryOnFileSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ee <directoryOnFileSize+0x6e>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1377 <directoryOnFileSize+0x1f7>
jmp    11f3 <directoryOnFileSize+0x73>
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     135f <directoryOnFileSize+0x1df>
mov    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xde0(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x60(%rbp),%rsi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <lstat@plt>
cmp    $0x0,%rax
jge    1262 <directoryOnFileSize+0xe2>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1377 <directoryOnFileSize+0x1f7>
mov    -0x28(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1315 <directoryOnFileSize+0x195>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12d0 <directoryOnFileSize+0x150>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
je     12bd <directoryOnFileSize+0x13d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    12d0 <directoryOnFileSize+0x150>
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <directoryOnFileSize+0x190>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1030 <opendir@plt>
mov    -0x60(%rbp),%rsi
mov    %rax,%rdi
call   1090 <directoryOnFileSize@plt>
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xd18(%rip),%rdi
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    132a <directoryOnFileSize+0x1aa>
lea    0xd03(%rip),%rdi
lea    0xd0f(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xce3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rsi
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f3 <directoryOnFileSize+0x73>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<directoryOnFileSize>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%rcx
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %rdi,%rdi
je     12fc <directoryOnFileSize+0x16c>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rcx,-0x30(%rbp)
call   1090 <readdir@plt>
test   %rax,%rax
je     1300 <directoryOnFileSize+0x170>
mov    %rax,%r13
xor    %ebx,%ebx
jmp    125f <directoryOnFileSize+0xcf>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
call   1040 <opendir@plt>
mov    %rax,%rdi
mov    %r12,%rsi
call   10a0 <directoryOnFileSize@plt>
add    %rax,%rbx
lea    0xe03(%rip),%rdi
lea    0xe14(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x40(%rbp),%rsi
add    %rsi,%rbx
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdea(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1090 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1302 <directoryOnFileSize+0x172>
mov    0x0(%r13),%rcx
mov    %r12,%rdi
lea    0xd93(%rip),%rsi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
lea    0xd8a(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
lea    -0x40(%rbp),%rsi
call   1080 <lstat@plt>
test   %rax,%rax
js     130c <directoryOnFileSize+0x17c>
mov    -0x38(%rbp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     12f0 <directoryOnFileSize+0x160>
lea    0xd61(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%r13),%rax
cmpb   $0x2e,(%rax)
jne    11f0 <directoryOnFileSize+0x60>
movzbl 0x1(%rax),%eax
cmp    $0x2e,%al
je     12cf <directoryOnFileSize+0x13f>
test   %al,%al
jne    11f0 <directoryOnFileSize+0x60>
lea    0xd39(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1225 <directoryOnFileSize+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd28(%rip),%rdi
jmp    1217 <directoryOnFileSize+0x87>
xor    %ebx,%ebx
jmp    1312 <directoryOnFileSize+0x182>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1070 <closedir@plt>
jmp    130e <directoryOnFileSize+0x17e>
xor    %ebx,%ebx
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i64, i32 }
@BUFSIZ = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [6 x i8] c"%-15s\00"
@.str.2 = [3 x i8] c" D\00"
@.str.3 = [11 x i8] c" not Found\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [5 x i8] c"%27s\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [5 x i8] c"%12s\00"
@.str.8 = [7 x i8] c" %10zu\00"
@.str.9 = [8 x i8] c" %10zu\0A\00"
define i64 @directoryOnFileSize(i32* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca %struct.dirent*
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%13 = load i32, i32* @BUFSIZ
%14 = add nsw i32 %13, 1
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %8
%17 = alloca i8, i64 %15
store i64 %15, i64* %9
store i64 0, i64* %10
store i64 0, i64* %11
%18 = load i32*, i32** %4
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %2
store i64 0, i64* %3
store i32 1, i32* %12
br label %92
21: ; preds = %2
br label %22
22: ; preds = %78, %21
%23 = load i32*, i32** %4
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %6
%25 = icmp ne %struct.dirent* %24, null
br i1 %25, label %26, label %88
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = load %struct.dirent*, %struct.dirent** %6
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%33 = call i64 @lstat(i8* %17, %struct.stat* %7)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %26
store i64 0, i64* %3
store i32 1, i32* %12
br label %92
36: ; preds = %26
%37 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i64 @S_ISDIR(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %76
41: ; preds = %36
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%43 = load %struct.dirent*, %struct.dirent** %6
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 46
br i1 %49, label %50, label %68
50: ; preds = %41
%51 = load %struct.dirent*, %struct.dirent** %6
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 46
br i1 %57, label %66, label %58
58: ; preds = %50
%59 = load %struct.dirent*, %struct.dirent** %6
%60 = getelementptr inbounds %struct.dirent, %struct.dirent* %59, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %58, %50
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %75
68: ; preds = %58, %41
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%70 = call i32* @opendir(i8* %17)
%71 = call i64 @directoryOnFileSize(i32* %70, i8* %17)
%72 = load i64, i64* %10
%73 = add i64 %72, %71
store i64 %73, i64* %10
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
br label %75
75: ; preds = %68, %66
br label %78
76: ; preds = %36
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
br label %78
78: ; preds = %76, %75
%79 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%80 = load i64, i64* %79
%81 = load i64, i64* %10
%82 = add i64 %81, %80
store i64 %82, i64* %10
%83 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%84 = load i64, i64* %83
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i64 %84)
%86 = load i64, i64* %10
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i64 %86)
br label %22
88: ; preds = %22
%89 = load i32*, i32** %4
%90 = call i32 @closedir(i32* %89)
%91 = load i64, i64* %10
store i64 %91, i64* %3
store i32 1, i32* %12
br label %92
92: ; preds = %88, %35, %20
%93 = load i8*, i8** %8
%94 = load i64, i64* %3
ret i64 %94
}

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