#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 {
  scalar_t__ st_size;
  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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, long, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
long rdu(char *dirname) {
  DIR *p_dir;
  struct dirent *p_struct_dir;
  struct stat statbuf;
  long byte_size = 0L;
  char filename[1024];
  if ((p_dir = opendir(dirname)) == NULL) {
    (void)fprintf(stderr, "opendir error : %s", strerror(errno));
    return (0L);
  }
  while ((p_struct_dir = readdir(p_dir)) != NULL) {
    if (strcmp(p_struct_dir->d_name, "..") == 0)
      continue;
    (void)sprintf(filename, "%s/%s", dirname, p_struct_dir->d_name);
    if (lstat(filename, &statbuf) != 0) {
      (void)fprintf(stderr, "lstat error (%s) : %s", filename, strerror(errno));
      continue;
    }
    if (S_ISDIR(statbuf.st_mode)) {
      if (strcmp(p_struct_dir->d_name, ".") != 0)
        byte_size += rdu(filename);
      continue;
    }
    byte_size += statbuf.st_size;
  }
  closedir(p_dir);
  if (byte_size)
    (void)printf("%ld\t%s\n", byte_size / 1024, dirname);
  return (byte_size);
}


x86 assembly (clang, -O0):
<rdu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121f <rdu+0x6f>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x444(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x444(%rbp),%edi
mov    %rax,%rdx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1379 <rdu+0x1c9>
jmp    1224 <rdu+0x74>
mov    -0x18(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     133c <rdu+0x18c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xdca(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    125d <rdu+0xad>
jmp    1224 <rdu+0x74>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xda0(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x440(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <lstat@plt>
cmp    $0x0,%rax
je     12e3 <rdu+0x133>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x454(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rdx
mov    %rax,%rcx
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1224 <rdu+0x74>
mov    -0x28(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     132b <rdu+0x17b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd11(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1326 <rdu+0x176>
lea    -0x440(%rbp),%rdi
call   1030 <rdu@plt>
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1224 <rdu+0x74>
mov    -0x30(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1224 <rdu+0x74>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
cmpq   $0x0,-0x38(%rbp)
je     1371 <rdu+0x1c1>
mov    -0x38(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,%rsi
mov    -0x10(%rbp),%rdx
lea    0xcc6(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rdi,%r15
call   1040 <opendir@plt>
test   %rax,%rax
je     12f1 <rdu+0x141>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     131f <rdu+0x16f>
mov    %rax,%r13
lea    0xe23(%rip),%r12
lea    0x20(%rsp),%r14
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    123d <rdu+0x8d>
xchg   %ax,%ax
mov    0x2dd9(%rip),%rax
mov    (%rax),%ebp
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %ebp,%edi
lea    0xdfc(%rip),%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     12bc <rdu+0x10c>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     122d <rdu+0x7d>
mov    0x0(%r13),%rcx
mov    %r14,%rdi
lea    0xdba(%rip),%rsi
mov    %r15,%rdx
call   10c0 <sprintf@plt>
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
call   1080 <lstat@plt>
test   %rax,%rax
jne    1200 <rdu+0x50>
mov    0x18(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     12a8 <rdu+0xf8>
mov    0x0(%r13),%rdi
lea    0xd85(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     122d <rdu+0x7d>
mov    %r14,%rdi
call   1030 <rdu@plt>
add    %rax,0x8(%rsp)
jmp    122d <rdu+0x7d>
mov    0x8(%rsp),%rax
add    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
jmp    122d <rdu+0x7d>
mov    %rbx,%rdi
call   1070 <closedir@plt>
mov    0x8(%rsp),%rbp
test   %rbp,%rbp
je     1327 <rdu+0x177>
lea    0x3ff(%rbp),%rsi
test   %rbp,%rbp
cmovns %rbp,%rsi
sar    $0xa,%rsi
lea    0xd4b(%rip),%rdi
mov    %r15,%rdx
call   1050 <printf@plt>
jmp    1329 <rdu+0x179>
mov    0x2ce8(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xcf1(%rip),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1329 <rdu+0x179>
mov    %rbx,%rdi
call   1070 <closedir@plt>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x428,%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 }
@stderr = global i32 0
@.str = [19 x i8] c"opendir error : %s\00"
@errno = global i32 0
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [22 x i8] c"lstat error (%s) : %s\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [8 x i8] c"%ld\09%s\0A\00"
define i64 @rdu(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
%6 = alloca %struct.stat
%7 = alloca i64
%8 = alloca [1024 x i8]
store i8* %0, i8** %3
store i64 0, i64* %7
%9 = load i8*, i8** %3
%10 = call i32* @opendir(i8* %9)
store i32* %10, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
store i64 0, i64* %2
br label %79
17: ; preds = %1
br label %18
18: ; preds = %62, %61, %39, %28, %17
%19 = load i32*, i32** %4
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %5
%21 = icmp ne %struct.dirent* %20, null
br i1 %21, label %22, label %67
22: ; preds = %18
%23 = load %struct.dirent*, %struct.dirent** %5
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
br label %18
29: ; preds = %22
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%31 = load i8*, i8** %3
%32 = load %struct.dirent*, %struct.dirent** %5
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %34)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%37 = call i64 @lstat(i8* %36, %struct.stat* %6)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %29
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %41, i8* %43)
br label %18
45: ; preds = %29
%46 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%47 = load i32, i32* %46
%48 = call i64 @S_ISDIR(i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %62
50: ; preds = %45
%51 = load %struct.dirent*, %struct.dirent** %5
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %50
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%58 = call i64 @rdu(i8* %57)
%59 = load i64, i64* %7
%60 = add nsw i64 %59, %58
store i64 %60, i64* %7
br label %61
61: ; preds = %56, %50
br label %18
62: ; preds = %45
%63 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%64 = load i64, i64* %63
%65 = load i64, i64* %7
%66 = add nsw i64 %65, %64
store i64 %66, i64* %7
br label %18
67: ; preds = %18
%68 = load i32*, i32** %4
%69 = call i32 @closedir(i32* %68)
%70 = load i64, i64* %7
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %67
%73 = load i64, i64* %7
%74 = sdiv i64 %73, 1024
%75 = load i8*, i8** %3
%76 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 %74, i8* %75)
br label %77
77: ; preds = %72, %67
%78 = load i64, i64* %7
store i64 %78, i64* %2
br label %79
79: ; preds = %77, %12
%80 = load i64, i64* %2
ret i64 %80
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [19 x i8] c"opendir error : %s\00"
@errno = global i32 0
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [22 x i8] c"lstat error (%s) : %s\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [8 x i8] c"%ld\09%s\0A\00"
define i64 @rdu(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca [1024 x i8]
%4 = bitcast %struct.stat* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @opendir(i8* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %16, label %8
8: ; preds = %1
%9 = call %struct.dirent* @readdir(i32* %6)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @closedir(i32* %6)
br label %68
13: ; preds = %8
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %55
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %68
21: ; preds = %55, %37
%22 = phi %struct.dirent* [ %56, %55 ], [ %38, %37 ]
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %37, label %27
27: ; preds = %21
%28 = load i8*, i8** %23
%29 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %28)
%30 = call i64 @lstat(i8* %5, %struct.stat* %2)
%31 = icmp eq i64 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %35)
br label %37
37: ; preds = %32, %21
%38 = call %struct.dirent* @readdir(i32* %6)
%39 = icmp eq %struct.dirent* %38, null
br i1 %39, label %61, label %21
40: ; preds = %27
%41 = load i32, i32* %14
%42 = call i64 @S_ISDIR(i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %58, label %44
44: ; preds = %40
%45 = load i8*, i8** %23
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %44
%49 = call i64 @rdu(i8* %5)
%50 = add nsw i64 %49, %57
br label %51
51: ; preds = %44, %48, %58
%52 = phi i64 [ %60, %58 ], [ %50, %48 ], [ %57, %44 ]
%53 = call %struct.dirent* @readdir(i32* %6)
%54 = icmp eq %struct.dirent* %53, null
br i1 %54, label %61, label %55
55: ; preds = %13, %51
%56 = phi %struct.dirent* [ %9, %13 ], [ %53, %51 ]
%57 = phi i64 [ 0, %13 ], [ %52, %51 ]
br label %21
58: ; preds = %40
%59 = load i64, i64* %15
%60 = add nsw i64 %59, %57
br label %51
61: ; preds = %51, %37
%62 = phi i64 [ %57, %37 ], [ %52, %51 ]
%63 = call i32 @closedir(i32* %6)
%64 = icmp eq i64 %62, 0
br i1 %64, label %68, label %65
65: ; preds = %61
%66 = sdiv i64 %62, 1024
%67 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 %66, i8* %0)
br label %68
68: ; preds = %11, %61, %65, %16
%69 = phi i64 [ 0, %16 ], [ %62, %65 ], [ 0, %61 ], [ 0, %11 ]
ret i64 %69
}