#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_blocks;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
scalar_t__ lstat(char const *, struct stat *);
int /*<<< orphan*/ printf(char *, int, char const *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int listfile_size(const char *path, const char *filename, int flags) {
  struct stat s;
  if (lstat(path, &s) < 0) {
    fprintf(stderr, "lstat '%s' failed: %s\n", path, strerror(errno));
    return -1;
  }
  printf("%lld %s\n", s.st_blocks / 2, filename);
  return 0;
}


x86 assembly (clang, -O0):
<listfile_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jge    11ae <listfile_size+0x6e>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <listfile_size+0x92>
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listfile_size>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <lstat@plt>
test   %rax,%rax
js     117d <listfile_size+0x3d>
mov    0x8(%rsp),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
lea    0xea6(%rip),%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11ad <listfile_size+0x6d>
mov    0x2e5c(%rip),%rax
mov    (%rax),%ebp
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe65(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"lstat '%s' failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [9 x i8] c"%lld %s\0A\00"
define i32 @listfile_size(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i64 @lstat(i8* %0, %struct.stat* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %11)
br label %18
13: ; preds = %3
%14 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%15 = load i32, i32* %14
%16 = sdiv i32 %15, 2
%17 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %1)
br label %18
18: ; preds = %13, %8
%19 = phi i32 [ -1, %8 ], [ 0, %13 ]
ret i32 %19
}