#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 */
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int u_int64_t;
typedef int int64_t;
struct TYPE_5__ {
  int fts_info;
  TYPE_1__ *fts_statp;
};
struct TYPE_4__ {
  int st_size;
};
typedef TYPE_2__ FTSENT;
typedef int /*<<< orphan*/ FTS;

/* Variables and functions */
#define FTS_D 133
#define FTS_DNR 132
#define FTS_ERR 131
#define FTS_NS 130
int /*<<< orphan*/ FTS_PHYSICAL;
#define FTS_SL 129
#define FTS_SLNONE 128
int /*<<< orphan*/ fts_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fts_open(char **, int /*<<< orphan*/, int /*<<< orphan*/);
TYPE_2__ *fts_read(int /*<<< orphan*/ *);
int64_t PBFolderSize4KRounded(const char *inPath) {
  FTS *ftsp;
  FTSENT *tFile;
  char *tPath[2] = {(char *)inPath, NULL};
  int64_t tFolderSize = 0;
  if ((ftsp = fts_open(tPath, FTS_PHYSICAL, 0)) == NULL) {
    return -1;
  }
  while ((tFile = fts_read(ftsp)) != NULL) {
    u_int64_t tFileSize;
    switch (tFile->fts_info) {
    case FTS_D:
    case FTS_SL:
    case FTS_SLNONE:
      continue;
    case FTS_DNR:
    case FTS_ERR:
    case FTS_NS:
      fts_close(ftsp);
      return -1;
    default:
      break;
    }
    tFileSize = tFile->fts_statp->st_size;
    tFolderSize += ((tFileSize + 0xFFF) >> 12) << 2;
  }
  fts_close(ftsp);
  return tFolderSize;
}


x86 assembly (clang, -O0):
<PBFolderSize4KRounded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <fts_open@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1181 <PBFolderSize4KRounded+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    1234 <PBFolderSize4KRounded+0x104>
jmp    1186 <PBFolderSize4KRounded+0x56>
mov    -0x18(%rbp),%rdi
call   1040 <fts_read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1225 <PBFolderSize4KRounded+0xf5>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     11e0 <PBFolderSize4KRounded+0xb0>
jmp    11b7 <PBFolderSize4KRounded+0x87>
mov    -0x3c(%rbp),%eax
add    $0xffffff7e,%eax
sub    $0x3,%eax
jb     11e5 <PBFolderSize4KRounded+0xb5>
jmp    11cd <PBFolderSize4KRounded+0x9d>
mov    -0x3c(%rbp),%eax
sub    $0x85,%eax
jne    11fa <PBFolderSize4KRounded+0xca>
jmp    11e0 <PBFolderSize4KRounded+0xb0>
jmp    1186 <PBFolderSize4KRounded+0x56>
mov    -0x18(%rbp),%rdi
call   1030 <fts_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1234 <PBFolderSize4KRounded+0x104>
jmp    11ff <PBFolderSize4KRounded+0xcf>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0xfff,%eax
sar    $0xc,%eax
shl    $0x2,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1186 <PBFolderSize4KRounded+0x56>
mov    -0x18(%rbp),%rdi
call   1030 <fts_close@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PBFolderSize4KRounded>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %edx,%edx
call   1050 <fts_open@plt>
test   %rax,%rax
je     11cd <PBFolderSize4KRounded+0x9d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fts_read@plt>
test   %rax,%rax
je     11c3 <PBFolderSize4KRounded+0x93>
xor    %ebp,%ebp
mov    $0xfff,%r14d
mov    $0x23,%r15d
jmp    11ae <PBFolderSize4KRounded+0x7e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rax),%rax
mov    (%rax),%eax
add    %r14d,%eax
sar    $0xa,%eax
and    $0xfffffffc,%eax
add    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fts_read@plt>
test   %rax,%rax
je     11c3 <PBFolderSize4KRounded+0x93>
mov    (%rax),%ecx
add    $0xffffff80,%ecx
cmp    $0x5,%ecx
ja     1190 <PBFolderSize4KRounded+0x60>
bt     %ecx,%r15d
jb     11a1 <PBFolderSize4KRounded+0x71>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <fts_close@plt>
jmp    11d2 <PBFolderSize4KRounded+0xa2>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__* }
%struct.TYPE_4__ = type { i32 }
@FTS_PHYSICAL = global i32 0
define i32 @PBFolderSize4KRounded(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.TYPE_5__*
%6 = alloca [2 x i8*]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%10 = load i8*, i8** %3
store i8* %10, i8** %9
%11 = getelementptr inbounds i8*, i8** %9, i64 1
store i8* null, i8** %11
store i32 0, i32* %7
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%13 = load i32, i32* @FTS_PHYSICAL
%14 = call i32* @fts_open(i8** %12, i32 %13, i32 0)
store i32* %14, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -1, i32* %2
br label %47
17: ; preds = %1
br label %18
18: ; preds = %31, %26, %17
%19 = load i32*, i32** %4
%20 = call %struct.TYPE_5__* @fts_read(i32* %19)
store %struct.TYPE_5__* %20, %struct.TYPE_5__** %5
%21 = icmp ne %struct.TYPE_5__* %20, null
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %23, i32 0, i32 0
%25 = load i32, i32* %24
switch i32 %25, label %30 [
i32 133, label %26
i32 129, label %26
i32 128, label %26
i32 132, label %27
i32 131, label %27
i32 130, label %27
]
26: ; preds = %22, %22, %22
br label %18
27: ; preds = %22, %22, %22
%28 = load i32*, i32** %4
%29 = call i32 @fts_close(i32* %28)
store i32 -1, i32* %2
br label %47
30: ; preds = %22
br label %31
31: ; preds = %30
%32 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%33 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %32, i32 0, i32 1
%34 = load %struct.TYPE_4__*, %struct.TYPE_4__** %33
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %34, i32 0, i32 0
%36 = load i32, i32* %35
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 4095
%39 = ashr i32 %38, 12
%40 = shl i32 %39, 2
%41 = load i32, i32* %7
%42 = add nsw i32 %41, %40
store i32 %42, i32* %7
br label %18
43: ; preds = %18
%44 = load i32*, i32** %4
%45 = call i32 @fts_close(i32* %44)
%46 = load i32, i32* %7
store i32 %46, i32* %2
br label %47
47: ; preds = %43, %27, %16
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, %struct.TYPE_4__* }
%struct.TYPE_4__ = type { i32 }
@FTS_PHYSICAL = global i32 0
define i32 @PBFolderSize4KRounded(i8* %0) {
%2 = alloca [2 x i8*]
%3 = bitcast [2 x i8*]* %2 to i8*
%4 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
store i8* %0, i8** %4
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
store i8* null, i8** %5
%6 = load i32, i32* @FTS_PHYSICAL
%7 = call i32* @fts_open(i8** %4, i32 %6, i32 0)
%8 = icmp eq i32* %7, null
br i1 %8, label %33, label %9
9: ; preds = %1
%10 = call %struct.TYPE_5__* @fts_read(i32* %7)
%11 = icmp eq %struct.TYPE_5__* %10, null
br i1 %11, label %30, label %12
12: ; preds = %9, %26
%13 = phi %struct.TYPE_5__* [ %28, %26 ], [ %10, %9 ]
%14 = phi i32 [ %27, %26 ], [ 0, %9 ]
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 0
%16 = load i32, i32* %15
switch i32 %16, label %17 [
i32 133, label %26
i32 129, label %26
i32 128, label %26
i32 132, label %30
i32 131, label %30
i32 130, label %30
]
17: ; preds = %12
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i64 0, i32 1
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %18
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %19, i64 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 4095
%23 = ashr i32 %22, 10
%24 = and i32 %23, -4
%25 = add nsw i32 %24, %14
br label %26
26: ; preds = %12, %12, %12, %17
%27 = phi i32 [ %25, %17 ], [ %14, %12 ], [ %14, %12 ], [ %14, %12 ]
%28 = call %struct.TYPE_5__* @fts_read(i32* %7)
%29 = icmp eq %struct.TYPE_5__* %28, null
br i1 %29, label %30, label %12
30: ; preds = %26, %12, %12, %12, %9
%31 = phi i32 [ 0, %9 ], [ -1, %12 ], [ -1, %12 ], [ -1, %12 ], [ %27, %26 ]
%32 = call i32 @fts_close(i32* %7)
br label %33
33: ; preds = %30, %1
%34 = phi i32 [ -1, %1 ], [ %31, %30 ]
ret i32 %34
}