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

/* Variables and functions */
int MAXPATHLEN;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strcasecmp(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
void get_dir_size(char *dirname, int *files, unsigned long long *bytes) {
  DIR *dirg;
  struct dirent *dp;
  struct stat st;
  char temppath[MAXPATHLEN];
  dirg = opendir(dirname);
  if (dirg) {
    while (1) {
      dp = readdir(dirg);
      if (!dp)
        break;
      if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..") ||
          !strcasecmp(dp->d_name, "file_id.diz") ||
          !strcmp(dp->d_name, ".message"))
        continue;
      if (strlen(dp->d_name) > 3)
        if (!strcasecmp(dp->d_name + strlen(dp->d_name) - 4, ".nfo"))
          continue;
      snprintf(temppath, MAXPATHLEN, "%s/%s", dirname, dp->d_name);
      stat(temppath, &st);
      if (S_ISREG(st.st_mode)) {
        *(files) += 1;
        *(bytes) += (unsigned long long)st.st_size;
      } else if (S_ISDIR(st.st_mode)) {
        get_dir_size(temppath, files, bytes);
      }
    }
    closedir(dirg);
  }
}


x86 assembly (clang, -O0):
<get_dir_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1393 <get_dir_size+0x1e3>
jmp    120d <get_dir_size+0x5d>
jmp    1212 <get_dir_size+0x62>
mov    -0x20(%rbp),%rdi
call   10d0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122f <get_dir_size+0x7f>
jmp    138a <get_dir_size+0x1da>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xdc4(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     129f <get_dir_size+0xef>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xda7(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     129f <get_dir_size+0xef>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd8e(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
je     129f <get_dir_size+0xef>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd7e(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12a4 <get_dir_size+0xf4>
jmp    120d <get_dir_size+0x5d>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
cmp    $0x3,%eax
jle    12fc <get_dir_size+0x14c>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    -0x58(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xd34(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    12f7 <get_dir_size+0x147>
jmp    120d <get_dir_size+0x5d>
jmp    12fc <get_dir_size+0x14c>
mov    -0x50(%rbp),%rdi
mov    0x2ce1(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    (%rax),%r8
lea    0xd02(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0x50(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <stat@plt>
mov    -0x38(%rbp),%edi
call   10c0 <S_ISREG@plt>
cmp    $0x0,%rax
je     135d <get_dir_size+0x1ad>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
jmp    1385 <get_dir_size+0x1d5>
mov    -0x38(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1380 <get_dir_size+0x1d0>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <get_dir_size@plt>
jmp    1385 <get_dir_size+0x1d5>
jmp    120d <get_dir_size+0x5d>
mov    -0x20(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dir_size>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,-0x38(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rsp,%rbx
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rdi,-0x48(%rbp)
call   1050 <opendir@plt>
test   %rax,%rax
je     135f <get_dir_size+0x1af>
mov    %rax,%r14
mov    %rbx,-0x40(%rbp)
mov    %rax,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     1353 <get_dir_size+0x1a3>
mov    %rax,%r12
lea    0xde7(%rip),%rbx
jmp    1294 <get_dir_size+0xe4>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
mov    (%r12),%r8
mov    %r13,%rdi
lea    0xdea(%rip),%rdx
mov    -0x48(%rbp),%rcx
call   1080 <snprintf@plt>
mov    %r13,%rdi
lea    -0x58(%rbp),%rsi
call   10b0 <stat@plt>
mov    -0x58(%rbp),%ebx
mov    %ebx,%edi
call   10c0 <S_ISREG@plt>
test   %rax,%rax
je     1327 <get_dir_size+0x177>
mov    -0x30(%rbp),%rax
addl   $0x1,(%rax)
mov    -0x50(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    %rax,(%rcx)
lea    0xd8d(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   10d0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     1353 <get_dir_size+0x1a3>
mov    (%r12),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1280 <get_dir_size+0xd0>
mov    %r15,%rdi
lea    0xd4f(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1280 <get_dir_size+0xd0>
mov    %r15,%rdi
lea    0xd3f(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1280 <get_dir_size+0xd0>
mov    %r15,%rdi
lea    0xd38(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1280 <get_dir_size+0xd0>
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    $0x4,%eax
jl     121c <get_dir_size+0x6c>
mov    (%r12),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xcf3(%rip),%rbx
lea    0xd03(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
jne    121c <get_dir_size+0x6c>
jmp    1280 <get_dir_size+0xd0>
mov    %ebx,%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
lea    0xcc9(%rip),%rbx
je     1280 <get_dir_size+0xd0>
mov    %r13,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <get_dir_size@plt>
jmp    1280 <get_dir_size+0xd0>
mov    %r14,%rdi
call   1090 <closedir@plt>
mov    -0x40(%rbp),%rbx
mov    %rbx,%rsp
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 { i32, i64 }
@MAXPATHLEN = global i32 0
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [12 x i8] c"file_id.diz\00"
@.str.3 = [9 x i8] c".message\00"
@.str.4 = [5 x i8] c".nfo\00"
@.str.5 = [6 x i8] c"%s/%s\00"
define void @get_dir_size(i8* %0, i32* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca %struct.stat
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
store i64* %2, i64** %6
%12 = load i32, i32* @MAXPATHLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %10
%15 = alloca i8, i64 %13
store i64 %13, i64* %11
%16 = load i8*, i8** %4
%17 = call i32* @opendir(i8* %16)
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %108
20: ; preds = %3
br label %21
21: ; preds = %104, %72, %52, %20
br label %22
22: ; preds = %21
%23 = load i32*, i32** %7
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %8
%25 = load %struct.dirent*, %struct.dirent** %8
%26 = icmp ne %struct.dirent* %25, null
br i1 %26, label %28, label %27
27: ; preds = %22
br label %105
28: ; preds = %22
%29 = load %struct.dirent*, %struct.dirent** %8
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %52
34: ; preds = %28
%35 = load %struct.dirent*, %struct.dirent** %8
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %34
%41 = load %struct.dirent*, %struct.dirent** %8
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i32 0, i32 0
%43 = load i8*, i8** %42
%44 = call i32 @strcasecmp(i8* %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %40
%47 = load %struct.dirent*, %struct.dirent** %8
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i8*, i8** %48
%50 = call i32 @strcmp(i8* %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %46, %40, %34, %28
br label %21
53: ; preds = %46
%54 = load %struct.dirent*, %struct.dirent** %8
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = call i32 @strlen(i8* %56)
%58 = icmp sgt i32 %57, 3
br i1 %58, label %59, label %74
59: ; preds = %53
%60 = load %struct.dirent*, %struct.dirent** %8
%61 = getelementptr inbounds %struct.dirent, %struct.dirent* %60, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = load %struct.dirent*, %struct.dirent** %8
%64 = getelementptr inbounds %struct.dirent, %struct.dirent* %63, i32 0, i32 0
%65 = load i8*, i8** %64
%66 = call i32 @strlen(i8* %65)
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %62, i64 %67
%69 = getelementptr inbounds i8, i8* %68, i64 -4
%70 = call i32 @strcasecmp(i8* %69, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%71 = icmp ne i32 %70, 0
br i1 %71, label %73, label %72
72: ; preds = %59
br label %21
73: ; preds = %59
br label %74
74: ; preds = %73, %53
%75 = load i32, i32* @MAXPATHLEN
%76 = load i8*, i8** %4
%77 = load %struct.dirent*, %struct.dirent** %8
%78 = getelementptr inbounds %struct.dirent, %struct.dirent* %77, i32 0, i32 0
%79 = load i8*, i8** %78
%80 = call i32 @snprintf(i8* %15, i32 %75, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %76, i8* %79)
%81 = call i32 @stat(i8* %15, %struct.stat* %9)
%82 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%83 = load i32, i32* %82
%84 = call i64 @S_ISREG(i32 %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %95
86: ; preds = %74
%87 = load i32*, i32** %5
%88 = load i32, i32* %87
%89 = add nsw i32 %88, 1
store i32 %89, i32* %87
%90 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%91 = load i64, i64* %90
%92 = load i64*, i64** %6
%93 = load i64, i64* %92
%94 = add i64 %93, %91
store i64 %94, i64* %92
br label %104
95: ; preds = %74
%96 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%97 = load i32, i32* %96
%98 = call i64 @S_ISDIR(i32 %97)
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %95
%101 = load i32*, i32** %5
%102 = load i64*, i64** %6
br label %103
103: ; preds = %100, %95
br label %104
104: ; preds = %103, %86
br label %21
105: ; preds = %27
%106 = load i32*, i32** %7
%107 = call i32 @closedir(i32* %106)
br label %108
108: ; preds = %105, %3
%109 = load i8*, i8** %10
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
%struct.dirent = type { i8* }
@MAXPATHLEN = global i32 0
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [12 x i8] c"file_id.diz\00"
@.str.3 = [9 x i8] c".message\00"
@.str.4 = [5 x i8] c".nfo\00"
@.str.5 = [6 x i8] c"%s/%s\00"
define void @get_dir_size(i8* %0, i32* nocapture %1, i64* nocapture %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = load i32, i32* @MAXPATHLEN
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = tail call i32* @opendir(i8* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %67, label %12
12: ; preds = %3
%13 = call %struct.dirent* @readdir(i32* %10)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %65, label %15
15: ; preds = %12
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
br label %18
18: ; preds = %15, %33
%19 = phi %struct.dirent* [ %13, %15 ], [ %34, %33 ]
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %18
%25 = call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %24
%28 = call i32 @strcasecmp(i8* %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %55, %64, %61, %18, %24, %27, %30, %39
%34 = call %struct.dirent* @readdir(i32* %10)
%35 = icmp eq %struct.dirent* %34, null
br i1 %35, label %65, label %18
36: ; preds = %30
%37 = call i32 @strlen(i8* %21)
%38 = icmp sgt i32 %37, 3
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = load i8*, i8** %20
%41 = call i32 @strlen(i8* %40)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 -4
%44 = getelementptr inbounds i8, i8* %43, i64 %42
%45 = call i32 @strcasecmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i32 %45, 0
br i1 %46, label %33, label %47
47: ; preds = %39, %36
%48 = load i32, i32* @MAXPATHLEN
%49 = load i8*, i8** %20
%50 = call i32 @snprintf(i8* %9, i32 %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %49)
%51 = call i32 @stat(i8* %9, %struct.stat* %4)
%52 = load i32, i32* %16
%53 = call i64 @S_ISREG(i32 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %61, label %55
55: ; preds = %47
%56 = load i32, i32* %1
%57 = add nsw i32 %56, 1
store i32 %57, i32* %1
%58 = load i64, i64* %17
%59 = load i64, i64* %2
%60 = add i64 %59, %58
store i64 %60, i64* %2
br label %33
61: ; preds = %47
%62 = call i64 @S_ISDIR(i32 %52)
%63 = icmp eq i64 %62, 0
br i1 %63, label %33, label %64
64: ; preds = %61
br label %33
65: ; preds = %33, %12
%66 = call i32 @closedir(i32* %10)
br label %67
67: ; preds = %65, %3
ret void
}