#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 {
  char *st_size;
};
typedef char *off_t;

/* Variables and functions */
int errno;
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int filesizes(char *str_path) {
  struct stat buf;
  if (lstat(str_path, &buf) < 0) {
    perror("stat() failed");
    return errno;
  }
  off_t filesize = buf.st_size;
  printf("%5llub\t", filesize);
  printf("%s\n", str_path);
  return 0;
}


x86 assembly (clang, -O0):
<filesizes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jge    1170 <filesizes+0x40>
lea    0xea6(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    119f <filesizes+0x6f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filesizes>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <lstat@plt>
test   %rax,%rax
js     116f <filesizes+0x3f>
mov    0x8(%rsp),%rsi
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
jmp    1169 <filesizes+0x39>

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

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