#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 {
  long st_size;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
long directory_size(char const *);
scalar_t__ lstat(char const *, struct stat *);
long entry_size(const char *path) {
  struct stat buf;
  if (lstat(path, &buf) != 0)
    return -1;
  if (S_ISDIR(buf.st_mode))
    return buf.st_size + directory_size(path);
  else
    return buf.st_size;
}


x86 assembly (clang, -O0):
<entry_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
je     1160 <entry_size+0x30>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    119e <entry_size+0x6e>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1196 <entry_size+0x66>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <directory_size@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    119e <entry_size+0x6e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<entry_size>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
call   1040 <lstat@plt>
mov    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    116e <entry_size+0x3e>
mov    0x10(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    0x8(%rsp),%rbx
test   %rax,%rax
je     116e <entry_size+0x3e>
mov    %r14,%rdi
call   1050 <directory_size@plt>
add    %rax,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
define i64 @entry_size(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @lstat(i8* %5, %struct.stat* %4)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 -1, i64* %2
br label %23
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call i64 @S_ISDIR(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i8*, i8** %3
%18 = call i64 @directory_size(i8* %17)
%19 = add nsw i64 %16, %18
store i64 %19, i64* %2
br label %23
20: ; preds = %9
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%22 = load i64, i64* %21
store i64 %22, i64* %2
br label %23
23: ; preds = %20, %14, %8
%24 = load i64, i64* %2
ret i64 %24
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
define i64 @entry_size(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @lstat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%8 = load i32, i32* %7
%9 = tail call i64 @S_ISDIR(i32 %8)
%10 = icmp eq i64 %9, 0
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i64, i64* %11
br i1 %10, label %16, label %13
13: ; preds = %6
%14 = tail call i64 @directory_size(i8* %0)
%15 = add nsw i64 %14, %12
br label %16
16: ; preds = %6, %1, %13
%17 = phi i64 [ %15, %13 ], [ -1, %1 ], [ %12, %6 ]
ret i64 %17
}