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

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ dirwalk(char const *, void (*)(char const *));
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, char const *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
void fsize(const char *name) {
  struct stat sbuff;
  if (stat(name, &sbuff) < 0) {
    fprintf(stderr, "can't access %s: ", name);
    perror(NULL);
    return;
  }
  if (S_ISDIR(sbuff.st_mode)) {
    dirwalk(name, fsize);
  }
  printf("%8ld %s\n", sbuff.st_size, name);
}


x86 assembly (clang, -O0):
<fsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    11aa <fsize+0x4a>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
jmp    11df <fsize+0x7f>
mov    -0xc(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11cc <fsize+0x6c>
mov    -0x8(%rbp),%rdi
mov    0x2e21(%rip),%rsi
call   1070 <dirwalk@plt>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsize>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     11ad <fsize+0x4d>
mov    0xc(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     1194 <fsize+0x34>
mov    0x2e5c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <dirwalk@plt>
mov    0x8(%rsp),%esi
lea    0xe73(%rip),%rdi
mov    %rbx,%rdx
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1080 <perror@plt>
jmp    11a7 <fsize+0x47>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"can't access %s: \00"
@.str.1 = [9 x i8] c"%8ld %s\0A\00"
define void @fsize(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @stat(i8* %4, %struct.stat* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %2
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32 @perror(i32* null)
br label %25
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i64 @S_ISDIR(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8*, i8** %2
%19 = call i32 @dirwalk(i8* %18, void (i8*)* @fsize)
br label %20
20: ; preds = %17, %12
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %23)
br label %25
25: ; preds = %20, %7
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"can't access %s: \00"
@.str.1 = [9 x i8] c"%8ld %s\0A\00"
define void @fsize(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32 @perror(i32* null)
br label %21
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%12 = load i32, i32* %11
%13 = call i64 @S_ISDIR(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = call i32 @dirwalk(i8* %0, void (i8*)* @fsize)
br label %17
17: ; preds = %15, %10
%18 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %0)
br label %21
21: ; preds = %17, %6
ret void
}