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

/* Variables and functions */
unsigned long directoryOnFileSize(int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned long);
int main(int argc, char **argv) {
  char *dir;
  unsigned long size = 0;
  if (argc == 1) {
    dir = ".";
  } else if (argc == 2)
    dir = argv[1];
  else
    perror(dir);
  size = directoryOnFileSize(opendir(dir), dir);
  printf("Total Size : %zu\n", size);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1188 <main+0x38>
lea    0xe81(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11b1 <main+0x61>
cmpl   $0x2,-0x8(%rbp)
jne    11a3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11ac <main+0x5c>
mov    -0x18(%rbp),%rdi
call   1060 <perror@plt>
jmp    11b1 <main+0x61>
mov    -0x18(%rbp),%rdi
call   1030 <opendir@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1050 <directoryOnFileSize@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
je     1188 <main+0x38>
cmp    $0x2,%edi
je     1191 <main+0x41>
call   1060 <perror@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <directoryOnFileSize@plt>
lea    0xe89(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe71(%rip),%rbx
jmp    1160 <main+0x10>
mov    0x8(%rsi),%rbx
jmp    1160 <main+0x10>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [18 x i8] c"Total Size : %zu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
br label %22
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
br label %21
18: ; preds = %11
%19 = load i8*, i8** %6
%20 = call i32 @perror(i8* %19)
br label %21
21: ; preds = %18, %14
br label %22
22: ; preds = %21, %10
%23 = load i8*, i8** %6
%24 = call i32 @opendir(i8* %23)
%25 = load i8*, i8** %6
%26 = call i64 @directoryOnFileSize(i32 %24, i8* %25)
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %27)
%29 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [18 x i8] c"Total Size : %zu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %6 [
i32 1, label %8
i32 2, label %3
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
br label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* undef)
br label %8
8: ; preds = %2, %3, %6
%9 = phi i8* [ %5, %3 ], [ undef, %6 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = tail call i32 @opendir(i8* %9)
%11 = tail call i64 @directoryOnFileSize(i32 %10, i8* %9)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%13 = tail call i32 @exit(i32 0)
unreachable
}