#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char *argv[]) {
  char fname[80];
  FILE *rfp;
  long count;
  puts("Please input the file's name:");
  scanf("%s", fname);
  if ((rfp = fopen(fname, "r")) == NULL) {
    printf("Can't open file %s.\n", fname);
    exit(0);
  }
  count = 0;
  while (fgetc(rfp) != EOF)
    count++;
  fclose(rfp);
  printf("There are %ld characters in file %s.\n", count, fname);
  puts("\nPress any key to quit...");
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
lea    -0x60(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    11e9 <main+0x69>
lea    -0x60(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
movq   $0x0,-0x70(%rbp)
mov    -0x68(%rbp),%rdi
call   1060 <fgetc@plt>
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%rax
je     121b <main+0x9b>
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
jmp    11f1 <main+0x71>
mov    -0x68(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x70(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1080 <getch@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
lea    0xe82(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     121c <main+0x9c>
mov    %rax,%r14
mov    $0xffffffffffffffff,%rbx
mov    0x2e1c(%rip),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
call   1060 <fgetc@plt>
add    $0x1,%rbx
cmp    (%r15),%rax
jne    11d0 <main+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe48(%rip),%rdi
mov    %rsp,%rdx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <getch@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe00(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Please input the file's name:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"Can't open file %s.\0A\00"
@EOF = global i64 0
@.str.4 = [38 x i8] c"There are %ld characters in file %s.\0A\00"
@.str.5 = [26 x i8] c"\0APress any key to quit...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i32*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
store i64 0, i64* %8
br label %20
20: ; preds = %25, %19
%21 = load i32*, i32** %7
%22 = call i64 @fgetc(i32* %21)
%23 = load i64, i64* @EOF
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i64, i64* %8
%27 = add nsw i64 %26, 1
store i64 %27, i64* %8
br label %20
28: ; preds = %20
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
%31 = load i64, i64* %8
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i64 %31, i8* %32)
%34 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Please input the file's name:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"Can't open file %s.\0A\00"
@EOF = global i64 0
@.str.4 = [38 x i8] c"There are %ld characters in file %s.\0A\00"
@.str.5 = [26 x i8] c"\0APress any key to quit...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %2, %12
%13 = phi i64 [ %17, %12 ], [ 0, %2 ]
%14 = call i64 @fgetc(i32* %7)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
%17 = add nuw nsw i64 %13, 1
br i1 %16, label %18, label %12
18: ; preds = %12
%19 = call i32 @fclose(i32* %7)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i64 %13, i8* %4)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 (...) @getch()
ret i32 0
}