#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 */
int /*<<< orphan*/ _PC_PATH_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
long double file_size(char *);
char *getcwd(char *, size_t);
int /*<<< orphan*/ humanize(long double, char *);
int is_digit(char *);
scalar_t__ isdir(char *);
scalar_t__ malloc(size_t);
long pathconf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
long double walk_dir_size(char *, int);
int main(int argc, char *argv[]) {
  long double bytes_cnt;
  char output[24];
  long size;
  char *buf;
  char *fp;
  char *cwd;
  size = pathconf(".", _PC_PATH_MAX);
  if ((buf = (char *)malloc((size_t)size)) != NULL)
    cwd = getcwd(buf, (size_t)size);
  if (argc == 1) {
    fp = cwd;
  }
  if (argc > 1) {
    if (is_digit(argv[1]) == 1) {
      fp = argv[1];
    } else {
      printf("Not implemented");
      exit(0);
    }
  }
  if (isdir(fp)) {
    bytes_cnt = walk_dir_size(fp, (1 << 0));
  } else {
    bytes_cnt = file_size(fp);
  }
  humanize(bytes_cnt, output);
  printf("%s\n", output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
lea    0xe3a(%rip),%rdi
call   1040 <pathconf@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     11f7 <main+0x57>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1070 <getcwd@plt>
mov    %rax,-0x60(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1209 <main+0x69>
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1254 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <is_digit@plt>
cmp    $0x1,%eax
jne    123a <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    124f <main+0xaf>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    1254 <main+0xb4>
mov    -0x58(%rbp),%rdi
call   1090 <isdir@plt>
cmp    $0x0,%rax
je     127d <main+0xdd>
mov    -0x58(%rbp),%rdi
mov    $0x1,%esi
call   1050 <walk_dir_size@plt>
fstpt  -0x20(%rbp)
jmp    1289 <main+0xe9>
mov    -0x58(%rbp),%rdi
call   1080 <file_size@plt>
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <humanize@plt>
lea    -0x40(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    0xe33(%rip),%rdi
call   1050 <pathconf@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     11f7 <main+0x47>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1080 <getcwd@plt>
mov    %rax,%rbx
cmp    $0x2,%ebp
jge    11fc <main+0x4c>
jmp    120e <main+0x5e>
cmp    $0x2,%ebp
jl     120e <main+0x5e>
mov    0x8(%r14),%rdi
call   10c0 <is_digit@plt>
cmp    $0x1,%eax
jne    1252 <main+0xa2>
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   10a0 <isdir@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     122a <main+0x7a>
mov    $0x1,%esi
call   1060 <walk_dir_size@plt>
jmp    122f <main+0x7f>
call   1090 <file_size@plt>
fstpt  (%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <humanize@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@_PC_PATH_MAX = global i32 0
@.str.1 = [16 x i8] c"Not implemented\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca x86_fp80
%7 = alloca [24 x i8]
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @_PC_PATH_MAX
%13 = call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %12)
store i64 %13, i64* %8
%14 = load i64, i64* %8
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i8*, i8** %9
%20 = load i64, i64* %8
%21 = call i8* @getcwd(i8* %19, i64 %20)
store i8* %21, i8** %11
br label %22
22: ; preds = %18, %2
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i8*, i8** %11
store i8* %26, i8** %10
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %44
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @is_digit(i8* %33)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
store i8* %39, i8** %10
br label %43
40: ; preds = %30
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %36
br label %44
44: ; preds = %43, %27
%45 = load i8*, i8** %10
%46 = call i64 @isdir(i8* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i8*, i8** %10
%50 = call x86_fp80 @walk_dir_size(i8* %49, i32 1)
store x86_fp80 %50, x86_fp80* %6
br label %54
51: ; preds = %44
%52 = load i8*, i8** %10
%53 = call x86_fp80 @file_size(i8* %52)
store x86_fp80 %53, x86_fp80* %6
br label %54
54: ; preds = %51, %48
%55 = load x86_fp80, x86_fp80* %6
%56 = getelementptr inbounds [24 x i8], [24 x i8]* %7, i64 0, i64 0
%57 = call i32 @humanize(x86_fp80 %55, i8* %56)
%58 = getelementptr inbounds [24 x i8], [24 x i8]* %7, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@_PC_PATH_MAX = global i32 0
@.str.1 = [16 x i8] c"Not implemented\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [24 x i8]
%4 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @_PC_PATH_MAX
%6 = tail call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i64 @malloc(i64 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = inttoptr i64 %7 to i8*
%11 = tail call i8* @getcwd(i8* %10, i64 %6)
br label %12
12: ; preds = %9, %2
%13 = phi i8* [ %11, %9 ], [ undef, %2 ]
%14 = icmp sgt i32 %0, 1
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @is_digit(i8* %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i8*, i8** %16
br label %25
22: ; preds = %15
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %20, %12
%26 = phi i8* [ %21, %20 ], [ %13, %12 ]
%27 = tail call i64 @isdir(i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = tail call x86_fp80 @walk_dir_size(i8* %26, i32 1)
br label %33
31: ; preds = %25
%32 = tail call x86_fp80 @file_size(i8* %26)
br label %33
33: ; preds = %31, %29
%34 = phi x86_fp80 [ %30, %29 ], [ %32, %31 ]
%35 = call i32 @humanize(x86_fp80 %34, i8* %4)
%36 = call i32 @puts(i8* %4)
ret i32 0
}