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

/* Variables and functions */
scalar_t__ S_ISDIR(int);
int /*<<< orphan*/ dirwalk(char *, void (*)(char *));
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/, int /*<<< orphan*/,
                          char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
void fsize(char *name) {
  struct stat stbuf;
  if (stat(name, &stbuf) == -1) {
    fprintf(stderr, "fsize: can't access %s\n", name);
    return;
  }
  if (S_ISDIR(stbuf.st_mode))
    dirwalk(name, fsize);
  printf("%6o  %5ld %10ld %s\n", stbuf.st_mode, stbuf.st_ino, stbuf.st_size,
         name);
}


x86 assembly (clang, -O0):
<fsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    1190 <fsize+0x40>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe7a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11cb <fsize+0x7b>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11b2 <fsize+0x62>
mov    -0x8(%rbp),%rdi
mov    0x2e3b(%rip),%rsi
call   1070 <dirwalk@plt>
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%r8
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsize>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     11a6 <fsize+0x56>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     1187 <fsize+0x37>
mov    0x2e69(%rip),%rsi
mov    %rbx,%rdi
call   1070 <dirwalk@plt>
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%edx
lea    0xe82(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%r8
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdx
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fprintf@plt>

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

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