#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;
  scalar_t__ st_size;
};

/* Variables and functions */
int S_IFMT;
int S_IFREG;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct stat st;
  if (argc != 2) {
    fprintf(stderr, "Usage: filesize file\n");
    exit(-1);
  }
  if (stat(argv[1], &st) < 0) {
    perror(argv[1]);
    exit(-1);
  }
  if ((st.st_mode & S_IFMT) != S_IFREG) {
    fprintf(stderr, "%s: %s is not the regular file\n", argv[0], argv[1]);
    exit(-1);
  }
  printf("%ld\n", (long)st.st_size);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1191 <main+0x41>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11c3 <main+0x73>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%eax
mov    0x2e0b(%rip),%rcx
and    (%rcx),%eax
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%eax
je     120e <main+0xbe>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    119e <main+0x4e>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     11bf <main+0x6f>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%eax
jne    11d2 <main+0x82>
mov    0x8(%rsp),%rsi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    0x8(%rbx),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
lea    0xe2d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@stderr = global i32 0
@.str = [22 x i8] c"Usage: filesize file\0A\00"
@S_IFMT = global i32 0
@S_IFREG = global i32 0
@.str.1 = [32 x i8] c"%s: %s is not the regular file\0A\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @stat(i8* %16, %struct.stat* %6)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @perror(i8* %22)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %13
%26 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i32, i32* @S_IFMT
%29 = and i32 %27, %28
%30 = load i32, i32* @S_IFREG
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %25
%43 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%44 = load i64, i64* %43
%45 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %44)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@stderr = global i32 0
@.str = [22 x i8] c"Usage: filesize file\0A\00"
@S_IFMT = global i32 0
@S_IFREG = global i32 0
@.str.1 = [32 x i8] c"%s: %s is not the regular file\0A\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @stat(i8* %12, %struct.stat* %3)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = call i32 @perror(i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* @S_IFMT
%23 = and i32 %22, %21
%24 = load i32, i32* @S_IFREG
%25 = icmp eq i32 %23, %24
br i1 %25, label %32, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = load i8*, i8** %11
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29)
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %19
%33 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%34 = load i64, i64* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %34)
ret i32 0
}