#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 */
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  int fd;
  off_t size;
  if (argc != 2) {
    printf("E: Need a filename as an argument.\n");
    return EXIT_FAILURE;
  }
  if ((fd = open(argv[1], O_RDONLY)) == -1) {
    perror("E: Can not open input file");
    exit(EXIT_FAILURE);
  }
  size = lseek(fd, 0, SEEK_END);
  setlocale(LC_ALL, "");
  printf("\nFile size: %'zi\n", size);
  return EXIT_SUCCESS;
}


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     119f <main+0x3f>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11db <main+0x7b>
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1050 <setlocale@plt>
mov    -0x18(%rbp),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11cf <main+0x5f>
mov    0x8(%rsi),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11e6 <main+0x76>
mov    0x2e54(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%ebx
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xe5e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dfb(%rip),%rax
jmp    11e2 <main+0x72>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"E: Need a filename as an argument.\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [27 x i8] c"E: Can not open input file\00"
@SEEK_END = global i32 0
@LC_ALL = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [18 x i8] c"\0AFile size: %'zi\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %3
br label %33
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %13
%25 = load i32, i32* %6
%26 = load i32, i32* @SEEK_END
%27 = call i32 @lseek(i32 %25, i32 0, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* @LC_ALL
%29 = call i32 @setlocale(i32 %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @EXIT_SUCCESS
store i32 %32, i32* %3
br label %33
33: ; preds = %24, %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [27 x i8] c"E: Can not open input file\00"
@SEEK_END = global i32 0
@LC_ALL = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [18 x i8] c"\0AFile size: %'zi\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [35 x i8] c"E: Need a filename as an argument.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %6
%17 = load i32, i32* @SEEK_END
%18 = tail call i32 @lseek(i32 %10, i32 0, i32 %17)
%19 = load i32, i32* @LC_ALL
%20 = tail call i32 @setlocale(i32 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %22
22: ; preds = %16, %4
%23 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %16 ]
%24 = load i32, i32* %23
ret i32 %24
}