#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 off_t;
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__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int printf(char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  FILE *f;
  off_t size = 0;
  if (argc != 2) {
    printf("E: Need a filename as an argument.\n");
    return EXIT_FAILURE;
  }
  f = fopen(argv[1], "r");
  if (f == NULL) {
    perror("E: Can not open input file");
    exit(EXIT_FAILURE);
  }
  for (;;) {
    fgetc(f);
    if (ferror(f)) {
      perror("E: Error reading input file");
      exit(EXIT_FAILURE);
    }
    if (feof(f)) {
      break;
    } else {
      size += 1;
    }
  }
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d6 <main+0x46>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12ca <main+0x13a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1213 <main+0x83>
lea    0xe26(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    1218 <main+0x88>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     124e <main+0xbe>
lea    0xe06(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1266 <main+0xd6>
jmp    1274 <main+0xe4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1218 <main+0x88>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12a1 <main+0x111>
lea    0xdcf(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
call   1080 <setlocale@plt>
mov    -0x1c(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    121f <main+0x7f>
mov    0x8(%rsi),%rdi
lea    0xe4c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1275 <main+0xd5>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1205 <main+0x65>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    123c <main+0x9c>
add    $0x1,%ebx
mov    %r14,%rdi
call   1070 <fgetc@plt>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11e0 <main+0x40>
lea    0xe11(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    127e <main+0xde>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1090 <setlocale@plt>
lea    0xdf0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <printf@plt>
lea    0xd86(%rip),%rdi
jmp    120c <main+0x6c>
lea    0xdb4(%rip),%rdi
jmp    120c <main+0x6c>

LLVM IR (-O0):
@.str = [36 x i8] c"E: Need a filename as an argument.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"E: Can not open input file\00"
@.str.3 = [28 x i8] c"E: Error reading input file\00"
@.str.4 = [28 x i8] c"E: Can not close input file\00"
@LC_ALL = global i32 0
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%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 %57
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %13
br label %25
25: ; preds = %43, %24
%26 = load i32*, i32** %6
%27 = call i32 @fgetc(i32* %26)
%28 = load i32*, i32** %6
%29 = call i64 @ferror(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %25
%36 = load i32*, i32** %6
%37 = call i64 @feof(i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
br label %44
40: ; preds = %35
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %43
43: ; preds = %40
br label %25
44: ; preds = %39
%45 = load i32*, i32** %6
%46 = call i64 @fclose(i32* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %44
%53 = load i32, i32* @LC_ALL
%54 = call i32 @setlocale(i32 %53, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32, i32* %7
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %55)
store i32 %56, i32* %3
br label %57
57: ; preds = %52, %10
%58 = load i32, i32* %3
ret i32 %58
}

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