#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*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ perror(char *);
int printf(char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  FILE *f;
  char *buf;
  size_t n = (1024 * 4), i, size = 0;
  if (argc != 2) {
    printf("E: Need a filename as an argument.\n");
    return EXIT_FAILURE;
  }
  if ((buf = (char *)malloc(n)) == NULL) {
    perror("E: Can not make a buffer");
    exit(EXIT_FAILURE);
  }
  if ((f = fopen(argv[1], "r")) == NULL) {
    perror("E: Can not open input file");
    exit(EXIT_FAILURE);
  }
  for (;;) {
    i = fread(buf, 1, n, f);
    if (ferror(f)) {
      perror("E: Error reading input file");
      exit(EXIT_FAILURE);
    } else if (i == 0) {
      break;
    } else {
      size += i;
    }
  }
  if (fclose(f)) {
    perror("E: Can not close input file");
    exit(EXIT_FAILURE);
  }
  setlocale(LC_ALL, "");
  return (printf("\nFile size: %'zi\n", size));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1000,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11df <main+0x4f>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1315 <main+0x185>
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1210 <main+0x80>
lea    0xe27(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    124c <main+0xbc>
lea    0xe04(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    1251 <main+0xc1>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1298 <main+0x108>
lea    0xdd3(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
jne    12a8 <main+0x118>
jmp    12be <main+0x12e>
mov    -0x30(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    12b9 <main+0x129>
jmp    1251 <main+0xc1>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     12eb <main+0x15b>
lea    0xd9c(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
call   1080 <setlocale@plt>
mov    -0x38(%rbp),%rsi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1257 <main+0xb7>
mov    %rsi,%rbx
mov    $0x1000,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12b6 <main+0x116>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
lea    0xe42(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12bf <main+0x11f>
mov    %rax,%r15
mov    $0x1000,%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    123d <main+0x9d>
xor    %r12d,%r12d
xchg   %ax,%ax
test   %rbx,%rbx
je     1278 <main+0xd8>
add    %rbx,%r12
mov    $0x1000,%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1210 <main+0x70>
lea    0xdf0(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
jne    12cb <main+0x12b>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
call   1090 <setlocale@plt>
lea    0xdcb(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <printf@plt>
lea    0xd43(%rip),%rdi
jmp    1244 <main+0xa4>
lea    0xd53(%rip),%rdi
jmp    1244 <main+0xa4>
lea    0xd7e(%rip),%rdi
jmp    1244 <main+0xa4>

LLVM IR (-O0):
@.str = [36 x i8] c"E: Need a filename as an argument.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"E: Can not make a buffer\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"E: Can not open input file\00"
@.str.4 = [28 x i8] c"E: Error reading input file\00"
@.str.5 = [28 x i8] c"E: Can not close input file\00"
@LC_ALL = global i32 0
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [18 x i8] c"\0AFile size: %'zi\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 4096, i64* %8
store i64 0, i64* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %71
16: ; preds = %2
%17 = load i64, i64* %8
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %7
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %29, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %25
br label %36
36: ; preds = %57, %35
%37 = load i8*, i8** %7
%38 = load i64, i64* %8
%39 = load i32*, i32** %6
%40 = call i64 @fread(i8* %37, i32 1, i64 %38, i32* %39)
store i64 %40, i64* %9
%41 = load i32*, i32** %6
%42 = call i64 @ferror(i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %36
%45 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %36
%49 = load i64, i64* %9
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %48
br label %58
52: ; preds = %48
%53 = load i64, i64* %9
%54 = load i64, i64* %10
%55 = add i64 %54, %53
store i64 %55, i64* %10
br label %56
56: ; preds = %52
br label %57
57: ; preds = %56
br label %36
58: ; preds = %51
%59 = load i32*, i32** %6
%60 = call i64 @fclose(i32* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %58
%63 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %58
%67 = load i32, i32* @LC_ALL
%68 = call i32 @setlocale(i32 %67, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%69 = load i64, i64* %10
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i64 %69)
store i32 %70, i32* %3
br label %71
71: ; preds = %66, %13
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"E: Can not make a buffer\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"E: Can not open input file\00"
@.str.4 = [28 x i8] c"E: Error reading input file\00"
@.str.5 = [28 x i8] c"E: Can not close input file\00"
@LC_ALL = global i32 0
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [18 x i8] c"\0AFile size: %'zi\0A\00"
@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 %7, 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))
%6 = load i32, i32* @EXIT_FAILURE
br label %52
7: ; preds = %2
%8 = tail call i64 @malloc(i64 4096)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = tail call i64 @fread(i8* %9, i32 1, i64 4096, i32* %18)
%22 = tail call i64 @ferror(i32* %18)
%23 = icmp eq i64 %22, 0
br i1 %23, label %37, label %33
24: ; preds = %15
%25 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %37
%29 = add i64 %38, %39
%30 = tail call i64 @fread(i8* %9, i32 1, i64 4096, i32* %18)
%31 = tail call i64 @ferror(i32* %18)
%32 = icmp eq i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %28, %20
%34 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %20, %28
%38 = phi i64 [ %30, %28 ], [ %21, %20 ]
%39 = phi i64 [ %29, %28 ], [ 0, %20 ]
%40 = icmp eq i64 %38, 0
br i1 %40, label %41, label %28
41: ; preds = %37
%42 = tail call i64 @fclose(i32* %18)
%43 = icmp eq i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %41
%49 = load i32, i32* @LC_ALL
%50 = tail call i32 @setlocale(i32 %49, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i64 %39)
br label %52
52: ; preds = %48, %4
%53 = phi i32 [ %6, %4 ], [ %51, %48 ]
ret i32 %53
}